OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: IceShade on 06 Jun 2009, 03:49:26

Title: "if statement in a while loop" troubles
Post by: IceShade on 06 Jun 2009, 03:49:26
Hi there, it's been a while since I've been here. I think my last post was somewhere in.. 2004. Good to see my account is still active ;)

In any case, I'm having some trouble with this code.
Code: [Select]
while {true} do
{
"start" setmarkerpos (getpos me);

if (testvar == true) then
{
"testmark" setmarkerpos (getpos me);
};

sleep 5;
};

An infinite while loop, sets the "start" marker to "me" location. It reaches the if statement, which is supposed to set a new marker at my location if testvar equals true.

Wait 5 seconds, do it all over again.

Without the if statement, this works fine. The "start" marker updates every 5 seconds on my position. With the if statement, however, it will execute the "start" marker setmarkerpos once, and then die.

I am clueless as what can go wrong here. Just to be sure, I defined "testvar" as false first (at the very start of the init.sqf), then set testvar = true, then called the script.

Surely I'm doing something wrong and this isn't a sqf limitation? I'd hate to make a second script just to get a second marker on my position (that requires a condition).
Title: Re: "if statement in a while loop" troubles
Post by: hoz on 06 Jun 2009, 05:17:50
Try this... however its not breaking out of the code anywhere.



Code: [Select]
testvar = true;


while {testvar} do
{
"start" setmarkerpos (getpos me);

if (testvar == true) then
{
"testmark" setmarkerpos (getpos me);
};

sleep 5;
};
Title: Re: "if statement in a while loop" troubles
Post by: h- on 06 Jun 2009, 08:00:15
When doing boolean checks you don't need to use ==

Code: [Select]
while {true} do
{
"start" setmarkerpos (getpos me);

if (testvar) then
{
"testmark" setmarkerpos (getpos me);
};

sleep 5;
};
Title: Re: "if statement in a while loop" troubles
Post by: IceShade on 06 Jun 2009, 11:04:05
When doing boolean checks you don't need to use ==

There we go! I didn't imagine that it would actually matter, but apparently sqf is very picky about its syntax.

Thanks guys, it's always better to have a few extra minds to look over some code that doesn't seem to work (but the answer is always so obvious).


EDIT#: Don't quote the entire previous post you're replying to..   h-
Title: Re: "if statement in a while loop" troubles
Post by: h- on 06 Jun 2009, 12:27:49
It has always been like that to my knowledge, no matter if it is sqs or sqf.
Title: Re: "if statement in a while loop" troubles
Post by: IceShade on 06 Jun 2009, 14:30:10
I'll go ahead and lock this now -> resolved.