What is a script argument for?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

Definition/What they are[edit]

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.

How to use them in your own scripts[edit]

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 "Who", so my first line should look like:

plotscript, Pace NPC, 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 (Who, west, 1)
 wait for npc (Who)
 wait (12) #this is so the NPC pauses before pacing back in the other direction
 walk npc (Who, east, 1)
 wait for npc (Who)
end

In the script above, the word 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 going to 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 "Who" in the Pace NPC script!
 Pace NPC (5)
 Pace NPC (12)
 resume npcs
end

Advanced stuff[edit]

  • 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. A list of the various ways to call scripts, and which arguments are sent by each, can be found here: Other Ways To Start A Script
  • Formulae, variables, and even calls to commands and 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 value in the end. Mathematical operations are easy to see and understand in this regard, but things can be more complicated. For example, we could create a new NPC and cause it to pace with "Pace NPC (create NPC (1, 2, 3))" (the create npc command returns an NPC reference).

See Also[edit]