The RPG Maker Resource Kit

Other Game Creation => Program Troubleshooting => Topic started by: golothwen on August 16, 2008, 05:07:40 PM

Title: Creating and accessing an array [Resolved]
Post by: golothwen on August 16, 2008, 05:07:40 PM
Ok, so I get that you make an array by typing something like main_characters = ["Levi", "Peregrine"].

How do I create that in RMXP when the program is doing all of its usual initialization, and then have the program maintain its status (so if the array changes to ["Al", "Gina"] it will not go back to ["Levi", "Peregrine"] the next time I or the player start it up?)

After that, what specifically would I type in to an event that let me access and/or change the contents of the array?
Title: Re: Creating and accessing an array (simple question)
Post by: modern algebra on August 16, 2008, 06:41:34 PM
Well, there are a number of ways to do what you are asking. It really depends on where you want this array to be accessed from. For instance, you could do this:

$bad_global = ["Levi", "Peregrine"]

and if you put this code in in the new_game method of Scene_Title then it would initialize only once. It could then be accessed by simply calling $bad_global.

Or you could set the array as an instance variable of another class, such as Game_Party.

Then you could set this code:

attr_accessor :main_chars

and then in the initialize method, write:

@main_chars = ["Levi", "Peregrine"]


Then the array would initialize once and only once and it would be accessible through the code $game_party.main_chars
Title: Re: Creating and accessing an array (simple question)
Post by: golothwen on August 16, 2008, 08:35:55 PM
That makes sense, thanks so much. =)