RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

Creating and accessing an array [Resolved]

Started by golothwen, August 16, 2008, 05:07:40 PM

0 Members and 1 Guest are viewing this topic.

golothwen

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?

modern algebra

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

golothwen