[Ace] Can't figure out what I am doing wrong.

My question is why is it that when I call getValue(name) in the code below, that 0 returns when I'm expecting an array. Thanks for reading

Spoiler
class exampleClass
attr_accessor :variableName

def initialize()
@variableName = {}
end

def someMethod()
@variableName["example"] = [1,2,3,4]
end
end

class Game_Interpreter
alias original_initialize initialize

def initialize(depth = 0)
original_initialize(depth)
$global_variable = exampleClass.new
end

def anotherMethod()
$global_variable.someMethod()
end

def getValue(name)
return $global_variable.variableName[name]
end
end

Code:
Note: I have two events on the map that each activate with action button. The first one calls "anotherMethod" while the second one calls getValue(name). First I talk to the first event than I talk to the second event but getValue(name) returns 0. I am unsure why that is.

More details: http://www.mediafire.com/?zca21o16sutpgxz
When I try to import your code, I get a "class/module should be a CONSTANT" error.

Other than that, I capitalized the first E in ExampleClass and performed these calls:

anotherMethod()

msgbox getValue("example")

It works fine and returns an array as I'm assuming it should.
Ok, didn't know class names had to be capitalized (it is in my game though, this was just thrown together to highlight the problem). When you tried to run the calls were they from different events? If I called them back to back they work but when I call them from two different events the array doesn't come out.

To further explain how I was using them I have two npcs. Both are set to trigger with the action button. When I "talk" to one of them it will call "anotherMethod()". Afterwards I talk to the second NPC which calls getValue() but the data returned is nil or 0.

Also thanks for taking the time to respond.
you need to use something as name that's inside that hash, or it can't really return anything.

Did you use getValue("example")?
I ran them from different events and it worked.
@mobychan - yeah, forgot to type it in when posting

@PK8 - I guess the error must be somewhere else or I typed something wrong and I overlooked it.

I uploaded my project to mediafire. If you run a "new game" you will appear next to two npcs. Talk to the south one than talk to the east one. http://www.mediafire.com/?zca21o16sutpgxz

I'm sure I made a silly error somewhere but I can't find it and it's really bugging me.

Thanks for reading.
I don't know why, i actually never used a global variable i made myself in RGSS before, but I changed your "$dungeons" to "@dungeons" and now it works Oo
I'm not sure if my way of thinking is right but i solved your problem...

You initialized Dungeons in Game_Interpreter, that's what you did wrong because everytime a Game_Interpreter is initialized it'll initialize Dungeons and doing so, your dugeon_list will be be rewriten. So when you call your common event test, it'll return 0 since the value of $game_variables[1] will be zero. I fixed it for you. Just initialize Dungeons in DataManager instead of Game_Interpreter, like this:



Code:
module DataManager
  def self.create_game_objects
    $game_temp		  = Game_Temp.new
    $game_system	    = Game_System.new
    $game_timer		 = Game_Timer.new
    $game_message	   = Game_Message.new
    $game_switches	  = Game_Switches.new
    $game_variables	 = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_actors	    = Game_Actors.new
    $game_party		 = Game_Party.new
    $game_troop		 = Game_Troop.new
    $game_map		   = Game_Map.new
    $game_player	    = Game_Player.new
    $dungeons		   = Dungeons.new
  end
end
This way your code will work just fine.
@mobychan I chose to use a global variable because that was the only way I knew how to save the data when the user loads it later.

@Gleen - I used your suggestion and it appears to be working as intended right now. Thank you.

@Everyone - Thanks for taking the time to help me, I really appreciate it. I guess it was due to my poor understanding of how the game interpreter works. I thought it was only initialized once every game.

Original thread: https://forums.rpgmakerweb.com/threads/ace-cant-figure-out-what-i-am-doing-wrong.2651/