Ruby/RGSSx questions that don't deserve their own thread

class Game_Actor < Game_Battler alias lithkast_level_up level_up def level_up lithkast_level_up $game_variables[@id + x] += 1 endendLet's assume your variables are all sequential. Change x in the code above to be one less than the first variable (if actor 1 has variable 1, just remove the + x altogether and leave it as $game_variables[@id]. If actor 1 is assigned to variable 18, make x 17.
do I post that as its own script, or go under Game_Actor and add it in?
In its own script slot, under Materials
It returned an error

Script 'Game_Variables' line 19: Typeerror Occurred

the offending section w​as this

  def [](variable_id)
    @data[variable_id] || 0
  end
And what is the code you had?

What was written below the error?

Give us the text of full error message.

Is it

undefined method += for nil:nilClassEDIT : Shaz's post below is why I'm asking what is the code you had.
Shouldn't be - nothing in there that would cause a problem for a saved game.


Did you change the x to a number? Try changing @id to @actor_id - that's probably it.
There was nothing before the error code I wrote.  I wrote that exactly as the error was mentioned to me. : /

As for the fix  Shaz was right.  it should be @actor_id.  That fixed it and its working fine now.  All that's left is to add in a way to display the variable on the characters status page, but I can tool around in luna engine and figure that out probably.  Shaz, how should I credit you?
I don't need credit for that.
This is just related to scripting in general, and not to anyone's particular scripts. 

Is there a way to make it so that using a normal attack can write a value to a variable based on what kind of weapon you have equipped?
what kind of variable based on the weapon equipped? Keeping in mind that enemies also use the normal attack and don't have weapons.


If it's one of the weapon parameters, you could possibly modify the skill formula to pop something into a variable, but I suspect the check to see if it's an actor and if there's a weapon equipped might make the formula too long to fit in the formula box.
The monsters actually wont be using the normal attack in this game. There are more than enough skill slots for them to have their own moves.

It's actually not a weapon parameter. I'm talking about writing to a variable of my own creation. So like, for example, SwordEXPactor1 or BowEXPactor2. Is this possible?
Your description is very ambiguous. You're not talking about $game_variables? Where is this variable defined and where do you use it? What are you putting into it?


If you want a specific answer, you have to give a specific example. Say EXACTLY what you want it to do and we can show you how. "a value" and "a variable" are not specific enough.
I'm just talking about the variables that you can create as part of events with the control variable command. But, alright, let me start over. 

I am trying to construct a system where I can have attacks and skill usage add an exp value to a certain variable. so like there'd be two variables per skill. "sword exp actor1" and "sword level actor1"
 
Then I'd make a common event and set it to parallel process. Give it a conditional branch that says something like if "sword exp actor1" is greater than or equal to 100, then increase "sword level actor1" by 1 and subtract 100 from "sword exp actor 1". 

Is there a way to make a normal attack that's carried out by an actor add to that variable that I've described there, based on what weapon that actor is using. Is there any way to do that.
yes, you'll need to place the variable commands into the damage formula for that - there is an entire topic on how to use the damage formula box for additional effects and functions.


However, the place available in the damage formula is limited - writing $game_variables[33]+=1; for several variables might be too much, and then you'll need to define the changes as a regular script function and simply call that function in the damage formula box.


But I suggest not using a permanently running parallel process for checking that - if the experience can only gained in combat, then you only need to run the check once after each combat and can shut off the parallel event after running once.
Could you write v[33]+= 1? Since v = $game_variables in the damage method? Or is that a copy of the array only?


Anyway, this isn't really scripting, so if you want to do it via the damage formula, find the thread Andar is talkign about (I think it's pinned in the VX Ace Tutorials forum) and post there - also have a look through it for ideas.
Can I set a variable in the script editor? If so, please tell me how 🙁

I'm new to sripting.

I tryed this code but it gave me an error.

$game_variables[1] = 0I need the variable to be set when the game starts
Where did you do that? And what error? Most probably you might have run it in a time where $game_variables is not yet defined
What Engr. Adiktuzmiko said :

$game_variables is defined after the Main Process has executed.

So maybe you wanted to add that line at the end of create_game_objects and extract_save_contents methods in the DataManager?

On the other note, I think that variables in $game_variables are automatically set to 0, or they are set to 0 when you for the first time access them.

Or I'm wrong.
The error is :

Script: My Variable line 2 - NoMethodError occured

undefined method '[]=' for nil:NilClass

So if I can't place the script in the Materials section, where should I place it?
I think this will solve it :

class << DataManager  alias :some_random_alias_init  :init  def self.init    some_random_alias_init    $game_variables[1] = 0  endendOr change 1 to any other iD you want

Place this below Materials

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/