Help Calling Scripts with Common Events and Variable Additions [VX ACE] (solved)

Heya, so I've got some very basic questions about Common Events Script Calling:
----------------------------------------------------
[ Final Edit: Turns out it was a formatting issue on the script call side of things (thanks A Moonless Night for helping me with that!) combined with me needing to relearn about Public Instance Variables and their relations to classes.

All sorted now and I'm on track to get what I want done done!

Thanks for all the help! ]

----------------------------------------------------

For the life of me I can't get my Skill Activated Common Events to do the script I want it to.

Say I do this in the Script Editor:
(Edit 2: This method is in the Game_Actor < Game_Battler class)
def sarah_action_turn
@s_a_turn = 1
sarah_action_turn = @s_a_turn
p(sarah_action_turn)
end


And then I make a common event that activates when a skill (let's say Strong Attack) is used...

How do I make that common event skill add 1 to the s_a_turn variable?

I've tried @s_a_turn += 1
I've tried writing it with class and a new method
Heck, I've even tried just asking it to p(@s_a_turn) or p(sarah_action_turn)

But no matter what I do, nothing comes up in my console.
What am I doing wrong?
How do I make Script Calls in common events worrrrrrrrk?

I realise this is super simple, but I can't find any good tutorials on this and the things I'm trying aren't working.

Help please.
Moved to the Learning Ruby/RGSS board.

The most obvious issue I see is that this method is not defined inside of a Class, or if it is and you haven't shown it, then you are not using an Instance of that Class to call it. As an example, the gain_item method is part of the Game_Party class, and there is an instance of that class created at game startup called $game_party - that is why when we call that method in a common event we would use a structure like $game_party.gain_item(item, quantity)

Without a Class, or an instance of that Class, there's nothing available to actually call and run that method. It's just kind of orphaned code, floating in the middle of nowhere. (Also, note that @variable such as your @s_a_turn is how you define a class variable - essentially, a property of instances that belong to the class. It means nothing unless an instance of the class is created to take that property.)

The second obvious issue I see is with your line: p(sarah_action_turn)
Since sarah_action_turn is equal to 1 at this point, you might as well be typing p(1), which makes no sense whatsoever to my eye. What is the method "p"? Where is it defined, and what does it do? Note that if you're trying to define a method alias called "p" for sarah_action_turn with this line, that's not how you do it. You'd have to define it outside of all other methods (but inside the Class), using def p(parameters) and if it is an alias of another method you would need to place the alias-defining line right above that def p definition line.
The first issue:
I currently have the method defined above set under the Game_Actor class.

So does that mean to reference it I'd do:
Game_Actor.sarah_action_turn
?

So to add 1 to the variable @s_a_turn would I have to create an additional method within Game_Actor class that adds 1 to that variable and then call that like so:
Game_Actor.additional_method
?

I shall try that next.

The second issue:
When you write p(something) it outputs the value of that something into the console that accompanies the game pop up when you playtest the game if you have console enabled.
I was attempting to use it to see if my code was working.

But as stated in the original post, no matter what I tried I wasn't getting anything in my console, so I was clearly doing something wrong.

Hopefully that way of typing class methods you showed is what I was needing.
Thanks for the reply!
Moved to the Learning Ruby/RGSS board.

The most obvious issue I see is that this method is not defined inside of a Class, or if it is and you haven't shown it, then you are not using an Instance of that Class to call it. As an example, the gain_item method is part of the Game_Party class, and there is an instance of that class created at game startup called $game_party - that is why when we call that method in a common event we would use a structure like $game_party.gain_item(item, quantity)

Without a Class, or an instance of that Class, there's nothing available to actually call and run that method. It's just kind of orphaned code, floating in the middle of nowhere. (Also, note that @variable such as your @s_a_turn is how you define a class variable - essentially, a property of instances that belong to the class. It means nothing unless an instance of the class is created to take that property.)

The second obvious issue I see is with your line: p(sarah_action_turn)
Since sarah_action_turn is equal to 1 at this point, you might as well be typing p(1), which makes no sense whatsoever to my eye. What is the method "p"? Where is it defined, and what does it do? Note that if you're trying to define a method alias called "p" for sarah_action_turn with this line, that's not how you do it. You'd have to define it outside of all other methods (but inside the Class), using def p(parameters) and if it is an alias of another method you would need to place the alias-defining line right above that def p definition line.

So, I've tried this under class Game_Actor < Game_Battler:
Poop.png


And then I've tried this in the Common Event Script Call that's summoned when skill[150] is used:

Poop 2.png


It's coming back now with the error that sarah_action_turn is an undefined method within Game_Actor class despite it... well not being undefined as far as I can tell.

I'm sure part of this is me not fully understanding how to do variables with methods
And part of this is me not fully understanding how to do script calls with common events

But I could be wrong I guess lol

Please help.


( side note - the method p(____) outputs whatever ______ is to the console that accompanies the game window whenever you playtest something )
Each actor is their own instance of Game_Actor, so you need to use the specific instance you need. Try $game_actors[1].sarah_action_turn for actor 1.

Also, when you're checking if a variable is equal to something, you need to use ==. = is just for setting the variable.
You can't call a method using a Class like Game_Actor; you have to call it with an instance of that class. (Just FYI, and not as code you should write - if you look through the base code, you can see where instances of the Game_Actor class are being created. I think it's Line 20 inside the Game_Actors script.)

Go ahead and follow @A-Moonless-Night's advice, and see what happens from there.
Each actor is their own instance of Game_Actor, so you need to use the specific instance you need. Try $game_actors[1].sarah_action_turn for actor 1.

Also, when you're checking if a variable is equal to something, you need to use ==. = is just for setting the variable.

Thanks so much for this!
$game_actors[1].sarah_action_turn was exactly the kind of formatting I was just not computing in my head and now feel like I understand.

Also yup, I knew that about == and = but that was a silly error on my part by forgetting that when I wrote that example lol!


You can't call a method using a Class like Game_Actor; you have to call it with an instance of that class. (Just FYI, and not as code you should write - if you look through the base code, you can see where instances of the Game_Actor class are being created. I think it's Line 20 inside the Game_Actors script.)

Go ahead and follow @A-Moonless-Night's advice, and see what happens from there.

I'm not entirely sure I understand what you mean by this, but after seeing your reply, Moonless Night's reply and rewatching DP3's tutorial on attr variables (found here: )...

I can safely say I'm on the right track to doing what I want to do and now feel like this initial hurdle has been cleared/resolved.

(Public Instance Variables for the win!)

Thanks for all the replies!
This thread can now be closed or w/e (not sure how that process works).

My battle system is taking shape! 😀
If your request has been solved and you want it Closed, it's generally better to Report your own post and say it has been solved, rather than editing your title (I know some forums ask for the title change instead). That way a Mod is sure to see it.

Thread closed a

Original thread: https://forums.rpgmakerweb.com/threads/help-calling-scripts-with-common-events-and-variable-additions-vx-ace-solved.124468/