|
Post by GH Games on Dec 3, 2016 23:01:20 GMT
Hi, I have created my first ever script (yay!) but it doesn't seem to fully work and I don't know why because everything seems fine to me. Here it is:
bool NetworkActive = false; void Main() { if (NetworkActive = true) { iObjectShow(OBJ_0); //Connected! } if(NetworkActive = false) { iObjectShow(OBJ_22); //Failed to connect! } }
It is supposed to show "Connected!" if the client successfully connects to a server and "Failed to connect!" if it fails.
What am I doing wrong? I also tried:
bool NetworkActive = false; void Main() { if (NetworkActive = true) { iObjectShow(OBJ_0); //Connected! } else { iObjectShow(OBJ_22); //Failed to connect! } }
|
|
|
Post by NicusorN5 on Dec 4, 2016 8:41:01 GMT
Uhh, what objects are OBJ_22 and OBJ_0 ?
If they are TextPrints , use
iObjectTextSet(OBJ_X,string);
Where OBJ_X is the TextPrint object where you want to change it's text and where string is the text you want to set for the specified TextPrint.
void Main() { iObjectTestSet(OBJ_0,"Failed to connect"); } ///This is a example
|
|
|
Post by TinSoldier on Dec 5, 2016 7:30:30 GMT
try this -
bool NetworkActive = false; void Main() { if(NetworkActive){ iObjectShow(OBJ_0); //Connected! iObjectHide(OBJ_22); }else{ iObjectShow(OBJ_22); //Failed to connect! iObjectHide(OBJ_0); } }
|
|
|
Post by Famer on Jan 20, 2017 10:40:00 GMT
This is my second script but this doesn't seem to work either.... This is after a lot of corrections while checking the script and still I get one error...... Expected expression value line 24 pos.1
What is expression value?
|
|
|
Post by GH Games on Jan 20, 2017 11:25:08 GMT
The only thing wrong was you had to many ; (semi-colons) and your else if's were 'elseif'. I don't think that works I think there needs to be a space. It's good practice anyway. You've done a good job bro it should work.
void Main() { if (IN_44 >= 10000) { iObjectHide(OBJ_0); iObjectShow(OBJ_66); iObjectStart(OBJ_88); OUT_67 = 0.1; } else if (IN_44 >= 25000); { iObjectHide(OBJ_0); iObjectShow(OBJ_66); iObjectStart(OBJ_88); OUT_67 = 0.3; } else if (IN_44 >= 50000) { iObjectHide(OBJ_0); iObjectShow(OBJ_66); iObjectStart(OBJ_88); OUT_67 = 0.5; } else { iObjectHide(OBJ_0); iObjectShow(OBJ_66); iObjectStart(OBJ_88); OUT_67 = 0.7; } }
|
|
|
Post by Famer on Jan 20, 2017 12:42:47 GMT
When I click it says:
And:
What is expression value anyway?
|
|
|
Post by GH Games on Jan 20, 2017 12:49:08 GMT
int test = 10;
void Main() { if(test >= 10) {
} else if(test >= 5) {
} else if(test >= 1) {
} else { } }
I just ran this and I get no erros. It's the same thing as what you have (if and if else wise). Try this:
void Main() { if(IN_44 >= 10000) { iObjectHide(OBJ_0); iObjectShow(OBJ_66); iObjectStart(OBJ_88); OUT_67 = 0.1; } else if(IN_44 >= 25000) { iObjectHide(OBJ_0); iObjectShow(OBJ_66); iObjectStart(OBJ_88); OUT_67 = 0.3; } else if(IN_44 >= 50000) { iObjectHide(OBJ_0); iObjectShow(OBJ_66); iObjectStart(OBJ_88); OUT_67 = 0.5; } else { iObjectHide(OBJ_0); iObjectShow(OBJ_66); iObjectStart(OBJ_88); OUT_67 = 0.7; } }
|
|
|
Post by Famer on Jan 20, 2017 15:07:15 GMT
Thanks man! But I figured another way out: The mistake was the condition value started increasing in the else if statements as you go down, but instead if you make it like the highest condition value in the top and the value gets down as you go down, it works....
|
|
|
Post by TinSoldier on Jan 21, 2017 0:55:10 GMT
Famer Heres a little neater version void Main(){
if(IN_0 > 50000){ DoIt(); OUT_67 = 2; }else if(IN_0 > 35000){ DoIt(); OUT_67 = 0.7; }else if(IN_0 > 20000){ DoIt(); OUT_67 = 0.4; }else{ DoIt(); OUT_67 = 0; } } void DoIt(){ iObjectHide(OBJ_44); iObjectShow(OBJ_66); iObjectStart(OBJ_88); } Disclaimer: If your computer explodes, it's the other guys fault, not mine .
|
|
|
Post by Famer on Jan 21, 2017 11:51:03 GMT
So... Dolt is a subroutine right?? Thanks!!! And, can we rename the subroutine to anything?
|
|
|
Post by Power Supersport on Jan 21, 2017 15:36:42 GMT
It's called a function, famer... XD
|
|
|
Post by TinSoldier on Jan 21, 2017 18:41:58 GMT
So... Dolt is a subroutine right?? Thanks!!! And, can we rename the subroutine to anything? Name it anything you want.
|
|