UID95497
帖子
精華
主題
積分5444
現金
積極性
威望
違規
熱心
推廣次數
閱讀權限20
註冊時間2008-7-8
在線時間 小時
最後登錄1970-1-1
TA的每日心情 | 開心 2010-9-5 08:41 PM |
---|
簽到天數: 1 天 連續簽到: 0 天 [LV.1]初來乍到
|
發表於 2009-8-7 12:56:45
|
顯示全部樓層
*rand(<number>{,<number>});This function returns a number, randomly positioned between 0 and the number you
specify (if you only specify one) and the two numbers you specify if you give it
two.
rand(10) would result in 0,1,2,3,4,5,6,7,8 or 9
rand(2,10) would result in 2,3,4,5,6,7,8,9 or 10 *set <variable>,<expression>;This command will set a variable to the value that the expression results in.
This is the only way to set a variable directly.
This is the most basic script command and is used a lot whenever you try to do anything more advanced than just printing text into a messagebox.
set @x,100;
will make @x equal 100.
set @x,1+5/8+9;
will compute 1+5/8+9 (which is, surprisingly, 10 - remember, all numbers are integer in this language) and make @x equal it.
Returns the variable reference (since trunk r12870). *if (<condition>) <statement>;This is the basic conditional statement command, and just about the only one available in this scripting language.
The condition can be any expression. All expressions resulting in a non-zero value will be considered True, including negative values. All expressions resulting in a zero are false.
If the expression results in True, the statement will be executed. If it isn't true, nothing happens and we move on to the next line of the script.
if (1) mes "This will always print.";
if (0) mes "And this will never print.";
if (5) mes "This will also always print.";
if (-1) mes "Funny as it is, this will also print just fine.";
For more information on conditional operators see the operators section above.
Anything that is returned by a function can be used in a condition check without bothering to store it in a specific variable:
if (strcharinfo(0)=="Daniel Jackson") mes "It is true, you are Daniel!";
More examples of using the 'if' command in the real world:
Example 1:
set @var1,1;
input @var2;
if(@var1==@var2) goto L_Same;
mes "Sorry that is wrong";
close;
L_Same:
close;
Example 2:
set @var1,1;
input @var2;
if(@var1!=@var2) mes "Sorry that is wrong";
close;
(Notice examples 1 and 2 have the same effect.)
Example 3:
set @var1,@var1+1;
mes "[Forgetfull Man]";
if (@var==1) mes "This is the first time you have talked to me";
if (@var==2) mes "This is the second time you have talked to me";
if (@var==3) mes "This is the third time you have talked to me";
if (@var==4) mes "This is the forth time you have talked to me, but I think I am getting amnesia, I have forgoten about you";
if (@var==4) set @var,0;
close;
Example 4:
mes "[Quest Person]";
if(countitem(512)>=1) goto L_GiveApple;
// The number 512 was found from item_db, it is the item number for the Apple.
mes "Can you please bring me an apple?";
close;
L_GiveApple:
mes "Oh an apple, I didnt want it, I just wanted to see one";
close;
Example 5:
mes "[Person Checker]";
if($name$!=null) goto L_Check;
mes "Please tell me someones name";
next;
input $name$;
set $name2$,strcharinfo(0);
mes "[Person Checker]";
mes "Thank you";
L_Check:
if($name$==strcharinfo(0) ) goto L_SameName;
mes "[Person Checker]";
mes "You are not the person that " +$name2$+ " mentioned";
L_End:
set $name$,null;
set $name2$,null;
close;
L_SameName:
mes "[Person Checker]";
mes "You are the person that " +$name2$+ " just mentioned";
mes "nice to meet you";
goto L_End;
See 'strcharinfo' for explanation of what this function does.
Example 6: Using complex conditions.
mes "[Multi Checker]";
if( (@queststarted==1) && (countitem(512)>=5) ) goto L_MultiCheck;
// Only if the quest has been started AND You have 5 apples will it goto "L_MultiCheck"
mes "Please get me 5 apples";
set @queststarted,1;
close;
L_MultiCheck:
mes "[Multi Checker]";
mes "Well done you have started the quest of got me 5 apples";
mes "Thank you";
set @queststarted,0;
delitem 512,5;
close;
With the Advanced scripting engine, we got nested if's. That is:
if (<condition>)
dothis;
else
dothat;
If the condition doesn't meet, it'll do the action following the else.
We can also group several actions depending on a condition, the following way:
if (<condition)
{
dothis1;
dothis2;
dothis3;
} else {
dothat1;
dothat2;
dothat3;
dothat4;
}
Remember that if you plan to do several actions upon the condition being false, and you forget to use the curlies (the { } ), the second action will be executed regardless the output of the condition, unless of course, you stop the execution of the script if the condition is true (that is, in the first grouping using a return; , and end; or a close; )
Also, you can have multiple conditions nested or chained, and don't worry about limits as to
how many nested if you can have, there is no spoon ;)
...
if (<condition 1>)
dothis;
else if (<condition 2>)
{
dotheother;
do that;
end;
} else
do this;
... - set .@rand,rand(3);
- if(.@rand == 0) mes ".@rand變數等於0";
- else if(.@rand == 1) mes ".@rand變數等於1";
- else mes ".@rand變數等於2";
- close;
複製代碼 |
|