Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 When should I use global, instance, local, and constants in event systems?
#10
Zeriab Wrote:Global variables are not resource hogs. I wonder where you found that myth.
Obtained from...

General Scripting Conventions
By Trickster
Proofreading by Yeyinde and Kurisu

Trickster at HBGames.Org Wrote:Global Variables should generally not be used. Global Variables are not an Object Oriented construct and violates information hiding. You do not want all of the scripts knowing about a variable, you only want your variables shown to methods/classes/scripts that need to view and perform operations on it. The only global variables that should be added are new $data_ and $game_ objects. System global variables created by RMXP (ex. $DEBUG and $scene are allowed). Global variables also consume more memory since they are not removed until the program terminates. The use of bad global variables is frowned upon, because you are cheating yourself, your script, and the users of your script.

Marbles Wrote:oh well aren't all the variables global in rpg maker events? (except the map specific variables that in a sense are still global to the events w/in the map)

When you consider the class variables such as $game_temp.map_bgm, you are not really using global variables, but instance variables created for that class. You may refer to or change the value of map_bgm from another class (be it a window or scene class) by the use of the $game_temp prefix. It uses the prefix so the system knows what class the value was created and stored. On the other hand, the value can be used throughout the Game_Temp class by referring to the @map_bgm instance value alone.

So I can call $game_temp.map_bgm from any class, or just @map_bgm in the Game_Temp class as it is an instance variable for that class.

Likewise, RMXP variables called from events are class variables too. You refer to the $game_variables[i] value, but when you do, you access the @data instance value (an array) that was created on the class's initialization.
Reply }


Messages In This Thread
When should I use global, instance, local, and constants in event systems? - by DerVVulfman - 12-28-2008, 08:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Popular Battle Systems kyonides 6 6,452 02-24-2022, 10:40 PM
Last Post: kyonides
Brick Common Event Library (Development + Brainstorm thread) PK8 3 9,083 02-11-2016, 09:25 PM
Last Post: JayRay
   What do you dislike in ATB Systems? DoubleX 18 22,317 06-13-2015, 05:03 AM
Last Post: DoubleX
   What Makes an Event System DerVVulfman 8 13,022 01-19-2010, 09:07 PM
Last Post: Bolt
   What is "event scripting?" PK8 11 16,390 12-19-2008, 11:20 PM
Last Post: PK8



Users browsing this thread: