2017年2月13日星期一

Script Guide_4 variables and conditional statement

[if] - the conditional statement

The script [if] is used to check flag, point score or other variables you want to store, this script goes with some conditions (  logical IF statement).
Read the next line of script automatically if the result is true, or go to the next script [end if] line if the result is false.

[if (@variable Operator Value)]
[end if]
variable: the name of variable. Write the name after “@” and end with a space. You can also use some value here.
Operator: can use == as equality; != as  inequality ; > as greater than    ;    >= greater than or equal to;<    less than;<=  less than or equal to.
Value: the value you want to check can be a round number or string. You can also use variable here.

&&  logical AND  and    ||   logical OR   are supported in this script. Use a pair of bracket to split the statements.
[if (1>2)||(1<2)] obtains True
[if (1>2)&&(1<2)] obtains False
[if (1>2)||(1<2)||(1<3)] obtains True
You cannot use another [if] in a pair of [if] and [end if],use a [goto] instead.

Example: check a flag

[eval @food =carrot]
[eval @number =5]
[dialog bunny| what did I eat last night]
[if @food == carrot]
[dialog bunny|I had cabbage]
[goto labelC]
[end if]

[dialog bunny| the result is false if it is not carrot]
[goto somewhere]

[label labelC]
[if @number >3]
[dialog bunny| I ate too much]
[end if]

[label somewhere]

In this example, it will check the food type and the number. If the food type obtains false, the script will jump to another label and never check the number again.



[eval] -assignment statement

It usually need to store some value such flags and points in a game. The script [eval] is used to gave variables a value and store it. Read the next line of script automatically .

[eval @variable Operator Value]
variable: the name of variable. Write the name after “@” and end with a space.
Operator: can use + addition; - subtraction and = to evaluation.
Value:  can be a round number or string. You can also use variable here.

When you want to show a variable in dialog or some text, use a “@” and a space.

Example: evaluation a variable

[eval @food =carrots]
[eval @number =5]
[dialog bunny| I ate @number  @food  this morning. ]
[eval @number +1]
[dialog bunny| I ate @number  today. ]

the bunny will say “I ate 5 carrots this morning.” and”I ate 6 today.”
if you use [eval @number +another] after this, the result will be ”I ate 1another today.” Be careful to use number and string .A string does not support the subtraction operator.

All variables which defined in the init file will be stored in a save files. The variables in staticvar will write in file once their value are changed. If a variable has not been defined, you can still use it but it will not write in a save file.





标签: , ,

0 条评论:

发表评论

订阅 博文评论 [Atom]

<< 主页