jedwynne Posted June 30, 2012 Posted June 30, 2012 (edited) how can i have 2 initial value in FOR STATEMENT sample that i need to set value of x and y to 0 for (set .@x,0; .@x <= 100;set .@x,.@x + 1) { code} Edited June 30, 2012 by jedwynne Quote
Euphy Posted June 30, 2012 Posted June 30, 2012 Nest two "for" statements, one for x, one for y. You're not providing enough info for me to write you an example. Quote
DevilEvil Posted June 30, 2012 Posted June 30, 2012 In a for statement you can set several initialization statements: for(x=100, y=0; x!=y ;x--,y++){} Just need to put a comma 1 Quote
Euphy Posted June 30, 2012 Posted June 30, 2012 @DevilEvil: Oh, I had no idea about that. Thanks~ Quote
deathscythe13 Posted July 1, 2012 Posted July 1, 2012 i think 2 initialization wont work inside 1 for loop in npc script i have tried it Quote
jedwynne Posted July 1, 2012 Author Posted July 1, 2012 In a for statement you can set several initialization statements: for(x=100, y=0; x!=y ;x--,y++){} Just need to put a comma i think 2 initialization wont work inside 1 for loop in npc script i have tried it @DevilEvil, i agree to @deathscythe13 i tried this... for (set .@x,0,set .@y,0; .@x <= 100;set .@x,.@x + 1,set .@y,.@y + 1) but im having an error Quote
DevilEvil Posted July 1, 2012 Posted July 1, 2012 Oh, I may be wrong (since in C it's possible lol). Anyway, put the initialization statement before the for loop, and the increase statement at the bottom of the for loop. for(x=100, y=0; x!=y ;x--,y++){} to y=0; for(x=100; x!=y ;x--){ y++; } Quote
KeyWorld Posted July 2, 2012 Posted July 2, 2012 Yeah the script engine doesn't support coma operator So you can use DevilEvil's code, or imbricate set() but will look messy... or don't use for() (can use do/while() while(), goto, recursive function). By the way you should know that .@value don't need to be set to 0 when starting a script (because they are already set to 0), so in a lot of case the first statement of for() can be remove. Quote
Question
jedwynne
how can i have 2 initial value in FOR STATEMENT
sample that i need to set value of x and y to 0
for (set .@x,0; .@x <= 100;set .@x,.@x + 1) { code}
Edited by jedwynne7 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.