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.