About Script Calls

Discussion in 'RPG Maker MV' started by gundriveth, May 19, 2018.

  1. gundriveth

    gundriveth Medievaliant Veteran

    Messages:
    91
    Likes Received:
    29
    Location:
    Indonesia
    First Language:
    Bahasa
    Primarily Uses:
    RMMV
    Hello,
    I have some questions about Script Call that I can't figure it out myself. I know about the existence of Script Call list, but...
    • How to make use/maximize the efficiency of using Script Call? Like, maybe something that cannot be implemented by Event Commands but it can.
    • Can you give me an example of what can be done? (the written code in Script box might really help!)
    • Is it possible that the Script Call can be used/useful in writing plugin?
    Getting a creative block here. Please help whaha.
    Thank you!
     
    #1
  2. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,934
    Likes Received:
    9,942
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    It's difficult to give an answer to this question.
    Because you can execute literally anything inside the script box.
    Nevertheless, script field should ONLY be used for small chunks of simple code. For example for loops, function calls or small simple maths.
    The reason for that is that script field uses eval, which is almost 10000x slower in terms of code execution than standard function definition.
    So even though you can execute anything (and by anything I really mean anything) in the script field, it's better to leave more complex code for plugins.
    It can be used to integrate your plugins into the events though, so you can define a function inside a plugin and then just call it inside an event via script command.

    But to give you an example, this is an example of changing variable 1.

    script: $gameVariables.setValue(1, 300);

    Show message: \v[1]

    script: $gameVariables.setValue(1, 500)

    Show message: \v[1]

    I can't show a print screen, because I don't have a working pc right now.
     
    #2
    gundriveth and caethyril like this.
  3. Kuro DCupu

    Kuro DCupu Trust me, I'm a veteran RMer Veteran

    Messages:
    251
    Likes Received:
    1,044
    Location:
    Indonesia
    First Language:
    Indonesian
    Primarily Uses:
    RMMV
    Script calls open the possibility to tap into RPG Maker's full potential.
    To answer each of your question :
    • Script call is basically a "write your own event" command.
      Sometimes you just didn't find a command that do certain something. Maybe you want an NPC to confiscated all your dangerous equipment before entering the city and you want the NPC to return it later. But there's no "remove equipment only" in your event command. And you have no idea how to store those equipment data. That's where a script call come in handy.

    • Sure. Many example shown in public is for manipulating data, so you can't actually tell. So I'll give you one that have an immediate visual effect.
      RMMV, right? Copy this script call in your event, then trigger it!
      Code:
      _blackbox = new Sprite(new Bitmap(300,300));
      _blackbox.bitmap.fillAll('black');
      SceneManager._scene.addChild(_blackbox); 
      It might be just spawning a 300x300 black box. But imagine all the possibility you can do with it.
      With more dedication and know-how, you can even create something that break the limitation of RPG Maker.

      Everything's happen there, from the splash screen, title screen, dialog, battle system, walking, popup, whatever is made entirely from an event command with script call support.

    • What we call "plugin" IS a bunch of script. It is "write your own command", so technically you can do anything... within the limitation of course. But script call is part of an event command. Event can only be called from a map (scene_map) and battle (scene_battle). So that's the limitation.
     
    #3
    gundriveth, Poryg and caethyril like this.
  4. Aesica

    Aesica undefined Veteran

    Messages:
    796
    Likes Received:
    752
    Location:
    SW5GMW 4xVHk
    First Language:
    English
    Primarily Uses:
    RMMV
    To be honest, the script call box really isn't all that useful unless you want to do some quick, short bit of manipulation to something directly within the game's object structure. Here's what I mean:

    As mentioned already, the script box code is executed by eval, meaning it gets evaluated and executed on the fly and is thus significantly slower and less efficient. It's also a lot harder to debug because it isn't always obvious where exactly the error is coming from. The script box also has a character limit, which imo is a good thing because it discourages people from writing out complex functions and whatnot. Sure, you could write all the complex stuff in your own plugin, then reference it via the script box, however that leads me to my next point:

    For calling your own plugin's functions, you're really better off setting up plugin commands to access them. They're simpler and less messy to use, even if you're the only one who's ever going to be using your plugin.

    For example, I wrote a thing to streamline giving items to players, so that, with one simple line, I can a) give the player an item, weapon, armor, or gold in whatever quantities I wanted, b) play a sound that would be associated with acquiring an item, and c) display a message like, "Acquired Potion x3" with the intent that every item acquisition would appear uniform and easily recognizable. Certainly better than trying to make every single treasure box/etc present items to players in the same way. I had two possible ways to invoke this newly-created functionality:

    1) The script approach would look something like this: Aesica.Utilities.obtainItem(2, 4, 1); With parameters being type (2=armor), itemId, and quantity in that order. Not bad, but still a bit messy.

    2) The plugin command approach would look something like this: ObtainArmor 4 1 Which is a lot cleaner and easier to remember. In fact, i even set it up so that 1 was the default and thus, the quantity part could be left blank to imply a value of one, making the final command: ObtainArmor 4
     
    #4
    gundriveth likes this.
  5. gundriveth

    gundriveth Medievaliant Veteran

    Messages:
    91
    Likes Received:
    29
    Location:
    Indonesia
    First Language:
    Bahasa
    Primarily Uses:
    RMMV
    Hey guys thanks for the replies. Really appreciate it. :D
    I think I get a much better understanding of the Script Calls.

    So, we can do everything with it but limited compared to plugins. And I guess to actually invoke this " endless possibilities" depends on
    how much I know Javascript and how RMMV works (the files inside js folder), right?

    No other way around then, just need to learn further.
     
    #5
  6. Poryg

    Poryg Dark Lord of the Castle of Javascreeps Veteran

    Messages:
    3,934
    Likes Received:
    9,942
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Precisely. In fact you're also not limited to just Javascript. MV uses NW.js as the executable and NW.js also allows for c++ stuff. And due to the fact that you can customize all of your in game code you can do pretty much anything, because you can even alter how MV event commands behave in that particular game.
     
    #6
    caethyril likes this.

Share This Page