further about parameters:
as I can't really explain them that well myself, let me give an example of them in action:
(This is from the thread, ~ "Noob HK's Help Me Thread", in the latest posts, with my working on creating a combat system)
<command name="fight">
<pattern>fight #text#</pattern>
<script>
fight_function (game.pov,text)
</script>
</command>
parameters used:
game.pov
text
as this is a fight, combat, you vs "text"
there's an orc in the colloseum, you type: fight orc
the command runs the "fight_function" function, which will use the two objects: game.pov (you) and text (the orc)
<function name="fight_function" parameters="self,target">
enemy = GetObject (target)
If (enemy = null) {
msg ("That is not an object or it's not the object's NAME attribute.")
}
If (enemy.hostile = true) {
msg ("The " + enemy + " attacks you!")
self.hp = self.hp - enemy.damage
msg ("The " + enemy + " attacks you for " + enemy.damage + " damage!")
msg ("You attack the " + enemy +"!")
enemy.hp = enemy.hp - self.damage
msg ("You attack the " + enemy + " for " + self.damage + " damage!")
} else {
msg ("You can't attack that, it's not your enemy or it's not yet ... your enemy, silly!")
}
</function>
now, inside the function, "fight_function", game.pov -> self and text (orc) -> target -> enemy, as internally the game engine is substituting in "game.pov" for the function's new parameter~variable "self", and "text (orc)" for the function's new parameter~variable "enemy"
so, the use of parameters is like a way to "carry over" (and rename them too if you want to)* local variables from one script to another (and "non-nested" ~ separate) script (scripts, functions, and through~with call~ing functions).
*you don't have to rename the parameters:
<command name="fight">
<pattern>fight #text#</pattern>
<script>
fight_function (game.pov,text)
</script>
</command>
<function name="fight_function" parameters="game.pov,text">
enemy = GetObject (text)
If (enemy = null) {
msg ("That is not an object or it's not the object's NAME attribute.")
}
If (enemy.hostile = true) {
msg ("The " + enemy + " attacks you!")
game.pov.hp = game.pov.hp - enemy.damage
msg ("The " + enemy + " attacks you for " + enemy.damage + " damage!")
msg ("You attack the " + enemy +"!")
enemy.hp = enemy.hp - game.pov.damage
msg ("You attack the " + enemy + " for " + game.pov.damage + " damage!")
} else {
msg ("You can't attack that, it's not your enemy or it's not yet ... your enemy, silly!")
}
</function>
you have to convert "text" to "enemy" because you got to get the actual object of "text", so you've can actually work with it in the function, and also, it'll try to apply the string "text" and the object "enemy" to the "text" in the would-be: "text (instead of "enemy") = GetObject (text). Otherwise, in the Command script, you'd use for the pattern, fight #object# , as this will get the object right there, of what you typed in.
you can go many levels deep too with variables through parameters:
[code]<command name="fight">
<pattern>fight #text#</pattern>
<script>
fight_function (game.pov,text)
</script>
</command>
<function name="fight_function" parameters="self,target">
enemy = GetObject (target)
If (enemy = null) {
msg ("That is not an object or it's not the object's NAME attribute.")
}
If (enemy.hostile = true) {
msg ("The " + enemy + " attacks you!")
enemy_attack_function (self,enemy)
msg ("The " + enemy + " attacks you for " + enemy.damage + " damage!")
msg ("You attack the " + enemy +"!")
self_attack_function (self,enemy)
msg ("You attack the " + enemy + " for " + self.damage + " damage!")
} else {
msg ("You can't attack that, it's not your enemy or it's not yet ... your enemy, silly!")
}
</function>
<function name="enemy_attack_function" parameters="human,monster">
human.hp = human.hp - monster.damage
</function>
<function name="self_attack_function" parameters="human,monster">
monster.hp = monster.hp - human.damage
</function>
game.pov => self => human
(typed in: orc) => text => target => enemy => monster
also, last detail about parameters:
function 1: parameters="1A,2A,3A"
function 2: parameters="1B,2B,3B"
parameters="1st slot , 2nd slot , 3rd slot"
they always match up by order ("slot") of them being listed as I've shown above, as seen here below:
1A <=> 1B
2A <=> 2B
3A <=> 3B