Home
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Details for command getarg:
* getarg <number>{,<Default Value>};
This function is used when you use the 'callsub' or 'callfunc' commands. In the
call you can specify variables that will make that call different from another
one. This function willwill return an argument the function or subroutine was
called with, and is the normal way to get them.
This is another thing that can let you use the same but of code more than once.
Argument numbering starts with 0, i.e. the first argument you gave is number 0.
If no such argument was given, a zero is returned.
place,50,50,6%TAB%script%TAB%Woman1%TAB%115,{
mes "[Woman]";
mes "Lets see if you win";
callfunc "funcNPC",2;
mes "Well done you have won";
...
place,52,50,6%TAB%script%TAB%Woman2%TAB%115,{
mes "[Woman]";
mes "Lets see if you win";
callfunc "funcNPC",5;
mes "Well done you have won";
...
function%TAB%script%TAB%funcNPC%TAB%{
set @win, rand(getarg(0));
if(@win==0) return;
mes "Sorry you lost";
"woman1" NPC object calls the funcNPC. The argument it gives in this call is
stated as 2, so when the random number is generated by the 'rand' function, it
can only be 0 or 1. Whereas "woman2" gives 5 as the argument number 0 when
calling the function, so the random number could be 0, 1, 2, 3 or 4, this makes
"woman2" less likely to say the player won.
You can pass multiple arguments in a function call:
callfunc "funcNPC",5,4,3;
getarg(0) would be 5, getarg(1) would be 4 and getarg(2) would be 3.
'getarg()' can also be used to carry information back from using the "callfunc"
script command, if the 'return' command is set to return a value:
place,50,50,6%TAB%script%TAB%Woman%TAB%115,{
mes "[Woman]";
mes "Lets see if you win";
callfunc "funcNPC";
mes "Well it seems you have "+getarg(0);
}
function%TAB%script%TAB%funcNPC%TAB%{
set @win, rand(2);
if(@win==0) return(won);
return(lost);
}
It is, however, better to use 'set' to get this value instead (see 'callfunc')
because otherwise you can't call functions from within other functions. (Return
values mess up the stack.)
Getarg has an optional argument since trunk r10773.
If the target argument exists, it is returned.
Otherwise, if <default_value> is present it is returned instead,
if not the script terminates immediately.
in the previous example getarg(2,-1) would be 3 and getarg(3,-1) would be -1
Return Values:
- When there is no argument found: The given default value