Variable
|
this-any-computer |
this-any-computer-ally |
this-any-computer-enemy |
this-any-computer-neutral |
this-any-human |
this-any-human-ally |
this-any-human-neutral |
this-any-neutral |
Rule variables are variables with a rule scope. This means that the variables are set within a rule and can be
used only within the same rule.
Only implicit variables are supported - the variables set by the system.
The variables have to be used as <player-number> argument in one of the following actions:
- chat-to-player
- chat-to-player-using-id
- clear-tribute-memory
- set-stance
- tribute-to-player
The variables are set by the associated wildcard parameters used in facts. For example:
any-enemy wildcard that is successful will store its result in this-any-enemy.
Here is an example of how variables can be used in rules:
(defrule
(players-civ any-enemy gothic)
=>
(chat-to-player this-any-enemy "I know you are a Goth")
(disable-self)
)
In this example the fact players-civ looks for an enemy player that is a Goth. If the enemy with that
civilization is found, the fact is true causing the rule to trigger. At the same time, the result of the
wildcard search is stored in this-any-enemy. The action chat-to-player is executed and uses this-any-enemy
variable to send a message to the appropriate enemy that has chosen to be a Goth.
It is important to remember that the variables have a rule scope. This means that once the rule has executed the
value in the variable becomes invalid. For example, if the following rule followed the one above, the message
"Hi, my Goth enemy" would not be sent.
(defrule
(true)
=>
(chat-to-player this-any-enemy "Hi, my Goth enemy") ; this is never sent
(disable-self)
)
|