- Free for use in non-commercial projects with credits
- Contact me for commercial use
== Change Log ==
1.4 - Feb 24, 2016
fixed bug where setting a value to 0 doesn't set anything.
1.3 - Feb 10, 2016
added support for clearing self-variables
1.2 - Jan 27, 2016
Added support for script calls in move routes
1.1 - Dec 27, 2016
added support for specifying eventId and mapId in script calls
1.0 - Dec 9, 2015
Initial release
== Usage ==
To assign a value to a self-variable, use the script call
this.set_self_variable(NAME, VALUE)
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
this.set_self_variable("check_times", 1)
Which would set the variable called "check_times" to 1.
You can then get the value of this self-variable using the script call
this.get_self_variable("check_times")
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.
If you would like to clear an event's self-variable, you can say
If no event ID is specified, it is assumed to be the current event.
If no map ID is specified, it is assumed to be the current map
-- 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.
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
this.set_self_variable("interact_count", 1)
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
this.set_self_variable("myName", "tester")
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.