Coding Help

Ok. This is frustrating me. This should work. But I am obviously missing something. The below is a function, called combat. I can call it from a room and pass it the name of the monster the player is fighting. Here's the problem. First, everything prints at once! I want it to stop after the player hits a monster, ask if the player wishes to test luck to do more damage, then print out all the stuff afterwards. The other issue I am having is that the mname.stamina in the part where they test luck is kicking back an invalid variable name, even though it is working in the top part.

msg ("<table style=\"width: 75%\"><tr><th>Combantant</th> <th align=\"center\">Skill</th> <th align=\"center\">Stamina</th> <th align=\"center\">Luck</th></tr> <tr> <td><b><font color=\"blue\">Player</b></font></td> <td align=\"center\">{player.skillcurrent}</td> <td align=\"center\">{player.staminacurrent}</td> <td align=\"center\">{player.luckcurrent}</td> </tr> <td><b><font color=\"red\">" + mname.alias + "</b></font></td> <td align=\"center\">" + mname.skill + "</td> <td align=\"center\">" + mname.stamina + "</td></tr> </table>")
mroll = mname.skill + DiceRoll ("2d6")
proll = player.skillcurrent + DiceRoll ("2d6")
msg ("<b><font color=\"blue\">Player Roll: "+ proll)
msg ("<b><font color=\"red\">" + mname.alias + " Roll: "+ mroll)
if (proll > mroll) {
  msg ("You damaged your opponent for 2 Stamina!")
  mname.stamina = mname.stamina - 2
  ShowMenu ("Do you want to test your Luck for more damage?", Split ("Yes; No", ";"), false) {
    switch (result) {
      case ("Yes") {
        lroll = DiceRoll ("2d6")
        if (lroll < player.luckcurrent) {
          msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
          mname.stamina = mname.stamina - 2
          player.luckcurrent = player.luckcurrent - 1
        }
        else {
          msg ("You luck roll was unsuccessful!")
          player.luckcurrent = player.luckcurrent - 1
        }
      }
    }
  }
}
else {
  msg ("You were damaged for 2 Stamina!")
  player.staminacurrent = player.staminacurrent - 2
  ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
  }
}
msg ("<table style=\"width: 75%\"><tr><th>Combantant</th> <th align=\"center\">Skill</th> <th align=\"center\">Stamina</th> <th align=\"center\">Luck</th></tr> <tr> <td><b><font color=\"blue\">Player</b></font></td> <td align=\"center\">{player.skillcurrent}</td> <td align=\"center\">{player.staminacurrent}</td> <td align=\"center\">{player.luckcurrent}</td> </tr> <td><b><font color=\"red\">" + mname.alias + "</b></font></td> <td align=\"center\">" + mname.skill + "</td> <td align=\"center\">" + mname.stamina + "</td></tr> </table>")

K.V.

Is mname an object?


If you want that last message to print after the ShowMenu() selection, do this (NOTE: You don't have a script to check if the answer was yes or no, but I'm just working with what you posted):

else {
  msg ("You were damaged for 2 Stamina!")
  player.staminacurrent = player.staminacurrent - 2
  ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
    msg ("<table style=\"width: 75%\"><tr><th>Combantant</th> <th align=\"center\">Skill</th> <th align=\"center\">Stamina</th> <th align=\"center\">Luck</th></tr> <tr> <td><b><font color=\"blue\">Player</b></font></td> <td align=\"center\">{player.skillcurrent}</td> <td align=\"center\">{player.staminacurrent}</td> <td align=\"center\">{player.luckcurrent}</td> </tr> <td><b><font color=\"red\">" + mname.alias + "</b></font></td> <td align=\"center\">" + mname.skill + "</td> <td align=\"center\">" + mname.stamina + "</td></tr> </table>")
  }
}


Can you post your entire code?


for 'yes/no', there's a built-in menu Script/Function:

// popup menu window:

ask ("YOUR_QUESTION") {
  if (result) {
    // scripting for 'yes' (true)
  } else {
    // scripting for 'no' (false)
  }
}

or, in-line/hyperlink menu:

