When does variables resets?

Lord Ganja

New member
Messages
161
Points
0
Age
34
Location
Ganja World
As the title says, when does variable resets?

Like, if we use '@' variable, it resets whenever the attached player logged out. 

How about the others? 

Thanks for those who can explain. 
default_no1.gif


variables.png

 
Last edited by a moderator:
Permanent variables, with no prefixes, or prefixes of $,# and ##  never reset unless you null them by yourself, that includes string variables ($ postfix).

There's no real difference between just variable and arrays, as normal variables are treated as array with index[0]. You can check that out yourself, for example TestVar and TestVar[0] will yeild same result if you set only one of them.

Temporary character variables are reset when character logs out. Temporary server variables ($@ prefix) reset during map server reset. Until that they're stored safely. NPC variables (. prefix) are also reset during server reset. Most interesting are scope variables (.@ prefix). They are reset whenever script hits an end (that includes close). They are very useful as a temporary variables you can use to count something, like if you need to rand a number and use it in 2 different parts of code, or for looping.

Also, Hercules has instance variables (' prefix), I believe those are nulled out once instance is destroyed, but can't be sure.

And some interesting fact about NPC variables: they are shared between duplicates of one NPC. I once hit that wall quite hard trying to figure out why it didn't go as planned at first with duplicate NPCs (And I'm quite lazy so I try to do almost everything with duplicates if it's possible. Using names of NPCs to store needed info to be able to duplicate easily is fun
default_happy.png
)

 
Last edited by a moderator:
@@Garr Thanks! anyway are permanent variables stored at sql? 
All variables are stored at SQL(except scope , since it is erased quickly (as soon as script ends))There are 6 tables char_reg_num_db char_reg_str_db and 2-2 more for login and global variables.

 
Back
Top