Jump to content
  • 0

Numerous variables


integral

Question


  • Group:  Members
  • Topic Count:  51
  • Topics Per Day:  0.01
  • Content Count:  167
  • Reputation:   4
  • Joined:  02/01/12
  • Last Seen:  

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?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  106
  • Reputation:   3
  • Joined:  01/01/12
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  51
  • Topics Per Day:  0.01
  • Content Count:  167
  • Reputation:   4
  • Joined:  02/01/12
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  51
  • Topics Per Day:  0.01
  • Content Count:  167
  • Reputation:   4
  • Joined:  02/01/12
  • Last Seen:  

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.

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

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
Link to comment
Share on other sites

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.

×
×
  • Create New...