设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 88|回复: 0

[转载发布] Scripting shorthands - various utilities to make simple scripts easier

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    7959

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    29925
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    38778

    灌水之王

    发表于 3 天前 | 显示全部楼层 |阅读模式


    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
    1. $gameVariables
    复制代码
    every time you want to use a game variable - you now need 5 times fewer keystrokes with
    1. $gv
    复制代码
    . But that's not all! Instead of using
    1. value
    复制代码
    and
    1. setValue
    复制代码
    functions, you can read and write
    1. $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:
    1. $gameVariables.value(42)
    复制代码
    can be replaces with
    1. $gv[42]
    复制代码
    1. $gameVariables.setValue(42, 100)
    复制代码
    turns into
    1. $gv[42] = 100
    复制代码
    1. $gameVariables.setValue(42, $gameVariables.value(42) + 5)
    复制代码
    becomes just
    1. $gv[42] += 5
    复制代码

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

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

    Examples:
    1. $gameSwitches.value(42)
    复制代码
    ->
    1. $gs[42]
    复制代码
    1. $gameSwitches.setValue(42, true)
    复制代码
    ->
    1. $gs[42] = true
    复制代码

    $ss
    And of course, there's also something for self-switches! Use
    1. $ss.x
    复制代码
    to access self-switch X, e.g.
    1. $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.
    1. $gameSelfSwitches.setValue([$gameMap._mapId, this.eventId(), 'C'], true)
    复制代码
    ->
    1. $ss.c = true
    复制代码
    A check if all basic self-switches are on (doing this normally is so annoying I won't even show it) ->
    1. $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
    1. $ossa
    复制代码
    ,
    1. $ossb
    复制代码
    ,
    1. $ossc
    复制代码
    and
    1. $ossd
    复制代码
    can each be used to access corresponding self-switches of another event on the same map, by adding its ID in brackets.

    Examples:
    1. $gameSelfSwitches.value([$gameMap._mapId, 42,'A'])
    复制代码
    ->
    1. $ossa[42]
    复制代码
    1. $gameSelfSwitches.setValue([$gameMap._mapId, 42,'B'], true)
    复制代码
    ->
    1. $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.
    1. $ossa["11-15"]
    复制代码
    will return a list of the values of self-switch A for events 11, 12, 13, 14 and 15, e.g.
    1. [false, true, false, false, true]
    复制代码
    1. $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. [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.
    1. $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
    1. 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
    1. 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
    1. $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
    1. $windows.get(Window_Gold).open()
    复制代码
    instead of
    1. SceneManager._scene._windowLayer.children.find(x=>x instanceof Window_Gold).open()
    复制代码
    . Or use
    1. $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.


    本贴来自国际rpgmaker官方论坛作者:Mac15001900处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/scripting-shorthands-various-utilities-to-make-simple-scripts-easier.166955/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-1 02:37 , Processed in 0.090003 second(s), 53 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表