OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Ferdin on 17 May 2009, 10:33:45
-
hi all,i'm confusing with follow:
private ["_i"];
for [{_i=0},{_i<100},{_i=_i+1}] do {
ctrlSetText [100,format["%1",_i]];
_i = _i - 1;
sleep 1;
};
seems "sleep" doesn't work well;
myDialog just type "100"...
can't i use sleep in "for[]do{}"?
thanks for your view :)
-
Then the "100" is hardcoded somewhere else since in your loop _i will will always be "0".
-
thanks a lot ;)
i'm a beginner :D
-
private ["_i"];
for [{_i=0},{_i<100},{_i=_i+1}] do {
ctrlSetText [100,format["%1",_i]];
_i = _i - 1;
sleep 1;
};
The string in "For" {_i=_i+1} increases your zero by 1 while "_i=_i -1;" reduces by 1.
So 0 + 1 - 1 = 0.
Change the above to:
private ["_i"];
for [{_i=0},{_i<100},{_i=_i-1}] do {
ctrlSetText [100,format["%1",_i]];
sleep 1;
};
and it will start at 0 and go down by 1 each second.
if you want it to start at 100 and go down replace the {_i=0} with {_i=100};
Hope that helps.
Luke
-
private ["_i"];
for [{_i=0},{_i<100},{_i=_i-1}] do {
ctrlSetText [100,format["%1",_i]];
sleep 1;
};
and it will start at 0 and go down by 1 each second.
Therefore _i will never be greater than hundred and the loop will run forever. Without the sleep this would freeze your ArmA.
-
Without the sleep this would freeze your ArmA.
This is something to avoid, and makes the sleep necessary.
Alternatively, you could remove it to punish those you hate,
but I believe that violates certain humanitarian conventions.
Luke
-
There are more convenient and obvious way to create a fixed-iteration-loop:
for "_i" from 0 to 99 do {
// something
};
for "_i" from 1 to 100 do {
// something
};
for "_i" from 100 to 1 step -1 do {
// something
};
I like this method for cleaner code.
-
Yeah, I'm a big fan of that for. Also note that the iterator, in this case _i, is automatically made private inside the loop (it does't even exist outside it). Saves you worrying about privating it.