Ask ("YOUR_QUESTION") {
  if (result) {
    // scripting for 'yes' (true)
  } else {
    // scripting for 'no' (false)
  }
}

No. I didn't do the result for reduction of damage yet. I was trying to get the first part to work first. I removed the second message. Realized I didn't really need it. But I am still having the issue, if the select yes to test their luck I get the following error:

Error running script: Error compiling expression 'mname.stamina - 2': Unknown object or variable 'mname'

Which is weird since it had no issue with it earlier in the function.

And if it helps, here is the entire function:

  <function name="combat" parameters="mname" type="string"><![CDATA[
    msg ("<table style=\"width: 75%\"><tr><th>Combantant</th> <th align=\"center\">Skill</th> <th align=\"center\">Stamina</th> <th align=\"center\">Luck</th></tr> <tr> <td><b><font color=\"blue\">Player</b></font></td> <td align=\"center\">{player.skillcurrent}</td> <td align=\"center\">{player.staminacurrent}</td> <td align=\"center\">{player.luckcurrent}</td> </tr> <td><b><font color=\"red\">" + mname.alias + "</b></font></td> <td align=\"center\">" + mname.skill + "</td> <td align=\"center\">" + mname.stamina + "</td></tr> </table>")
    mroll = mname.skill + DiceRoll ("2d6")
    proll = player.skillcurrent + DiceRoll ("2d6")
    msg ("<b><font color=\"blue\">Player Roll: "+ proll)
    msg ("<b><font color=\"red\">" + mname.alias + " Roll: "+ mroll)
    if (proll > mroll) {
      msg ("You damaged your opponent for 2 Stamina!")
      mname.stamina = mname.stamina - 2
      ShowMenu ("Do you want to test your Luck for more damage?", Split ("Yes; No", ";"), false) {
        switch (result) {
          case ("Yes") {
            lroll = DiceRoll ("2d6")
            if (lroll < player.luckcurrent) {
              msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
              mname.stamina = mname.stamina - 2
              player.luckcurrent = player.luckcurrent - 1
            }
            else {
              msg ("You luck roll was unsuccessful!")
              player.luckcurrent = player.luckcurrent - 1
            }
          }
        }
      }
    }
    else {
      msg ("You were damaged for 2 Stamina!")
      player.staminacurrent = player.staminacurrent - 2
      ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
      }
    }
  ]]></function>

unfortunately, for either: the 'ShowMenu', or (less likely), the 'switch', Scripts/Functions, your 'mname' VARIABLE needs to be passed into it via/as a Parameter/Argument, which it is not being so, and hence the 'unknown mname' ERROR MESSAGE. If this is the issue... you'll have to create your own menu

OR:

make sure your argument value is an Object (no double quotes, and it has to be an actual existing Object), for example:

// ---------------------------

// example of it:

// create ("orc")
// orc.WHATEVER_ATTRIBUTE = VALUE_OR_EXPRESSION
// etc etc etc setting/creating Attributes (stamina, alias, luckcurrent, skill, skillcurrent, etc) for your 'orc' Object

combat (orc)


and make sure that your Object has all of the Attributes that are used within your 'combat' Function's Scripting


P.S.

