Jump to content
  • 0

Question

Posted

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

Posted

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.)
  • Upvote 1
Posted

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

Posted

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).

  • Upvote 2
Posted

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

Posted

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.

Posted

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)

  • Upvote 1

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...