ozu_Self 1.0
by ozubon
Introduction
This is a self-variable or event variable plugin using mere 13 lines of code. Self-variables are saved with the game save, and persist through maps.
Self-variables? What?
Instead of using game variables for every event you can give the event its own variables. All those times you make new game variables for single events and your game variables list gets longer and... bloated..er... This, like other self-variable plugins seeks to address that. When you think about it, why
shouldn't events have their own variables?
How to use
Spoiler: Help file
Code: * =========================================================================== * Self-variables * =========================================================================== * A self-variable looks like this: * * self(this)[Variable id] * * Now that you know that, all you have to do is come up with a variable id * and set it to something! * * Let's say you want to set self-variable 1 to 9001 * Put this in a script call: * * self(this)[1] = 9001 * * Bonus: * You can have variable id's with names instead of numbers, but they gotta * be in quotation! * * self(this)["garlic cloves"] = 10 * * =========================================================================== * Conditional branch * =========================================================================== * This uses standard javascript operators, but don't panic, it's easy! * * To check if self-variable 1 is indeed 9001, put this into the conditional * branch script box: * * self(this)[1] == 9001 * * Don't use one lonely equal sign, one means set; two means compare! * * Here's some other operators: * * Greater than: > Less than: < * Greater than or equal to: >= Less than or equal to: <= * Not equal to: != Equal and equal type: === * * This will return true because garlic cloves is more than 9: * * self(this)["garlic cloves"] > 9 * * =========================================================================== * Math * =========================================================================== * These are the assignment operators: * * Set: = Mod: %= * Add: += Subtract: -= * Multiply: *= Divide: /= * * So, to add 3 to garlic cloves you do this: * * self(this)["garlic cloves"] += 3 * * Given that garlic cloves was 10, it is now 13! * * Bonus: MV's own modulo always return positive, if you want ot use it * it's a little extra finger work (or whatever you type with): * * self(this)["garlic cloves"] = self(this)["garlic cloves"].mod(5) * * =========================================================================== * Other events' variables * =========================================================================== * To access other events' variables all you have to do is replace "this" with * the id of the event. Let's say you want to set event 2's variable 3 to 4: * * self(2)[3] = 4 * * Or check in a conditional branch if it is 4: * * self(2)[3] == 4 * * =========================================================================== * Events on other maps * =========================================================================== * You can also access variables on events on other maps, to do that you * specify the map id after the event id: * * self(Event id, Map id)[Variable id] * * Let's say you want to set event 8 on map 7's potato variable to 6: * * self(8, 7)["potato"] = 6 * * Or check in a conditional branch if it is 6: * * self(8, 7)["potato"] == 6 * * =========================================================================== * Setting game variables to event variables * =========================================================================== * Simply, set a game variable using Control Variables with script operand: * * self(this)[Variable id] * * Some examples: * * self(this)[40] * self(3)["pebbles"] * self(1, 2)["quarks"] * 复制代码
Terms of use
You don't
have to credit me but I'd appreciate it!
For commercial use, you
gotta credit me!
Plugin
https://raw.githubusercontent.com/ozubon/tidbits/master/ozu_Self.js
Right-click link -> Save As
Credit
ozubon
本贴来自国际rpgmaker官方论坛作者:ozubon处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/ozu_self-no-frills-self-variables.121053/