Jump to content
  • 0

Question

Posted (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 by jedwynne

7 answers to this question

Recommended Posts

Posted

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

Posted

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

Posted

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.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...