Jump to content
Sign in to follow this  
VirusLIVED

Can you spot my code error?

Recommended Posts

Can anyone spot the problem with this script? I know the script is executing correctly and I am pretty sure the code is working up until it hits the "IF" statement. I can't figure out what I am doing wrong. Please help, and thank you.

private ["_locs", "_state"];
_locs = [loc1, loc2, loc3, loc4, loc5, loc6, loc7, loc8, loc9, loc10, loc11, loc12, loc13, locl4, loc15];
_state = "true";

sleep 0.1;

{_x setDamage 1} forEach _locs;
_state = "false";

if (_state == "false") then
{
{_x setDamage 0} forEach _locs;
exitWith{hint "RESTORED and ACTIVE!"}; 
};

Share this post


Link to post
Share on other sites

private ["_locs", "_state"];
_locs = [loc1, loc2, loc3, loc4, loc5, loc6, loc7, loc8, loc9, loc10, loc11, loc12, loc13, locl4, loc15];
_state = true;

sleep 0.1;

{_x setDamage 1} forEach _locs;
_state = false;

if (!_state) then
{
{_x setDamage 0} forEach _locs;
exitWith{hint "RESTORED and ACTIVE!"}; 
};

Here we go ;)

Share this post


Link to post
Share on other sites

change

if (_state == "false") then
{
   {_x setDamage 0} forEach _locs;
   exitWith{hint "RESTORED and ACTIVE!"}; 
};  

to:

if (_state == "false") exitWith
{
   {_x setDamage 0} forEach _locs;
   hint "RESTORED and ACTIVE!"; 
};  

Share this post


Link to post
Share on other sites

Thanks guys. I think that just about fixed my problem. This leads me to another question...

Why is it that when you declare a variable such as _state = "true" that you must reference it in quotation marks? I though true is boolean meaning its not a string therefore not needing quotation marks.

I tried the script above without quotes and the script didnt work. Then I tried it with quotes and it did.

Either way, problem is solved. This is a learning experience for me. Thanks again!

Share this post


Link to post
Share on other sites
Why is it that when you declare a variable such as _state = "true" that you must reference it in quotation marks? I though true is boolean meaning its not a string therefore not needing quotation marks.

I tried the script above without quotes and the script didnt work. Then I tried it with quotes and it did.

because you declared the variable _state = "true"; to be a string before the check, now you have to check it against a string to be valid, if you had declared it a bolean at start, you can check it against bolean later.

some examples:

strings:

_state = "true";
if (_state == "true") then {hint "this works"};

checking if false, (not same as).

_state = "trueish";
if (_state != "whatever") then {hint "this works too since _state is NOT same as "whatever"};

boleans:

_state = true;
if (_state) then {hint "this works too"};

above means that if true then display hint.

you can also check it against false:

_state = false;
if (!_state) then {hint "this works too because its checking for false"};

string VS bolean:

you can also check a bolean against a string if you need for some reason using str command.

_state = true;
if (str(_state) == "true") then {hint "this works too as it checks for if _state inside '' is same as 'true'"};

a note on the hint i used ' instead of " inside the hint since it will conflict with the hint itself, but it means " just incase you didnt know, not trying to confuse ;)

Edited by Demonized

Share this post


Link to post
Share on other sites

Thank you very much for helping me out, this is very good information and it really helps clarify my issues with quotation marks! :D

Thanks again.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×