you got two instances of 'mname.stamina = mname.stamina - 2', try removing out the first one, and see if you still got an error (if you have an error, this error is with the second instance of 'mname.stamina = mname.stamina - 2', then put back in this 1st instance of 'mname.stamina = mname.stamina - 2', and remove the 2nd instance of 'mname.stamina = mname.stamina -2', and see if you got an error (if you have an error, this error is with the first instance of 'mname.stamina = mname.stamina - 2', and report back to us about it, as it'll directly point us to exactly where/what the issue is, which we can then figure out how to fix it for you.


P.S.S.

it could be a spelling/typo mis-match issue... but I couldn't see any typos/spelling mis-match issues with anything.


K.V.

Post the script that calls that function when everything works, please.


K.V.

1. I don't see how that function doesn't throw an error without returning anything. (Or is it returning something, and I'm just overlooking it?)

2. HK is correct.

Play with this and watch things mess up left and right:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Passing Variables (and ShowMenu)">
    <gameid>ab540a5d-65f0-4054-9714-04129cc9d571</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script">
    </enter>
    <firstenter type="script">
      msg ("Fake function has returned this value: "+FakeFunction (npc_object1))
    </firstenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="npc_object1">
      <inherit name="editor_object" />
      <alias>Ludwig van Beethoven</alias>
      <usedefaultprefix type="boolean">false</usedefaultprefix>
    </object>
  </object>
  <function name="FakeFunction" parameters="fake_parameter" type="string">
    this = "temporary value"
    msg ("FakeFunction: fake_parameter.name = "+fake_parameter.name)
    msg ("")
    ShowMenu ("Pick YES or NO.  (It won't effect anything either way.)", Split("YES;NO",";"), false) {
      msg ("The fake_parameter's display name is: "+fake_parameter.name+".")
      msg ("The fake_parameter's display name is: {fake_parameter.name}.")
      this = GetDisplayName(fake_parameter)
    }
    msg ("This comes after ShowMenu in the script.")
    return (this)
  </function>
</asl>

Well, I don't think everyone is following me. So I will just post the entire code here.


<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="City of Thieves">
    <gameid>279159d1-909e-4eb4-af6e-c07a43336a6b</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
    <author>Ian Livingstone</author>
    <category>Fantasy</category>
    <start type="script">
      player.skillmax = 6 + DiceRoll ("1d6")
      player.skillcurrent = player.skillmax
      player.staminamax = 12 + DiceRoll ("2d6")
      player.staminacurrent = player.staminamax
      player.luckmax = 6 + DiceRoll ("1d6")
      player.luckcurrent = player.luckmax
    </start>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script">
      msg (" " + FirstDEATHHAWK.skill + " - " + FirstDEATHHAWK.stamina)
      combat (FirstDEATHHAWK)
      msg ("Enemy Stamine is " + FirstDEATHHAWK.stamina)
    </enter>
    <beforeenter type="script">
    </beforeenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <statusattributes type="stringdictionary">
        <item>
          <key>skilldisplay</key>
          <value>Skill: !</value>
        </item>
        <item>
          <key>staminadisplay</key>
          <value>Stamina: !</value>
        </item>
        <item>
          <key>luckdisplay</key>
          <value>Luck: !</value>
        </item>
      </statusattributes>
      <provisions type="int">10</provisions>
      <gold type="int">0</gold>
      <jewels type="int">0</jewels>
      <skillcurrent type="int">0</skillcurrent>
      <skillmax type="int">0</skillmax>
      <staminacurrent type="int">0</staminacurrent>
      <staminamax type="int">0</staminamax>
      <luckcurrent type="int">0</luckcurrent>
      <luckmax type="int">0</luckmax>
      <changedstaminacurrent type="script"><![CDATA[
        if (player.staminacurrent > player.staminamax) {
          player.staminacurrent = player.staminamax
        }
        if (player.staminacurrent < 1 ) {
          MoveObject (game.pov, Game Over)
        }
        player.staminadisplay = player.staminacurrent + " / " + player.staminamax
      ]]></changedstaminacurrent>
      <changedskillcurrent type="script"><![CDATA[
        if (player.skillcurrent > player.skillmax) {
          player.skillcurrent = player.skillmax
        }
        if (player.skillcurrent < 1 ) {
          MoveObject (game.pov, Game Over)
        }
        player.skilldisplay = player.skillcurrent + " / " + player.skillmax
      ]]></changedskillcurrent>
      <changedluckcurrent type="script"><![CDATA[
        if (player.luckcurrent > player.luckmax) {
          player.luckcurrent = player.luckmax
        }
        if (player.luckcurrent < 1 ) {
          MoveObject (game.pov, Game Over)
        }
        player.luckdisplay = player.luckcurrent + " / " + player.luckmax
      ]]></changedluckcurrent>
      <object name="sword">
        <inherit name="editor_object" />
        <alias>Sword</alias>
      </object>
      <object name="leatherarmor">
        <inherit name="editor_object" />
        <alias>Leather Armor</alias>
      </object>
      <object name="backpack">
        <inherit name="editor_object" />
        <alias>Backpack</alias>
      </object>
    </object>
  </object>
  <object name="potionofskill">
    <inherit name="editor_object" />
    <alias>Potion of Skill</alias>
    <take />
    <feature_usegive />
    <use type="script">
      msg ("You drink the potion and restore your Skill to it's maximum value.")
      player.skillcurrent = player.skillmax
    </use>
    <drink type="script">
      msg ("You drink the potion and restore your Skill to it's maximum value.")
      player.skillcurrent = player.skillmax
    </drink>
  </object>
  <object name="potionofstamina">
    <inherit name="editor_object" />
    <alias>Potion of Stamina</alias>
    <take />
    <feature_usegive />
    <use type="script">
      msg ("You drink the potion and restore your Stamina to it's maximum value.")
      player.staminacurrent = player.staminamax
    </use>
    <drink type="script">
      msg ("You drink the potion and restore your Skill to it's maximum value.")
      player.skillcurrent = player.skillmax
    </drink>
  </object>
  <object name="potionofluck">
    <inherit name="editor_object" />
    <alias>Potion of Luck</alias>
    <take />
    <feature_usegive />
    <use type="script">
      msg ("You drink the potion and restore your Luck to it's maximum value and increase it by 1!")
      player.luckmax = player.luckmax + 1
      player.luckcurrent = player.skillmax
    </use>
    <drink type="script">
      msg ("You drink the potion and restore your Skill to it's maximum value.")
      player.skillcurrent = player.skillmax
    </drink>
  </object>
  <object name="FirstDEATHHAWK">
    <inherit name="editor_object" />
    <stamina type="int">5</stamina>
    <skill type="int">4</skill>
    <alias>First DEATH HAWK</alias>
  </object>
  <function name="combat" parameters="mname" type="string"><![CDATA[
    msg ("<table style=\"width: 75%\"><tr><th>Combantant</th> <th align=\"center\">Skill</th> <th align=\"center\">Stamina</th> <th align=\"center\">Luck</th></tr> <tr> <td><b><font color=\"blue\">Player</b></font></td> <td align=\"center\">{player.skillcurrent}</td> <td align=\"center\">{player.staminacurrent}</td> <td align=\"center\">{player.luckcurrent}</td> </tr> <td><b><font color=\"red\">" + mname.alias + "</b></font></td> <td align=\"center\">" + mname.skill + "</td> <td align=\"center\">" + mname.stamina + "</td></tr> </table>")
    mroll = mname.skill + DiceRoll ("2d6")
    proll = player.skillcurrent + DiceRoll ("2d6")
    msg ("<b><font color=\"blue\">Player Roll: "+ proll)
    msg ("<b><font color=\"red\">" + mname.alias + " Roll: "+ mroll)
    if (proll > mroll) {
      msg ("You damaged your opponent for 2 Stamina!")
      mname.stamina = mname.stamina - 2
      ShowMenu ("Do you want to test your Luck for more damage?", Split ("Yes; No", ";"), false) {
        switch (result) {
          case ("Yes") {
            lroll = DiceRoll ("2d6")
            if (lroll < player.luckcurrent) {
              msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
              mname.stamina = mname.stamina - 2
              player.luckcurrent = player.luckcurrent - 1
            }
            else {
              msg ("You luck roll was unsuccessful!")
              player.luckcurrent = player.luckcurrent - 1
            }
          }
        }
      }
    }
    else {
      msg ("You were damaged for 2 Stamina!")
      player.staminacurrent = player.staminacurrent - 2
      ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
      }
    }
  ]]></function>
</asl>

K.V.

I have the game ready to test.

What steps do I take to recreate the error(s)?


Just start. If you as the player successfully attack (which happens most times), you'll see that it works fine and reduces the enemy's stamina. Then it will ask if you wish to test luck to do more damage. When you say yes and are successful (which, again, is most of the time). The error message pops up and doesn't reduce the enemy stamina. It's weird that it works the first time, but pops up an error when it trys to do it again.


K.V.

It's probably because of the dice roll. Sometimes it calls the script with the error, sometimes it calls the other.

Every time it says the roll was successful, I get the error.

The only way I can get it to fire the script is to restart the game. (I may be missing something.)


Try this (it fixes it for me):

msg ("<table style=\"width: 75%\"><tr><th>Combantant</th> <th align=\"center\">Skill</th> <th align=\"center\">Stamina</th> <th align=\"center\">Luck</th></tr> <tr> <td><b><font color=\"blue\">Player</b></font></td> <td align=\"center\">{player.skillcurrent}</td> <td align=\"center\">{player.staminacurrent}</td> <td align=\"center\">{player.luckcurrent}</td> </tr> <td><b><font color=\"red\">" + mname.alias + "</b></font></td> <td align=\"center\">" + mname.skill + "</td> <td align=\"center\">" + mname.stamina + "</td></tr> </table>")
mroll = mname.skill + DiceRoll ("2d6")
proll = player.skillcurrent + DiceRoll ("2d6")
msg ("<b><font color=\"blue\">Player Roll: "+ proll)
msg ("<b><font color=\"red\">" + mname.alias + " Roll: "+ mroll)
if (proll > mroll) {
  msg ("You damaged your opponent for 2 Stamina!")
  mname.stamina = mname.stamina - 2
  game.temporary_mname_stamina = mname.stamina
  game.temp_mname = mname
  ShowMenu ("Do you want to test your Luck for more damage?", Split ("Yes; No", ";"), false) {
    switch (result) {
      case ("Yes") {
        lroll = DiceRoll ("2d6")
        if (lroll < player.luckcurrent) {
          msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
          game.temporary_mname_stamina = game.temporary_mname_stamina - 2
          player.luckcurrent = player.luckcurrent - 1
        }
        else {
          msg ("You luck roll was unsuccessful!")
          player.luckcurrent = player.luckcurrent - 1
        }
      }
    }
    invoke (game.myTempShowMenuScript)
  }
  game.myTempShowMenuScript => {
    game.temp_mname.stamina = game.temporary_mname_stamina
    game.temporary_mname_stamina = null
    SetTurnTimeout(1){
      game.myTempShowMenuScript = null
    }
  }
}
else {
  msg ("You were damaged for 2 Stamina!")
  player.staminacurrent = player.staminacurrent - 2
  ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
  }
}

Edited

HK called it as soon as he saw the script.


Ok. That seems to be working. Now, here is another pickle. How do I run this function multiple times until the enemy is dead? The reason I'm doing this is some combats you can escape from and some you can't. So how do I tell the program "run this function once". I tried sticking the "combat (FirstDEATHHAWK)" in a while loop, but it just ran the function 3 times without ever checking the Luck statement. I got this:

Combantant Skill Stamina Luck
Player 9 18 11
First DEATH HAWK 4 5

Player Roll: 13
First DEATH HAWK Roll: 11
You damaged your opponent for 2 Stamina!
Do you want to test your Luck for more damage?
1: Yes
2: No
Combantant Skill Stamina Luck
Player 9 18 11
First DEATH HAWK 4 3

Player Roll: 16
First DEATH HAWK Roll: 16
You were damaged for 2 Stamina!
Do you want to test your Luck to reduce the damage?
1: Yes
2: No
Combantant Skill Stamina Luck
Player 9 16 11
First DEATH HAWK 4 3

Player Roll: 16
First DEATH HAWK Roll: 11
You damaged your opponent for 2 Stamina!
Do you want to test your Luck for more damage?
1: Yes
2: No
Combantant Skill Stamina Luck
Player 9 16 11
First DEATH HAWK 4 1

Player Roll: 17
First DEATH HAWK Roll: 6
You damaged your opponent for 2 Stamina!
Do you want to test your Luck for more damage?
1: Yes
2: No
Enemy Stamine is -1


from KV's post, it is the 'ShowMenu' Script/Function:

the 'ShowMenu' is a separate Script/Function from your 'combat' Function, which makes the 'mname' Parameter VARIABLE from your 'combat' Function 'out of scope', and hence the 'mname doesn't exist' ERROR.

we can see this in work with this:

this works fine (as we're passing/transferring our Parameter VARIABLE from Function to Function):

<game name="example_game">
  function_1 ("hi")
</game>

<function name="function_1" parameters="string_parameter_1">
  function_2 (string_parameter_1)
  // this is the same as doing:
  // function_2 (string_parameter_2) {
  //   msg (string_parameter_2)
  // }
</function>

<function name="function_2" parameters="string_parameter_2">
  msg (string_parameter_2)
</function>

----------------------

but this does NOT work:

<game name="example_game">
  function_1 ("hi")
</game>

<function name="function_1" parameters="string_parameter_1">
  function_2
  // this is the same as doing this (which is what the 'show menu/ShowMenu' is doing, well it has Parameters, but they're not related to inputting this input value of yours that you need inputted):
  //
  // function_2 () {
  //   msg (string_parameter_1)
  // }
</function>

<function name="function_2">
  msg (string_parameter_1)
</function>

you may be able to use a String Dictionary Attribute with its item's Values as String Dictionaries...

<game name="example_game">
  <dictionary_1 type="stringdictionary">
    <item>
      <key>yes</key>
      <value>game.dictionary_2</value>
    </item>
    <item>
      <key>no</key>
      <value>not_used_value</value>
    </item>
  </dictionary_1>
  <dictionary_2 type="stringdictionary">
    <item>
      <key>mname.
    </item>
  </dictionary_2>
</game>

// -----------------------

ShowMenu ("Do you want to test your Luck for more damage?", game.dictionary_1, false) {
}

ach.... this is way beyond my level... need Pixie's help... lol

there's probably some way to sneak in an extra VARIABLE... lol

well you could always have the value be a string... and use it... (and maybe via needing to use the String Manipulation Functions and/or make it into a String List and then use StringListItem)

for example:

<example_dictionary" type="stringdictionary">
  <item>
    <key>yes</key>
    <value>mname orc</value>
  </item>
  <item>
    <key>no</key>
    <value>not_used</value>
  </item>
</example_dictionary>

// -------

ShowMenu ("blah", game.example_dictionary, false) {
  if (result = "yes")
    string_variable = StringDictionaryItem (game.example_dictionary, "yes")
    stringlist_variable = split (string_variable, " ")
    // err... I'm stuck here... but hopefully you get ht idea... there's got to be a way to do it... I'm sure Pixie knows of a way to do this...
  }
}

easiest solutions:

use Attributes

runner-up in "easy-ness" :

make your own menu Function... (might not be easy to do, if you want it to be like the built-in 'ShowMenu / show menu' Functions, but if you just want a simple menu Function, I can help with that... well... you could just find the 'ShowMenu / show menu' code and copy/use it for your own menu Function, with the slight adjustment of adding in another Parameter for your input... to be used by your menu Function's copied scripting from the built-in 'ShowMenu / show menu' Function)


ah, multiple times, that's something easy for me, lol

if you get/use typed-in input, you HAVE TO (MUST) use 'tail recursion' (calling the Function/Script_Attribute within it: looping it), see my code below for an example of tail-recursion

if you don't get/use typed-in input, then you can use the 'while' Script/Function instead of 'tail recursion'

here's an example (horrible design, but it shows the concept of how its done):

<game name="example_game">
  <attr name="start" type="script">
    combat (orc)
    wait { // you may be able to use the 'on ready' ... but I'm not sure... when it can be used and when not (Pixie or whoever explained it, but I was still confused anyways, sighs)
      combat (orc) // this is to just see the 'The orc is already dead, silly' message displayed
    }
  </attr>
</game>

<object name="orc">
  <attr name="life" type="int">10</attr>
  <attr name="dead" type="boolean">false</attr>
</object>

<function name="combat" parameters="enemy">
  if (enemy.dead) {
    msg ("The " + enemy.name + " is already dead, silly")
  } else {
    enemy.life = enemy.life - 1
    msg ("You hit the " + enemy.name + " for 1 damage")
    if (enemy.life = 0) {
      enemy.dead = true
      msg ("You killed the " + enemy.name + "!")
    } else {
      combat (enemy)
    }
  }
</function>

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

Support

Forums