global variable call issue

I can't figure this out. I want to call the global variable id 1000 in a script. 


I use this script in event:
$journal[1] = "Alignment with Lakmi: #{$global_variables[1000]}"
before that I assign all journal entries up to page 1000 to empty:


$journal = []


n = 0


1000.times do


n += 1


$journal[n] = ""


end


$journal[1] = "Lakmi syays Hi! \n Speak set to on!"

after the assignment of journal[1] speak on it calls the journal, and works just fine. the alignment set happens when the player chooses a specific home planet...

it gives me Nil:NilClass error for method '[]' in game interpreter, when it tries to store the variable in journal.

what am I doing wrong, and how do I correct it?
I've moved this thread to Learning Ruby. Please be sure to post your threads in the correct forum next time. Thank you.


Ace Support is for non-script-related support


That said, when and where are you initialising those commands?


That script part is incomplete because it doesn't tell the class you placed the code into, and when in the game sequences you're calling those commands.


And if you're using an event command script for that - the event command is sandboxed, all data inside it will be erase when the event command ends. Even a second script command after the first in the same event will no longer have access to anything defined in the previous script command, that is why you need to place scripts that affect the engine into the script editor (and then into one of its classes)
that still doesn't tell me how to use a global variable in a script...

by global variable, I mean the variables one can assign in events.
$global_variables don't exist by default.


In-game variables, that are connected with Ace's eventing systems and such, are $game_variables[1000] and I think that's what you're looking for.


When you change the variables in events using Ace's editor ~ then it all refers to $game_variables[ID].


$game_variables is an array of global variables created and used anywhere in Ace by default. - They are also stored in the save file when saving your game.


Just use things like:


To set a value:


$game_variables[43] = 444


Use in conditional:


if $game_variables[43] > 200


  #more than 200


else


  #less than 200


end
thanks Riki!

Original thread: https://forums.rpgmakerweb.com/threads/global-variable-call-issue.60860/