Global variabels?

The1stOne

Warper
Member
Joined
Apr 28, 2014
Messages
3
Reaction score
0
First Language
English
Primarily Uses
Hi!

I'm sure this is a really simple question, if you know how, which I obviously don't.

I've just started playing around with RPG Maker VX Ace, and have been spending maybe five hours all in all so far. At least I have a map and a character up and running in my game. Now I wanted a feature, that when I level up, I wan't the character to recover all his HP and MP. I thought I would start out easily, by using the predefined "Recover All" when making a Common Event, and then work my way down to only recovering the HP and MP, not all "stats".

To do this, I had an idea of making a common event, that I then call from the script Game_Actor under the def level_up-section. It looks like this:

 

 def level_up

    @level += 1

    # * Level Up - Run a common event on level up (my event)

    $game_temp.reserve_common_event(1)

    self.class.learnings.each do |learning|

      learn_skill(learning.skill_id) if learning.level == @level

    end

  end

 

Since I guess that this part is executed/run for each character that levels up, I want to be able to "catch" the right "actor" from my common event. That means, when I want to use "Recover All" (for now), I want it to be executed for the current actor that has leveled up. I then thought i could use global variables, or at least instance variables, like &actor_id, @actor_id, &level and @level. But I am probably missing something really obvious when trying to use those variables, or I am doing something totally wrong. Any idea on how I should do this? Preferably without adding any (more) scripts of my own. I mean, global variables should be accessible in events, right?

 

 

Best Regards

The1stOne
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,969
Reaction score
13,603
First Language
English
Primarily Uses
RMMV
A common event will only be called ONCE, AFTER the battle window has closed and you return to the map. If several of your party members level up, the common event would need to process ALL of them.


Since you're already modifying the script, just put the hp/mp change into the script itself, instead of making it call a common event to do it.


Just add


mp = mp_max


hp = hp_max


right there in the level_up method.


Check the variables and syntax - I don't have Ace in front of me.
 
Last edited by a moderator:

The1stOne

Warper
Member
Joined
Apr 28, 2014
Messages
3
Reaction score
0
First Language
English
Primarily Uses
That's also a way of doing it, probably the fastest too.

But I am already bothered that I have had to edit the script like I did. Doesn't that mean that the changes I make there are static? What if I suddenly want no HP/MP recovery after a certain level, or only for certain actors. Isn't it better to use dynamic "code" in events rather than changing the basics/defaults in the script? So yes, I want the effect like I explained, and you showed a way how. Now I also want to learn how to do it "properly". Please teach me!  :)

I have also tried looking through the Variables Guide someone have posted here. It's a nice guide, but as far as i can see it "only" uses "local variables", for item counting and such, and nothing that has to do with the actor stats or similar.

Let's say I want to meet a NPC in the game that tells me which level and how much EXP all my actors need to level up. How would I go about to find out how many actors I have in my following? Do I loop in between each and everyone. How do I then pick up their level and the value for "next_lvl_exp" required. Aren't these also global variables that should be available somehow? (Sorry for making the question/issue larger suddenly.)

/The1stOne
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,969
Reaction score
13,603
First Language
English
Primarily Uses
RMMV
Well, are your battles random or evented? If they're evented, call one common event before the battle to put every player's level into its own variable, then another after the battle to compare the current level with what's in the saved variable. That's a way for you to see ALL the characters who have levelled up due to that battle.

If you have random battles though you don't get to call a common event beforehand.

There is no such thing as "local" variables. All variables are global. What you're calling variables are class variables, which is different to the variables you see in Control Variables and those used in conditions. Not every class variable is available in event commands. For some of them you will need to use the Script command (or Control Variables' Script box).

$game_party.members.size will tell you how many people in your party. Control Variables > Other > Party Members will do the same, putting the value into a variable.

Unfortunately the question you are asking is wide open - you are asking "what if I want to do <something>". The example you gave is a "what if". Give a concrete "this is what I want to do", and we'll TRY to give you a non-script way to do it. But there just may not be non-script ways to do everything you want to do.
 

Mouser

Veteran
Veteran
Joined
Aug 19, 2012
Messages
1,245
Reaction score
264
First Language
English
Primarily Uses
There is no such thing as "local" variables. All variables are global. What you're calling variables are class variables, which is different to the variables you see in Control Variables and those used in conditions. Not every class variable is available in event commands. For some of them you will need to use the Script command (or Control Variables' Script box).
If he's out in script land, variables do have scope in Ruby - not all of them are global (thankfully).

To the OP: if you do start messing with the scripts, be sure to make all your changes in separate text blocks that you put down below Materials and above Main (where it says <insert here>). This way you always have the original nice and safe if you need to go back to it.
 

The1stOne

Warper
Member
Joined
Apr 28, 2014
Messages
3
Reaction score
0
First Language
English
Primarily Uses
OK, so there is a scope for the variables.

Then my next question is if there is a list with all such available variables and under what class/scope they can be found.

Has this link any relevance to my question?

Guess I can't avoid playing around with the scripts. I wanted to stay out of them for as long as possible, since it's like Mouser implies, that you need to know what changes you are doing and where (and why).

Thanks for all the quick replies!

/The1stOne
 

whitesphere

Veteran
Veteran
Joined
Mar 14, 2014
Messages
1,688
Reaction score
784
First Language
English
Globals in Ruby always have a $ for their first character.  The pre-defined globals all live in the DataManager class.  You probably want $game_party for starters, which is a Game_Party..
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

I FINALLY DID IT! 5 years making my very first game and I just officially released it on STEAM..... OMG..... I can say I finished a game! The feelings!!!!!
Stream will be live shortly! I am going to be playing some Among Us! Feel free to drop by!
Ami
tv program always get the ratings (it's the reason why drama series has 1000+ episode),also full and nonsense of censorship (weird blur, a scene getting cut because the unconvenient viewer,but it unconvenient to me either. you never see what the original is)

i know the reason is to take cover the viewer from the negative thing,but i just laughing and mocking of them that they're always suck :guffaw:
Star Chart Idea - Just something I am working on.
My sister learned spanish the old fashioned way and saw my way of conjugating. I don't use the formal method and just wing it. I thought her heart might explode. Apparently, different words use different endings. Weird part is even though I never learned the difference, I still can tell when the endings "look wrong".

Forum statistics

Threads
104,457
Messages
1,006,428
Members
135,966
Latest member
Kleik
Top