What is a script argument for?

From OHRRPGCE-Wiki
Jump to: navigation, search
Revise.png
This article does not meet the standard of quality we would like to have. Feel free to revise it and make it better by using the edit link at the top of the page. This tag should be removed when an editor feels it is of high quality.

The reason this article has been marked is: ideally a lot of things in here ought to be linked to their wiki entries

Contents

[edit] Definition/What they are

An argument is a piece of information that a script or command uses. In the vast majority of simple cases it is either a number, or a special word that stands for a number.

Before thinking about arguments for your scripts, it may be easier to see them used in basic commands. Simply put, there are some commands in Hamsterspeak that know what to do without any extra information. One example would be wait for text box. This command does not need any arguments, because it always does the same thing. On the other hand, the command show text box is rather useless on its own. It needs to know which text box to show, and the number of the text box you want to show is called the argument. We put arguments in parentheses like so:

show text box (13)

Here 13 is the argument for the command "show text box". Programmers say that they have "passed the argument 13 to the command show text box" in such scenarios.

[edit] How to use them in your own scripts

First of all, it should be noted that the majority of scripts that authors write will not need arguments of their own. They may use plenty of commands that need arguments, but the scripts themselves probably won't need any. What kind of scripts could an author write that would need their own arguments?

Scripts only need arguments if they are going to occur in a variety of situations. "Show text box" needs an argument because it is used in a variety of situations, each time doing something slightly different. Imagine for a moment that we want to write our own script that makes an NPC pace, that is, it makes an NPC walk one step to the left, stop for a moment, and then walk one step to the right (for simplicity's sake, we will leave this NPC facing right after he's done pacing). The reason this script needs an argument is that the script itself has no way of knowing which NPC is pacing, and if we want this same script to be used over and over in our game to make different NPCs pace, we need to make it use an argument. Here is how:

First, when we name our script, we have to give a name to our argument right away. I'm going to name the script "Pace NPC", and I'm going to name the argument "arg_Who", so my first line should look like:

plotscript, Pace NPC, arg_Who, begin

After the word plotscript comes the name of the script, then a comma, then the names of any arguments we're going to use separated by commas, then we use the word "begin" to signal the end of the list of arguments and the beginning of the actual script (This means you cannot name your argument "begin"!).

In the script itself, we can use our argument names as if they are variables. So for this example I type:

 walk npc (arg_Who, west, 1)
 wait for npc (arg_Who)
 wait (12) #this is so the NPC pauses before pacing back in the other direction
 walk npc (arg_Who, east, 1)
 wait for npc (arg_Who)
end

In the script above, the word "arg_Who" gets replaced by the argument that is passed to this script whenever it is used. Now to use this script, I can call it by name in any other script like so:

plotscript, My Other Script, begin
 #I'm gonna use this script to make NPCs 4, 5, and 12 all pace one after another.
 suspend npcs #This is to make sure the NPCs don't move on their own while I'm trying to make them pace
 Pace NPC (4) #The 4 is the argument that will take the place of "arg_Who" in the Pace NPC script!
 Pace NPC (5)
 Pace NPC (12)
 resume npcs
end

[edit] Advanced stuff

  • More than one argument - Just as the command "Walk NPC" needs three arguments (which NPC to walk, what direction, and how many steps), it is entirely possible to create scripts with as many arguments as desired to allow whatever flexibility is needed.
  • Arguments automatically passed by custom - There are lots of different ways that a script can be triggered in a game. Some of these triggering mechanisms automatically pass certain special arguments to whatever script they triggered. For example, when an NPC is set to trigger a plotscript, it passes two arguments to the script automatically - first is a number telling the script which NPC triggered the script (an NPC reference, not the NPC ID number), and secondly it sends whatever number it's told to in custom in the Edit NPCs submenu of the Map Editor.
  • Formulae, variables, and even scripts can be put into argument slots - Just as we can type "show text box (5+4)" to get a script to show text box number 9, we can pass all sorts of complicated junk as arguments in the parentheses of both commands and scripts as long as whatever it is that we put there boils down to a number in the end. Mathematical operations are easy to see and understand in this regard, but things can be more complicated.

[edit] See Also