Function Help

Ok. Trying to create a Function called Combat. The parameters that are passed to it are (enemy_name, enemy_av, enemy_armor, enemy_damage, enemy_hp). Here is the code inside it:

msg ("You must fight the " + enemy_name + ".")
s = "<table width="100%" style="border: thin solid;background:white;">"
s = s + " "
s = s + " <td colspan="4" text-align:left;">"
s = s + "" + enemy_name + ""
s = s + " "
s = s + " "
s = s + " "
s = s + " "
s = s + "AV: " + enemy_av
s = s + " "
s = s + " "
s = s + "Armor: " + enemy_armor
s = s + " "
s = s + " "
s = s + "DMG: " + enemy_damage
s = s + " "
s = s + " "
s = s + "Hit Points: " + enemy_hp
s = s + " "
s = s + " "
s = s + ""
msg (s)
round = 1
msg ("Round " + round + ".")
if (player.missile_equipped = True) {
ShowMenu ("Do you wish to attack with your missile weapon?", Split("Yes;No", ";"), false) {
if (result = "Yes") {
enemy_hp = Missile_Attack (enemy_name, enemy_armor, enemy_av, enemy_hp)
s = "<table width="100%" style="border: thin solid;background:white;">"
s = s + " "
s = s + " <td colspan="4" text-align:left;">"
s = s + "" + enemy_name + ""
s = s + " "
s = s + " "
s = s + " "
s = s + " "
s = s + "AV: " + enemy_av
s = s + " "
s = s + " "
s = s + "Armor: " + enemy_armor
s = s + " "
s = s + " "
s = s + "DMG: " + enemy_damage
s = s + " "
s = s + " "
s = s + "Hit Points: " + enemy_hp
s = s + " "
s = s + " "
s = s + ""
msg (s)
}
}
}

So the parameters are recognized throughout until I use them to call the Missile_Attack. Then the program errors out saying "Unknown object or variable 'enemy_name'". So what am I doing wrong?


ShowMenu displays a menu, and makes a note of a piece of code to be run next turn, when the player has chosen a menu option.

Local variables are only available while the function is running. So before next turn, they've already gone.

If you need to use variables inside the ShowMenu block, you should assign them to an attribute first, so they will still be accessible the following turn.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums