FOR command

when using multiple occurances of the FOR command (EXAMPLE: for (i=0; i<10; i++)), does it matter what letter you use, or not? I feel silly asking after having worked with Gscript since 2002, but I was never sure, so I use different letters to be safe:
for (i=0; i<10; i++)
for (j=10; j<20; j++)
for (k=20; k<30; k++)
Ect…

I've noticed scripts work whether you use the same letter multiple times or not, but I want my scripts to be done right, not just simply work.

Re: FOR command

Good thing to use is to use “this.var” instead of “var”
Otherwise you risk having the variable hop to another NPC on the level.

Also, you can reuse letters, but do not reuse the letter inside of another loop.
Eg:

for(this.i = 0; this.i < 10; this.i ++) {
for(this.ii = 0; this.ii < 10; this.ii ++ ) {
this.counter++;
}
}
message #v(this.counter);

Output: 100

for(this.i = 0; this.i < 10; this.i ++) {
for(this.i = 0; this.i < 10; this.i ++ ) {
this.counter++;
}
}
message #v(this.counter);

Output: 11 (Because the first loop reached '10' from the internal loop)

for(this.i = 0; this.i < 10; this.i ++) {
for(this.i = 0; this.i < 5; this.i ++ ) {
this.counter++;
}
}
message #v(this.counter);

Output: Error - StackOverrun/Exceeded Loop Limit (Because the first loop will never reach '10' because the internal loop resets it to 5)

Re: FOR command

Ah, alright, thanks. I've yet to have issues using var instead of this.var, but I'll update my code before issues do arrise. Knowing my luck, they'd arrise at the point where I'll want to slam my head into the keyboard at the thought of how much I'd have to fix, lol

Re: FOR command

Well lets say you have:

NPC#1 do Active = 1; to set a certain mode on it.

NPC#2 is on a timeout and also happens to use the variable 'Active' to know what mode its supposed to use as well.

NPC#2 is supposed to be dead, his “Active = 3”
NPC#1 does Active = 1 for some reason or another, which was intended for itself only (a this.var)
NPC#2 loops and sees that Active = 1, NPC#2 now goes on a player killing spree with 0 hearts and invulnerability.

Re: FOR command

Well, I use this.var plenty, I ment I don't tend to use them in for () blocks of code, lol. But I do see what you're saying, and I can see where for () can potentially cause issues using var over this.var

Re: FOR command

Is there any this. prefixs for strings? Like I know of client.string and server.string, but i'm wondering if theres one to exclusively save words just for the current npc.

Or even is it possible to save words to normal this.vars, I only seem to get them to work for numbers. Unless theres a special # thing to go before them. I only know #v value and #s for string.

Re: FOR command

All strings with exception to server.strings, set onto the player.
Atleast until GS2 where there is an actual this.string = “string”; and it sets onto the NPC, not the player.

If you do say

“omg setstring this.string,string; works!” or “omg setstring client.string,string; works!”
That is because Graal is treating it as “this.string”, not this.“string”.