RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Total Noob Error?

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 76
RMRK Junior
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:
Code: [Select]
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

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
First, 8888 is too high. The Game_Variables class maxes it out at 5000.

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

Code: [Select]
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.
« Last Edit: December 12, 2010, 12:56:27 AM by modern algebra »

**
Rep: +0/-0Level 76
RMRK Junior
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

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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?

**
Rep: +0/-0Level 76
RMRK Junior
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

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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).

**
Rep: +0/-0Level 76
RMRK Junior
Thank you!
Normally the programm documentation isn't that good.
I'll give it a try