Scripting shorthands - various utilities to make simple scripts easier

1710796749117.png

An example of this plugin in action.

Synopsis
Howdy! Do you like to sometimes use scripts in your conditional branches and other commands? Are you annoyed at how much typing that requires? Well, you're in luck! *slaps roof of plugin* This bad boy can save you so many keystrokes! Let me show you just what it can do.

Features
$gv
First of all, you no longer need to type $gameVariables every time you want to use a game variable - you now need 5 times fewer keystrokes with$gv. But that's not all! Instead of using value and setValue functions, you can read and write $gv values just like with regular JavaScript variables, using an array-style bracket notation to specify the variable ID. What does that mean in practise? Just take a look at those examples:

$gameVariables.value(42) can be replaces with $gv[42]
$gameVariables.setValue(42, 100) turns into $gv[42] = 100
$gameVariables.setValue(42, $gameVariables.value(42) + 5) becomes just $gv[42] += 5

Behind the scenes, they still use regular value and setValue functions - for maximum plugin compatibility and to make sure event page conditions update properly (which they wouldn't if those were just simple $gameVariables._data aliases).

$gs
As you might have guessed, this shorthand serves a very similar function to $gv, but it's for switches. That's about all there is to say about it, really.

Examples:
$gameSwitches.value(42) -> $gs[42]
$gameSwitches.setValue(42, true) -> $gs[42] = true

$ss
And of course, there's also something for self-switches! Use $ss.x to access self-switch X, e.g. $ss.a to access self-switch A of the currently running non-parallel event. You don't even need an interpreter reference or know the ID of the that event.

Use them similarly to $gv and $gs, e.g.
$gameSelfSwitches.setValue([$gameMap._mapId, this.eventId(), 'C'], true) -> $ss.c = true
A check if all basic self-switches are on (doing this normally is so annoying I won't even show it) -> $ss.a && $ss.b && $ss.c && $ss.d

But that's not all! Download now and you'll get 22 brand new self-switches for free! That's right, you can also use letters from F to Z the same way you'd use A, B, C and D. The editor might not let you use those in most places, but they'll work just fine in scripts.

$oss
But what about self-switches on other events? Well, there's something for those too - four things in fact! Shorthands $ossa, $ossb, $ossc and $ossd can each be used to access corresponding self-switches of another event on the same map, by adding its ID in brackets.

Examples:
$gameSelfSwitches.value([$gameMap._mapId, 42,'A']) -> $ossa[42]
$gameSelfSwitches.setValue([$gameMap._mapId, 42,'B'], true) -> $ossb[42] = true

But that's not all! They can also be used to access the same self-switch on a range of events simultanously, by using a string with two numbers separated by a dash to indicate the first and last ID.
$ossa["11-15"] will return a list of the values of self-switch A for events 11, 12, 13, 14 and 15, e.g. [false, true, false, false, true]
$ossa["11-15"] = true will set self-switch A on all those events to true.

There's no built-in function for doing this on non-consecutive event IDs, but it can still be done reasonably easily like so: [1, 5, 34, 42].forEach(id => $ossa[id] = true);.

$es
So, the problem with switches, is that while you can now more easily access them, you still have to name them, and set them where needed... what if you didn't have to? This shorthand is here to solve that problem too! Well, sometimes. Usually not. But sometimes.

$es, standing for "event seen", is a quick way to check if the player has already interacted with another event on the same map. $es[42] will be true if the event with ID 42 has already been interacted with - so if that's all you need to know, you no longer have to use a switch just for that. And since it's set to true for a given event when it ends, it also doubles as a quick way to check if this is the first time the player is interacting with the current event.

Note: this feature is disabled by default, since it requires a change to the engine; you can enable it in plugin parameters.

$inp
The interpreter - it's needed to do all sort of things, and while it can be accessed with this inside of an event, it can be a bit annoying to get it elsewhere. But fear not, for now you have a very simple shorthand to get the currently active non-parallel interpreter: simply type $inp!

$windows
And this one here is an object with a bunch of different functions to help you with retrieving windows. Details can be found in the help file, but for an example of what it can do for you, you can now open the gold window anywhere with $windows.get(Window_Gold).open() instead of SceneManager._scene._windowLayer.children.find(x=>x instanceof Window_Gold).open(). Or use $windows.all() to get a list of all windows in the current scene, which is a really nice thing to have when trying to debug them from console.

Terms
Now, you might be asking yourself, what will all those cool features cost you? Well, it comes to a grand total of... $0. You really can't beat a price like that! It's also available under the MIT Licence - you can use it in your non-commercial games, in your commercial games, in your own plugins, or sell T-Shirts with the code printed out on them. Credit is appreciated but not required.


I'm also very open to the idea of expanding this plugin with even more QoL features, so if you have any suggestions please feel free to send them my way.
Neat idea!

I think something that might be handy for people is an easier way to set other self switches.

If you have multiple spaces in a corridor that can all trigger the same cutscene, setting all their self switches at the end is more efficient than needing a global variable or switch for every cutscene in the game.

But that's a super cumbersome script call.

So maybe a short hand for that would be useful - perhaps presume it's for an event on the same map, and you end up with (for example) Other Self Switch: $oss.14.a = true turns on self switch A for event 14 on whatever map you're currently on.

I've also seen this requested a few times - I think you might get bonus points if all the reference points for variables/switches/event IDs could also accept their names from the editor.
Neat idea!

I think something that might be handy for people is an easier way to set other self switches.

If you have multiple spaces in a corridor that can all trigger the same cutscene, setting all their self switches at the end is more efficient than needing a global variable or switch for every cutscene in the game.

But that's a super cumbersome script call.

So maybe a short hand for that would be useful - perhaps presume it's for an event on the same map, and you end up with (for example) Other Self Switch: $oss.14.a = true turns on self switch A for event 14 on whatever map you're currently on.

I've also seen this requested a few times - I think you might get bonus points if all the reference points for variables/switches/event IDs could also accept their names from the editor.
I guess I should probably add something like this. The reason I didn't do that in the first place was because in my project I like to keep things well encapsulated and try not to do that, but I suppose other people might want to work differently.

And to add some shameless self-promotion, that corridor situation is a perfect example of what Run Nearby Event is for, no switches or remotely set self-switches needed 😛
Speaking for myself, I have examples in my game where the same tutorial or conversation can be triggered in different places on the map, so they're not nearby each other but I still want to turn them all off at the same time; I consider hitting all their self switches to be cleaner than throwing junk into the global space 😉

But either way, neat concept for the plugin.
Huh, I guess that might be a reason I never needed to do that while other people do - this is also something I'd do with multiple events triggering the tutorial/conversation event, with only that event handling conditions on whether to actually run.

Definitely a good reason to include this feature, maybe even with some easy way to do that for multiple events.
its specially short than conditionalBrance+ which has this kind, also for weapons.
yours is specifically to selfswitches, switches and variables, but other selfSwitches
is missing as only thing, but nice list you made for those that uses it a lot.

I keep it on the other plugin for now, maybe you can simply it with $oss[mapId, eventId, true/false]
Version 1.1 is now available!

To update, download the file from the first post, replace your old file with it, and open the plugin in the plugin manager (to make sure the new option generates).

By popular request (well, of at least 2 different people), there's now a shorthand for self-switches of other events on the current map. Four of them in fact, one for each letter. You can read the updated first post for details (below the $ss section). A quick peek at the syntax:
$ossa[42] = true to set a single self-switch A
$ossb["11-15"] = true to set seft-switches B on a range of events
View attachment 298886
An example of this plugin in action.

Synopsis
Howdy! Do you like to sometimes use scripts in your conditional branches and other commands? Are you annoyed at how much typing that requires? Well, you're in luck! *slaps roof of plugin* This bad boy can save you so many keystrokes! Let me show you just what it can do.

Features
$gv
First of all, you no longer need to type $gameVariables every time you want to use a game variable - you now need 5 times fewer keystrokes with$gv. But that's not all! Instead of using value and setValue functions, you can read and write $gv values just like with regular JavaScript variables, using an array-style bracket notation to specify the variable ID. What does that mean in practise? Just take a look at those examples:

$gameVariables.value(42) can be replaces with $gv[42]
$gameVariables.setValue(42, 100) turns into $gv[42] = 100
$gameVariables.setValue(42, $gameVariables.value(42) + 5) becomes just $gv[42] += 5

Behind the scenes, they still use regular value and setValue functions - for maximum plugin compatibility and to make sure event page conditions update properly (which they wouldn't if those were just simple $gameVariables._data aliases).

$gs
As you might have guessed, this shorthand serves a very similar function to $gv, but it's for switches. That's about all there is to say about it, really.

Examples:
$gameSwitches.value(42) -> $gs[42]
$gameSwitches.setValue(42, true) -> $gs[42] = true

$ss
And of course, there's also something for self-switches! Use $ss.x to access self-switch X, e.g. $ss.a to access self-switch A of the currently running non-parallel event. You don't even need an interpreter reference or know that ID of the that event.

Use them similarly to $gv and $gs, e.g.
$gameSelfSwitches.setValue([$gameMap._mapId, this.eventId(), 'C'], true) -> $ss.c = true
A check if all basic self-switches are on (doing this normally is so annoying I won't even show it) -> $ss.a && $ss.b && $ss.c && $ss.d

But that's not all! Download now and you'll get 22 brand new self-switches for free! That's right, you can also use letters from F to Z the same way you'd use A, B, C and D. The editor might not let you use those in most places, but they'll work just fine in scripts.

$oss
But what about self-switches on other events? Well, there's something for those too - four things in fact! Shorthands $ossa, $ossb, $ossc and $ossd can each be used to access corresponding self-switches of another event on the same map, by adding its ID in brackets.

Examples:
$gameSelfSwitches.value([$gameMap._mapId, 42,'A']) -> $ossa[42]
$gameSelfSwitches.setValue([$gameMap._mapId, 42,'B'], true) -> $ossb[42] = true

But that's not all! They can also be used to access the same self-switch on a range of events simultanously, by using a string with two numbers separated by a dash to indicate the first and last ID.
$ossa["11-15"] will return a list of the values of self-switch A for events 11, 12, 13, 14 and 15, e.g. [false, true, false, false, true]
$ossa["11-15"] = true will set self-switch A on all those events to true.

There's no built-in function for doing this on non-consecutive event IDs, but it can still be done reasonably easily like so: [1, 5, 34, 42].forEach(id => $ossa[id] = true);.

$es
So, the problem with switches, is that while you can now more easily access them, you still have to name them, and set them where needed... what if you didn't have to? This shorthand is here to solve that problem too! Well, sometimes. Usually not. But sometimes.

$es, standing for "event seen", is a quick way to check if the player has already interacted with another event on the same map. $es[42]will be true if the event with ID 42 has already been interacted with - so if that's all you need to know, you no longer have to use a switch just for that. And since it's set to true for a given event when it ends, it also doubles as a quick way to check if this is the first time the player is interacting with the current event.

Note: this feature is disabled by default, since it requires a change to the engine; you can enable it in plugin parameters.

$inp
The interpreter - it's needed to do all sort of things, and while it can be access with this inside of an event, it can be a bit annoying to get it elsewhere. But fear not, for now you have a very simple shorthand to get the currently active non-parallel interpreter: simply type $inp!

$windows
And this one here is an object with a bunch of different functions to help you with retrieving windows. Details can be found in the help file, but for an example of what it can do for you, you can now open the gold window anywhere with $windows.get(Window_Gold).open() instead of SceneManager._scene._windowLayer.children.find(x=>x instanceof Window_Gold).open(). Or use $windows.all() to get a list of all windows in the current scene, which is a really nice thing to have when trying to debug them from console.

Terms
Now, you might be asking yourself, what will all those cool features cost you? Well, it comes to a grand total of... $0. You really can't beat a price like that! It's also available under the MIT Licence - you can use it in your non-commercial games, in your commercial games, in your own plugins, or sell T-Shirts with the code printed out on them. Credit is appreciated but not required.


I'm also very open to the idea of expanding this plugin with even more QoL features, so if you have any suggestions please feel free to send them my way.
Awesome stuff!

You wouldn't happen to have things like $subject and $target for skills/items/etc trying to run common events, would you?

Currently in battle I am doing things like BattleManager._action._targetIndex, _subjectEnemyIndex, etc. I've also rigged the evalDamageFormula to push a and b to v['user'] and v['target'] as another means to getting the user and target. Yanfly's Skill Core does help a lot with the eval script stuff, though.

Thanks!
You wouldn't happen to have things like $subject and $target for skills/items/etc trying to run common events, would you?
My game has neither items nor combat, so this plugin is definitely lacking in those areas 😛 I'd definitely be happy to expand into them too.

So, if I understand it correctly, you have items or skills that have some special effects, which are implemented by making those items/skills run common events. And you'd like a simpler way to reference the target that a given item/skill was used on?

I've also seen this requested a few times - I think you might get bonus points if all the reference points for variables/switches/event IDs could also accept their names from the editor.
I've somehow managed to miss this part part of your post earlier. It definitely sounds like it would be useful to make more complex variable operations look more readable. Might be a bit tricky to implement this efficiently, but I think I have some ideas.
So, if I understand it correctly, you have items or skills that have some special effects, which are implemented by making those items/skills run common events. And you'd like a simpler way to reference the target that a given item/skill was used on?
Correct - just something more intuitive if it is not too much to ask. I know Yanfly has it in the notes but the common events tied to skill/items have no way of knowing besides using the BattleManager, $gameParty._targetActorId, or adding a fake state and then checking actors/enemies for the state to figure out the target.

The damage formula uses a, b, etc. Intuitive design would be that when the common event is placed within the item/skill/etc, it should have access to that same information as well as the notes/damage formula/game action as a whole (shorthand instead of searching through the BattleManager or other places just to get the user and target).

Thanks!
So, I'm not going to interfere with this as a suggestion for Mac, but to offer a few bits of thought:
I know Yanfly has it in the notes but the common events tied to skill/items have no way of knowing besides using the BattleManager, $gameParty._targetActorId, or adding a fake state and then checking actors/enemies for the state to figure out the target.
Most people who are using Yanfly's plugins with access to these notetags would probably reproduce the effects of the common event inside that notetag instead of calling a common event at all.

Intuitive design would be that when the common event is placed within the item/skill/etc, it should have access to that same information as well as the notes/damage formula/game action as a whole
The problem with that is that by the time a common event in the Effects of a skill or item is called, the action has been resolved (and I'd have to double check, but I believe deleted). So trying to refer to it as a whole would fail.

You could certainly track the ID used, which is one of the things they added in MZ, but then you'd be only accessing the properties stored in the database.
So, I'm not going to interfere with this as a suggestion for Mac, but to offer a few bits of thought:

Most people who are using Yanfly's plugins with access to these notetags would probably reproduce the effects of the common event inside that notetag instead of calling a common event at all.


The problem with that is that by the time a common event in the Effects of a skill or item is called, the action has been resolved (and I'd have to double check, but I believe deleted). So trying to refer to it as a whole would fail.

You could certainly track the ID used, which is one of the things they added in MZ, but then you'd be only accessing the properties stored in the database.
Thanks for the response! Yes, those notes are very useful. I just thought it would be nice to have something for those who are not using the plugin.

The BattleManager._action does retain some info that stays until the next action is performed - I was thinking having something easier to remember since Mac was already working on things for shorthand.
Thanks a lot for this quality of life addition! This plugin is gonna be so helpful for my eventing!

I'm adding this to my project right away. Thanks again.
I hope I found this earlier. It is really neat.

Though I think most developers end up writing their syntax sugars after a boring period of copy'n paste. For example, I use $gameEvent for current event, $E to replace $gameMap.event,etc.
I think yours are much much better.😀
Hi I'm trying to use $oss but every time I do I get an error, for example :
$ossa[x] = true; in a script call RMMZ tells me that ossa is not defined, any idea ?
Thanks 🙂
Hi I'm trying to use $oss but every time I do I get an error, for example :
$ossa[x] = true; in a script call RMMZ tells me that ossa is not defined, any idea ?
Thanks 🙂
This is an MV plugin, and my capacity to support MZ is rather limited due to not having it.

Though why would $ossa ever be undefined (I'm assuming you didn't disable it) is an interesting puzzle. I seem to remember that MZ removed a bunch of things from the title screen, and I'm guessing that involves creating switches later on, leaving them undefined when Scripting Shorthands initialises things, which leads to creating a Proxy for an undefined object, making it itself undefined. If so, this might be fixable if you replace line 282 (originally an empty one) with:
JavaScript:
$.createShorthands();
This has the disadvantage of most of the plugin not working on the title screen, but afaik you can't really run events there in MZ, so hopefully it won't be too much of an issue.
Hi MAC ! Thank you for your reply, I didn't even realize this plugin is for MV... Another member recommanded me this plugin in another thread, so I didn't check...
I've tried to follow your instructions however the line 282 isn't an empty one, and is in the middle of one of the $es function.

Spoiler: line 282
mac_shorthand282.png

Do you mean the 282th line after comments ?

This has the disadvantage of most of the plugin not working on the title screen, but afaik you can't really run events there in MZ, so hopefully it won't be too much of an issue.

I do not need to use this on TitleScreen, well I do but my TitleScreen is made through eventing so there shouldn't be any issue there.

Thanks again 🙂
Hi MAC ! Thank you for your reply, I didn't even realize this plugin is for MV... Another member recommanded me this plugin in another thread, so I didn't check...
Sorry, I didn't check, either - I didn't realize Mac doesn't own MZ, I just assumed it was cross-released for both engines.

On the up side, if you can't get it working, it's not like the regular script call for self switches is that complicated: $gameSelfSwitches.setValue([map ID, event ID, "letter"], true/false)

So, for example, $gameSelfSwitches.setValue([4, 22, "A"], true)
to set event 22 on map 4's A switch to on. It's certainly longer than the shorthand in this plugin, but you can just keep that in a file or note box someplace and copy and paste as necessary.
I've tried to follow your instructions however the line 282 isn't an empty one
Ah, I looked a different version - I meant the empty one at 280 (though other ones here should work anyway). Also note that you will need to enable $es for this to work (it's disabled by default).
On the up side, if you can't get it working, it's not like the regular script call for self switches is that complicated: $gameSelfSwitches.setValue([map ID, event ID, "letter"], true/false)
Yep, that's what I've been using ever since you've told me about selfswitches' script calls being a thing! It works like a charm :LZScheeze:... But since we write a lot it's neater to use oss instead. Especially for conditional branches and variables script option, it also makes it more readable! (With RM's UI not being resizable and all... :LZSoops:)

Ah, I looked a different version - I meant the empty one at 280 (though other ones here should work anyway). Also note that you will need to enable $es for this to work (it's disabled by default).
Haha no worries! It does work now. Thanks a bunch, that's nice of you! :LZSproud:

For anyone having the same issue do not forget to give $es a variable to work with in plugin paramaters after adding the line 280.

Thanks again to both of you!!

Original thread: https://forums.rpgmakerweb.com/threads/scripting-shorthands-various-utilities-to-make-simple-scripts-easier.166955/