Main Menu
  • Welcome to The RPG Maker Resource Kit.

Total Noob Error?

Started by Saschb2b, December 12, 2010, 12:04:45 AM

0 Members and 1 Guest are viewing this topic.

Saschb2b

Hello :)
I want to change the behaviour of my scripts withing the game.
So I changed a ingame variable and wanted to use it in my script.
See here:
if $game_variables[8888] = 0
  ATB_PARTY_COMMAND_WAIT = false
else
  ATB_PARTY_COMMAND_WAIT = true
end


It tells me: "undefined method '[]='"
But this schouldn't be a method!
Whats the problem? I thought it's easy XD
Thanks

modern algebra

#1
First, 8888 is too high. The Game_Variables class maxes it out at 5000.

Second, it should be a double equal sign, like so:


if $game_variables[888] == 0
  ATB_PARTY_COMMAND_WAIT = false
else
  ATB_PARTY_COMMAND_WAIT = true
end



and []= is, in fact, a method. It is located in the Array, Table, and Hash classes, for instance, in addition to the Game_Switches and Game_Variables classes (which are really just wrappers for an array). It can be defined in any class, if there is a reason for it.

Saschb2b

oh yeah you're right.
But it says now "undefined method '[]'"
Instead of "undefined method '[]='"...
Going to bed now. Nearly 2 o'clock in the night here.
Coming back in a few hours of sleep.
Thanks

modern algebra

Well, it's likely that you're trying to use it before it's defined. My guess is you have it outside of a class, meaning it's interpreted before you even get to Main. Yeah, totally can't do that. I should have known that immediately from when you first reported that the error was an undefined method one. I guess I wasn't paying much attention. Sorry.

$game_variables is only initialized in Scene_Title. This means that those methods in Scene_Title need to be run before you can operate on it.

In any case, if you want the value of the constant to depend on $game_variables[888], why not just go everywhere else in the script and replace checks of that constant with checks on $game_variables?

Saschb2b

That was my first idea,too.
But how do I solve this?
It is a modul not a class... So it seems that there are only declarations.
I don't get it at all... Sry... I'm normally a good programmer at C# but RGSS2
is just too confusing for me.
Is there a documentation of what moduls are and what the order of scripts are.
Because you meant that scene_title is called after my code.
I want to understand this but I don't find good documentations

modern algebra

The Help File is actually fairly comprehensive. Look there and you'll find pretty much all the documentation you need.

In any case, scripts are interpreted in the order they are in the Script Editor. Once it gets to main, it sets $scene to Scene_Title.new and then continually calls the main method of $scene in a loop, as long as $scene is not nil. Scene_Title will create the game objects if you start a new game. Otherwise they are created in Scene_File. It is only after that that you may use $game_variables, and you are trying to use it before then.

The solution is that you can't use $game_variables to define the value of that constant. There are a number of solutions. The easiest would simply be to go to everywhere in the script that checks the value of that constant, and replace it with a check of that variable (assuming that it's never used outside of a method that is only called after the player has started the game; as it appears to be battle related, I assume that will be the case).

Saschb2b

Thank you!
Normally the programm documentation isn't that good.
I'll give it a try