Home   Help Search Login Register  

Author Topic: "if statement in a while loop" troubles  (Read 2280 times)

0 Members and 1 Guest are viewing this topic.

Offline IceShade

  • Members
  • *
"if statement in a while loop" troubles
« 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).
« Last Edit: 06 Jun 2009, 19:21:30 by savedbygrace »

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: "if statement in a while loop" troubles
« Reply #1 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;
};
Xbox Rocks

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: "if statement in a while loop" troubles
« Reply #2 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;
};
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline IceShade

  • Members
  • *
Re: "if statement in a while loop" troubles
« Reply #3 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-
« Last Edit: 06 Jun 2009, 12:28:59 by h- »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: "if statement in a while loop" troubles
« Reply #4 on: 06 Jun 2009, 12:27:49 »
It has always been like that to my knowledge, no matter if it is sqs or sqf.
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline IceShade

  • Members
  • *
Re: "if statement in a while loop" troubles
« Reply #5 on: 06 Jun 2009, 14:30:10 »
I'll go ahead and lock this now -> resolved.