integral Posted March 27, 2013 Posted March 27, 2013 Is it a bad thing to put numerous variables in a script? Like setting .item01 , .item02 ,... .item20 ... (npc variable) in a npc script. I mean, will it have any negative effect or what-so-ever? Quote
Euphy Posted March 28, 2013 Posted March 28, 2013 It depends on the situation. Some examples... Scope variables: Arbitrary variables with no meaning, ex. to handle for/while loops or to store random numbers. Anything in an uncommonly-used section of an NPC, where it would serve no purpose to store the data permanently. Scripts where different instances hold different values that should not overwrite each other, ex. storing a player's name in dialogue or other player data. NPC Variables (OnInit): Commonly-referenced variables in a prominent NPC, ex. basic configuration settings in my Quest Shop or WOE Controller. Large, occasionally-referenced arrays or simulated multi-dimensional arrays (setd/getd), where it would be a waste of processing to re-set the values each time the script is called. Stored values in NPCs with many duplicates, since NPC variables are only stored for the main NPC and not its duplicates (i.e. this saves both RAM and processing). NPC Variables (not OnInit): Variable that will be referenced later, after the current script terminates, ex. counts in event scripts. Temporary reference needed in another section of a script where scope variables are not passed (goto/donpcevent), where the variable is generally un-set (to zero or "") after use. (This is very uncommon; I may actually be the only scripter that does this.) 1 Quote
Oxxy Posted March 27, 2013 Posted March 27, 2013 No, it won't have any negative effect. But numerous variables don't work if number is first placed in variable. To better understand: set 1orc, 1; // Won't work Quote
Euphy Posted March 27, 2013 Posted March 27, 2013 NPC variables consume RAM, that's all. It's better to use scope variables, when possible, since they're erased after use; but commonly-referenced variables should be NPC variables set OnInit (to avoid constant re-setting of variables, or multiple instances of scope variables existing). 2 Quote
integral Posted March 28, 2013 Author Posted March 28, 2013 NPC variables consume RAM, that's all. It's better to use scope variables, when possible, since they're erased after use; but commonly-referenced variables should be NPC variables set OnInit (to avoid constant re-setting of variables, or multiple instances of scope variables existing). Sorry, got a little confused. Does that mean that, scope variables > npc variables set OnInit > npc variables not on OnInit Quote
integral Posted March 29, 2013 Author Posted March 29, 2013 I see, thank you for explaining it thoroughly. Therefore, since I'm just going to use a variable to store item id's, it's better to set it with Oninit, so that it will not be called many times, thus, saving RAM. Thank you, Euphy. Quote
Capuche Posted March 29, 2013 Posted March 29, 2013 Temporary reference needed in another section of a script where scope variables are not passed (goto/donpcevent), where the variable is generally un-set (to zero or "") after use. I'm not sure you were thinking about that but goto keep scope variables's value (from my simple test) 1 Quote
Question
integral
Is it a bad thing to put numerous variables in a script?
Like setting .item01 , .item02 ,... .item20 ... (npc variable) in a npc script.
I mean, will it have any negative effect or what-so-ever?
6 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.