Okay, newbie question.
I'm trying to modify a script so that a game variable is included in the math.
How do I declare a game variable so that when I run the game, it doesn't say something about an error for "undefined method '[]' for nil:nilClass
I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.
Tell us the EXACT error and show us where you have it set up in the script.
Without that information, we can only guess. And my guess would be that you're trying to access $game_variables before it has been created, by putting it in a script that runs before the main menu is shown and the player chooses to load a game or start a new game. $game_variables only exists while a game is actually in progress.
If that script is called from DataManager at the time when the $data* objects are created (ie - if you're reading and processing all the note tags right on loading the game), then $game_variables does not exist.
You will either need to use a constant instead, or set this up as a method that can be called AFTER $game_variables[200] is set.
I'll add some background information because I think that's were you misunderstand some of the processes.
Notetags are used to easily transfer data from the developer into the scripts, but in a lot of scripts that is done only once (at new game), because reading the notetags is slower than using internal variables for operations.
So at the beginning, the data is transferred from the notetags into the script's variables, and then the script works with its variables only.
That is why placing a $game_variable into the loading function for notetags is often useless - even if it works and you change that variable during gameplay, it will not have the desired effect because in a lot of cases the "load notetags" will not be called again later.
You need to find the lines where that value is actually used and apply the game variable there to have the desired effect.
I think you want to multiply by those numbers, not add them (working on the assumption that your calculation in the original script was correct).
(ps - I'm a girl 😉 )
1. The idea was that with a drop rate of... say, 20%, and then a bonus of 10 in v[200], you'd get a total drop cos of 30%.
Unless I screwed that up.
2. ...derp. My apologies, madam.
Nah, a bit of testing should indicate whether it's right or not. I'm just going by the fact that you multiplied it in the first script, and you're adding it in the second one. So the two will give different results.