Self Variable Script for RM VX Ace

Hi

I spent the last two days looking for a script that allows creation or use of self variables in events. It's useful for creating growing plants on farms etc.

All the stuff I found so far has broken links or is for MV...

There was one script on these forums called PK8's Self Data Suite. But all the links are dead as well.

Does anyone have a copy of the above script? Or at least something similar?
@Tsar CUBE I have put a copy in my dropbox. You can get it here.
As my dropbox is fairly full, please post to tell me when you've dl'd it so that I can delete it.
If i remember correctly Another Fen made one for the German Community, but the Website went down forever, here the Script without the Big Info explanation which is lost now.
Self Variables Script for Events:
Code:
class Game_System
 
  def self_variables(map_id, event_id)
    if map_id > 0 and event_id > 0
      # Erstelle Self-Variables-Hash wenn noch nicht vorhanden:
      @self_variables ||= Hash.new
      @self_variables[map_id] ||= Hash.new
      @self_variables[map_id][event_id] ||= Hash.new(0)
    else
      # Bei ungültiger Map-/Event-ID gebe einen leeren Hash zurück:
      Hash.new(0)
    end
  end
end


class Game_Interpreter
 
  def self_variables(event_id = @event_id)
    $game_system.self_variables(@map_id, event_id)
  end
end


class Game_Event

  def self_variables
    $game_system.self_variables(@map_id, @id)
  end
end

Self Variables Script for Actors:

Code:
class Game_Actor < Game_Battler
 
  def variables
    @variables ||= Hash.new(0)
  end
end


class Game_Interpreter
 
  def actor_variables(actor_id)
    actor = $game_actors[actor_id]
    actor != nil ? actor.variables : Hash.new(0)
  end
 
  def member_variables(member_index = 0)
    actor = $game_party.members[member_index]
    actor != nil ? actor.variables : Hash.new(0)
  end
end

Here some Examples of the Script and in General:

$game_system.self_variables([ID of your Map], [EventId])[Self Var Name/Number] = 1234

$game_system.self_variables([$game_map.map_id], [1])[Villager Gold] = 1234

Iam not sure about the brackets [] , long time not used this and never realy did so in the past. But its an awesome Script.

The moment you assign something to a Self Variable thats the moment it gets created. So no need for any previous Setup.
The Variables also get Safed in the Safefiles as far as i know, so no known Bugs or Problem known. But i dont have any more code examples. the call for the seccond one i dont have but should be no problem to paste something together with the available infos.
@Kes

I grabbed it!! Thanks a million!!!! I thought it was lost forever! 😂

@Bex Thank you too!! This is probably a very noob question but "$game_system.self_variables([ID of your Map], [EventId])[Self Var Name/Number] = 1234" sets the self variable? Is there an example of how to check in a condition branch whether that variable is above or below a certain number?
1.
You could use inside of the Conditional Branch the Scriptline:
$game_system.self_variables([$game_map.map_id], [1])[Villager Gold] == 1000
or
$game_system.self_variables([$game_map.map_id], [1])[Villager Gold] >= 1000

This == or >= or <= is a condition, equal, equal or more, and equal or less. only < and > should also work.
+= is adding something to the Variable but the previous mentioned ones are for Conditional Branches

2.
If you want to use it inside the Eventcommand Script on Eventpage3 than i believe it was:
If $game_system.self_variables([$game_map.map_id], [1])[Villager Gold] >= 1000
"insert code to happen if yes"
else
"insert else stuff"
end

Iam not a Scripter and mostly very bad with Syntax, so you are lucky that i had to use this a few Times or partialy still have those Lines on my PC.
How Bex wrote the syntax is correct, but it's unnecessary because the scripter already made a method in Game_Interpreter to simplify a thing.

So instead of goes like this
Code:
$game_system.self_variables([ID of your Map], [EventId])[Self Var Name/Number] = 1234
You can go by this in script command
Code:
self_variables[id] = 123
Where ID is variable id (you can put anything on it. Be a number, or a letter, or event a word)

If you want to access other event's self variable (assume in same map), you can go by this
Code:
self_variables(event_id)[id] = 123
@Bex @TheoAllen Thank you two so much! I think I get the idea of how it should work now, the examples will be a great reference 😂
Thx TheoAllen, i didnt know that. Big thanks for sharing.
However, the script is not flawless. In default switch, variable, self switch, the map refreshed as soon as those value changed. In this script, it doesn't. It's because it doesn't have signal to refresh the map like default script do. So, if you're using another script that let you use self variable as page condition, it won't change as soon as the self variable value changed. Take this as consideration. Idk how self data suite gonna handle this, maybe also consider to use that script instead, or maybe another scripter will fix this?
It wouldn't take much to fix this. Just a command to set the refresh flag for the map in each variable/self switch/whatever that can be changed, just like Ace does it for variables and switches.
Hmm, well I guess I will give it a try with this basic script first. If it doesn't work for what I'm planning I'll just try the self data suit. If neither works I guess it'll be back to the drawing board for me 😅

Edit: The basic script you guys posted seems to work well so far.
Thanks for the explanation. But it never occured to me to use Self Variables for Eventpageconditions, always triggered a Selfswitch when needed in those cases,
Common Event or other Map Event controlled the Damage for the Self Variables for Monster HP, the Events used a Event ID Pointer to safe me the work of making all that conditional branches.

For Plant Growing is also a good Idea and it safes you from probably a dozen tons of repetitive workload.

Original thread: https://forums.rpgmakerweb.com/threads/self-variable-script-for-rm-vx-ace.95824/