Basically, % is a special character.
If a "word" is surrounded by %percent%, it means "insert the value of the variable by the name percent".
I use word in quotes because it doesn't need to be between spaces and can (and often do) contain punctuation. Basically, if it starts with a (non-doubled) percent sign, and ends with one, it's a variable.
To escape a %, it must be doubled to %%. When the string %% is evaluated, it will evaluate to a single %, with no special meaning.
The key word in the previous sentence is
evaluated. The thing
eval does. As opposed to
set which just copies a value,
eval will actually parse the input.
So, in this code:
Code:
1 set thecard card_8
2 eval temp %%self.varexists(%thecard%)%%
3 eval hascard %temp%
4 if %hascard%
will be executed like this:
Code:
1 sets the value of thecard to card_8
2 evaluates the string "%%self.varexists(%thecard%)%%" from left to right:
"%%" is "%"
"self.varexists(" is unchanged "self.varexists(" since there are no special chars
"%thecard%" is the value of the variable named thecard, "card_8"
")" is unchanged, ) is not a special char in strings
"%%" becomes "%"
combined this becomes "%self.varexists(card_8)%" which is the put into the temp variable.
3 evaluates the value of %temp% (remember, % means get the value of the variable and insert it here, verbatim).
This value is "%self.varexists(card_8)%", which is evaluated.
The answer, either 1 or 0 is put into the hascard variable.
4 evaluates the value of the hascard variable, either 0 or 1. In this case, it performs a branching based on the value.
I haven't seen examples of using more than two percent signs at a time, but it is of course possible.
It probably helps if you, everytime you write %something% not think of it as the variable, but the
value of the variable.
If it helps; this is emergent behaviour, which was never considered during the design phase. which is why it isn't documented anywhere.