This plugin introduces the concept of “Self Variables” for your events.
Similar to Self Switches, each event can hold its own set of self-variables, which you can use to keep track of things like how many times you’ve interacted with the event, or the last position of the player that this event has seen, or anything else that you would like each event to keep track of on their own.
An event can have as many self-variables you want as long as you find an appropriate name for them.
Unlike self-switches, which only hold a true or false value, self-variables can hold any kind of information. Because you can access them using script calls, they can be used in conditional branches and other parts of your event to create intricate events that interact with the player or the game itself!
Plugin: download here (right-click, save-as)
- Custom Page Conditions – use events to determine if a page can be activated
Download ths plugin and place it in the “plugins” folder in your project’s “js” folder. Then open your Plugin Manager (F10), double-click an empty row, and select the HIME_SelfVariables plugin.
Once it is in your list of plugins, turn the plugin on.
To assign a value to a self-variable, use the script call
Where the NAME is the name of the self-variable you want to use, and the VALUE is some value that you want to assign.
For example, it could be a number
Which would set the variable called “check_times” to 1. You can then get the value of this self-variable using the script call
Which will return the value 1.
The value of the variable can be anything you want, including numbers, strings, objects, booleans, functions, and so on. There is no restriction to what you would like to store, as long as you’re consistent.
Working with other events
Notice that the only two pieces of information you provide are
1. the variable name
2. the value (when setting a value)
This is because we assume you are operating on the current event, on the current map. You may also choose to operate on other events by specifying event ID’s and map ID’s in your script calls.
this.set_self_variable(NAME, VALUE, EVENT_ID) this.set_self_variable(NAME, VALUE, EVENT_ID, MAP_ID)
For example if you write
this.set_self_variable("test", 3, 4)
It will set the self-variable “test” to value 3, for event 4.
If you specify event 0, it will mean the current event.
If you write
this.set_self_variable("test", 3, 4, 2)
Then you are setting the self-variable “test” to 3, for event 4, on map 2.
Similar script calls are available for getting self-variables:
this.get_self_variable(NAME, EVENTID) this.get_self_variable(NAME, EVENTID, MAPID)
Working with self-variables and numbers
Unlike regular variables, you don’t have a nice editor dialog to work with. So if you wanted to manipulate them, you will have to use some script calls.
For example, let’s say you wanted to keep track of the number of times you’ve interacted with the event. The first time you interact with it, you would say
The next time you interact with it again, you would start by getting the value of the self-variable, increase it by 1, and then assigning that to the variable.
var oldCount = this.get_self_variable("interact_count") || 0; var newCount = oldCount + 1; this.set_self_variable("interact_count", newCount);
Note the extra part in that first line. This is a shortcut in case that variable never had a value to begin with. This may be useful if you’re strictly working with numbers.
Working with self-variables and strings
You can store strings (or “text”) inside self-variables as well. For example, you could say
And the variable called `myName` will now hold the value “tester”.
If you wanted to check the value of this variable equals “tester, you could something like
this.get_self_variable("myName") === "tester"
Which will return true or false depending on what the value of the variable is.
What syntax would I use if I wanted to set a self-variable to a standard game variable?
Hi, I was wondering if this script was compatible with RPG Maker VX Ace? I’m trying to make a farming system for my game in VX ace and the unique style I’m trying requires self variables.
Actually nevermind, I’ll just see for myself.
Hi, I love your stuff! Can this be used to set a variable to a random number? If so how? Thanks in advance!
Maybe you could set a regular variable to a random number and then change the self variable to match the regular variable.
Hi, I made a remote control plugin for rmmv that mass searches and sets values for your self variable plugin. Is that ok?
Can I check/set self variables for all events on defined map via script?
Hime, is it possible to change self variables of events from another event?
Sorry, that was stupid question… I get it.
Wouldn’t it be shorter to use;
this.set_self_variable(“counter”, this.get_self_variable(“counter”) + 1);
var oldCount = this.get_self_variable(“counter”);
var newCount = oldCount + 1;
Or will this can possibly cause an error?
The results would be the same. The example was just written out step-by-step to make things clearer.
Ah thanks for clarifying, I was getting paranoid there for a sec.
this.set_self_variable(“counter”, this.get_self_variable(“counter”) + 1);
this will result in error and the counter variable value will become NaN which I think the param don’t accept operator inside.
Anyway this will work
this.set_self_variable(“counter”, (this.get_self_variable(“counter”) || 0) + 1);
True. I assumed the variables were initialized beforehand, which may not be a good assumption.
Can I use self variables with Common events in any way?
It is possible, depending on how you use the common event.
Self-variables are associated with a particular event, based on the event ID and map ID which is used to uniquely identify an event (under the assumption that the combination is unique).
Now, what happens with common event is if a map event calls a common event, the common event will have the same event and map ID as the calling event.
So if you had a common event that increments self-variable “Call Times” by 1 everytime it’s called, and you had 3 events calling it, each event would have its OWN “Call Times” variable incremented each time.
If the common event is called by any other method, such as an item use or something, the behavior is undefined. Meaning, I don’t know what will happen, because it is not intended to be used for that.
Thanks for the great reply. I think this will work perfectly for me.
I wanted to use it in common events to clean up the amount of self variables used my other events.
Thank you for this. I’m using it in conjunction with Hidden Choices to hide a choice if you have previously selected it (so that you could theoretically go through the dialogue over and over choosing each choice one by one).
So, the first time a player selects a choice, I added this:
Script: this.set_self_variable(“Chose1”, 1)
Then, when checking whether to hide the choice next time I added this:
If: Script: this.get_self_variable(“Chose1″===1)
Plugin Command: hide_choice 1
But, the choice still appears the second time. What am I missing here?
I got ti! It should be:
Right? Woops, sorry! I’m learning this whole script call thing for the first time with this plugin.
Yes, the general syntax for comparing two things is
left === right
Omg! Thank you!! This is exactly what I needed to make an ABS combat for my rpg!
Hi, i’m using your plugin for a tree-chopping event.
so I set it up as:
then on action button:
var A = this.get_self_variable(“tree_hp”)
var B = var A – 1
So how do I make a new event page that activate when value of “tree_hp” is less than or equal to 0?
You can check the value of the self-variable and then enable a self-switch to go to a different page.
TypeError. Cannot read property ‘setValue’ of undefined.
You will need to provide more information. How are you using the plugin?
Whoops, nevermind. It works after I start the playtest as new game rather than continuing from a save file.
Anyway, what was the script call to set the number to a random value again?
Eg: this.set_self_variable(“dice”, Math.floor(Math.random()*6+1))) // doesn’t seem to work.
Thanks for your help!
Er…. nevermind my last post. It works. I just spelled “math” instead of “Math”.
Awesome Plugin, just what i was searching for ! But can we use other things than fixed numbers ?
Awesome plugin, just what i was searching for ! But can we make the self variable equal to the place X of the event, or the place Y and other variable things ?
Yes. You will need to be able to reference the event in order to do this.
For example, you might say
Is possible to set selfvariables to the actors?, for example to create new stats like Charism, or replace the default stats, whit something like STR, VIT, INT, WIS, DEX….
Not these self variables, since it was designed to be for events.
Hi, could you tell me how to use this together with Custom Page Conditions?
I tried using temporal variable to check conditional branch but this is not working.
I found the solution in your demo video. thanks.
This is an amazing script, but I can’t seem to get it to work with conditional branches. I set my variable name and value as such:
Then I try to use it in a conditional branch like so:
this.get_self_variable(“GACTION”) === “6”
What am I doing wrong.
Thank you for the help and the awesome plugins.
0 is a number. “6” is a string.
You need to compare numbers with numbers, and strings with strings.
this.get_self_variable(“GACTION”) === 6
Thank you for the fast reply! I tried that before, with no luck. I got the error “Cannot read property ‘X’ of undefined”. I also tried comparing the strings listed in the script help, with the same error.
I set using: this.set_self_variable(“myName”, “tester”)
I did the branch with: this.get_self_variable(“myName”) === “tester”
What am I missing?
Make something similar using this demo and then send it to me so I can take a look. That “X” is strange.
I am actually kind of embarrassed to say this, but I found the issue. I was using plugin calls instead of script calls. So sorry to have wasted your time. Thank you for all of your help.
I’ve had that a couple times lol
Hey, this is an awsome plugin that sure helps to tidy up the database. I tried to use this together with Conditional Choice Text.
This is the sciptcall I used:
choice_text(1, "Rookie Fight(check)", "this.get_self_variable("Rookie_Fight") === 1")
But when I playtest and try to trigger the event it returns Syntax error: Unexpected identifier. Is this an error on my part or is it a compatibility error? I know this line is causing the error because without it everything run exactly the way it is supposed to.
Resolved on issue tracker. For reference: https://github.com/Hime-Works/Requests/issues/320