Jump to content
  • 0

for statement Question


jedwynne

Question


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  68
  • Reputation:   2
  • Joined:  03/10/12
  • Last Seen:  

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 jedwynne
Link to comment
Share on other sites

7 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

Nest two "for" statements, one for x, one for y. You're not providing enough info for me to write you an example.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  802
  • Reputation:   393
  • Joined:  11/09/11
  • Last Seen:  

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 :o

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

@DevilEvil: Oh, I had no idea about that. Thanks~

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  118
  • Reputation:   6
  • Joined:  01/25/12
  • Last Seen:  

i think 2 initialization wont work inside 1 for loop in npc script i have tried it

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  68
  • Reputation:   2
  • Joined:  03/10/12
  • Last Seen:  

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 :o

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  802
  • Reputation:   393
  • Joined:  11/09/11
  • Last Seen:  

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++; }

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...