Help with Coding

Ok. I've banged my head long enough. Can someone more experienced with Quest help me. I do some programming, but the logic of Quest confounds me and doesn't work logically. So I'm going to post what I have so far below.

Here is what I want. I want to be able to have a function called "Combat" where I can send it the name of a monster (which is an object in the game) and have the player fight one round of combat with the monster. At the room level I would like to be able to tell Quest to either fight the monster to the death (fight until Monster life < 0) or fight the monster for a number of rounds and give the player the option to flee or continue fighting. Once I get this combat portion figured out then the rest of the programming will be simple. I just cant seem to figure this out.

<!--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"><![CDATA[
      msg (" " + FirstDEATHHAWK.skill + " - " + FirstDEATHHAWK.stamina)
      while (FirstDEATHHAWK.stamina > 0) {
        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)
    game.temporary_mname_stamina = mname.stamina
    game.temp_mname = mname
    if (proll > mroll) {
      msg ("You damaged your opponent for 2 Stamina!")
      game.temporary_mname_stamina = game.temporary_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!")
              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)
    }
  ]]></function>
</asl>

How about this?

(I added functions and a turnscript, but not commands.)

(I tested it a few times. It seems to keep going (or to go for the correct amount of turns, depending on which function is called). This depends on you removing the opponent from the room when it is defeated.)

<!--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)
      // KV moved FirstDEATHHAWK to this room to make testing easy, and \
      // replaced your while script with the next 2 lines (you need both!):
      FightRounds (FirstDEATHHAWK, 3)
      combat (FirstDEATHHAWK)
      //
      // You could also put these 2 lines (you need both!):
      // FightUntilDead(FirstDEATHHAWK)
      // combat(FirstDEATHHAWK)
      //
      // OR, TO JUST ATTACK ONCE:
      // combat(FirstDEATHHAWK)
      //
      // End of KV's changes
      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 name="FirstDEATHHAWK">
      <inherit name="editor_object" />
      <stamina type="int">5</stamina>
      <skill type="int">4</skill>
      <alias>First DEATH HAWK</alias>
    </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>
  <turnscript name="fight_until_dead_turnscript">
    <enabled />
    <script>
      if (HasAttribute(game.pov,"incombat")) {
        if (game.pov.incombat) {
          if (HasAttribute(game.pov,"opponent")) {
            if (game.pov.parent = game.pov.opponent.parent) {
              combat (game.pov.opponent)
            }
          }
        }
      }
    </script>
  </turnscript>
  <function name="combat" parameters="mname" type="string"><![CDATA[
    // KV moved this next before the ShowMenu, so it will exist during the script
    if (not HasAttribute(game,"myTempShowMenuScript")) {
      game.myCombatShowMenuScript => {
        game.temp_mname.stamina = game.temporary_mname_stamina
        game.temporary_mname_stamina = null
      }
    }
    // END OF KV MOVING THINGS
    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)
    game.temporary_mname_stamina = mname.stamina
    game.temp_mname = mname
    if (proll > mroll) {
      msg ("You damaged your opponent for 2 Stamina!")
      game.temporary_mname_stamina = game.temporary_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!")
              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.myCombatShowMenuScript)
      }
    }
    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>
  <function name="FightRounds" parameters="object, rounds">
    if (not TypeOf(rounds) = "int") {
      if (not IsInt(rounds)) {
        error ("FightRounds:  rounds parameter must be an integer")
      }
      else {
        rounds = ToInt(rounds)
      }
    }
    game.pov.opponent = object
    game.pov.incombat = true
    SetTurnTimeout (rounds+1) {
      game.pov.opponent = null
      game.pov.incombat = false
    }
  </function>
  <function name="FightUntilDead" parameters="object">
    game.pov.opponent = object
    game.pov.incombat = true
  </function>
</asl>

We can help with the commands, too, if you like.


I pasted this into a new program and seems to be working ok. The only problem is, the combat never ends. The monster gets to -1 stamina and the combat never stops.


This depends on you removing the opponent from the room when it is defeated.

...but hold on. I can change it to depend on the opponent's stamina being less than 1.


Here you are:

<!--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)
      // KV moved FirstDEATHHAWK to this room to make testing easy, and \
      // replaced your while script with the next line:
      FightRounds (FirstDEATHHAWK, 3)
      //
      // You could also put this line:
      // FightUntilDead(FirstDEATHHAWK)
      //
      // OR, TO JUST ATTACK ONCE:
      // combat(FirstDEATHHAWK)
      //
      // End of KV's changes
      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 name="FirstDEATHHAWK">
      <inherit name="editor_object" />
      <stamina type="int">5</stamina>
      <skill type="int">4</skill>
      <alias>First DEATH HAWK</alias>
      <changedstamina type="script">
        // Added by KV for debugging
        Log ("FirstDEATHHAWK.stamina = "+ ToString(FirstDEATHHAWK.stamina))
      </changedstamina>
    </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>
  <turnscript name="fight_until_dead_turnscript">
    <enabled />
    <script><![CDATA[
      if (HasAttribute(game.pov,"incombat")) {
        if (game.pov.incombat) {
          if (HasAttribute(game.pov,"opponent")) {
            if (game.pov.parent = game.pov.opponent.parent) {
              if (game.pov.opponent.stamina > 0) {
                combat (game.pov.opponent)
              }
            }
          }
        }
      }
    ]]></script>
  </turnscript>
  <function name="combat" parameters="mname" type="string"><![CDATA[
    // KV moved this next before the ShowMenu, so it will exist during the script
    if (not HasAttribute(game,"myTempShowMenuScript")) {
      game.myCombatShowMenuScript => {
        game.temp_mname.stamina = game.temporary_mname_stamina
        game.temporary_mname_stamina = null
      }
    }
    // added this next line for debbuging
    // BE SURE TO REMOVE IT!!
    Log ("Running combat function.")
    // END OF KV MOVING THINGS
    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)
    game.temporary_mname_stamina = mname.stamina
    game.temp_mname = mname
    if (proll > mroll) {
      msg ("You damaged your opponent for 2 Stamina!")
      game.temporary_mname_stamina = game.temporary_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!")
              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.myCombatShowMenuScript)
      }
    }
    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)
    }
    // The next 6 lines are for debugging
    // BE SURE TO REMOVE THEM!!!
    Log ("opponent stamina:")
    stamina = ""
    if (mname.stamina<0) {
      stamina = "-"
    }
    stamina = stamina + mname.stamina
    Log (stamina)
    Log ("end of combat function")
  ]]></function>
  <function name="FightRounds" parameters="object, rounds">
    if (not TypeOf(rounds) = "int") {
      if (not IsInt(rounds)) {
        error ("FightRounds:  rounds parameter must be an integer")
      }
      else {
        rounds = ToInt(rounds)
      }
    }
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
    SetTurnTimeout (rounds+1) {
      game.pov.opponent = null
      game.pov.incombat = false
    }
  </function>
  <function name="FightUntilDead" parameters="object">
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
  </function>
</asl>

You can look at the log to see what happens behind the scenes.

I changed the way you call the functions I added in, too.

Look at the code in full code view to see the scripts with my notes intact.

Some things will need to be removed after testing is complete. (I add numerous entries to the log.)


Hate to be picky. But when the enemy is at less than 1 stamina, there is no need to check Luck to do more damage. It should just skip to done and remove the enemy from the room.


I didn't fool around up in that part of the code.

I can, if you'd like...

Just say the word.


INVISICLUE

The word is [BLORPLE].


BLORPLE lol


Have you played that game? (Spellbreaker?)

Man! I bet I typed BLORPLE more than a thousand times! (And it's not one of the easier words to type! Those INFOCOM bastards!!! (I love 'em!))

Anyway, how about this?

<!--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)
      // KV moved FirstDEATHHAWK to this room to make testing easy, and \
      // replaced your while script with the next line:
      FightRounds (FirstDEATHHAWK, 3)
      //
      // You could also put this line:
      // FightUntilDead(FirstDEATHHAWK)
      //
      // OR, TO JUST ATTACK ONCE:
      // combat(FirstDEATHHAWK)
      //
      // End of KV's changes
      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 name="FirstDEATHHAWK">
      <inherit name="editor_object" />
      <stamina type="int">5</stamina>
      <skill type="int">4</skill>
      <alias>First DEATH HAWK</alias>
      <changedstamina type="script">
        // Added by KV for debugging
        Log ("FirstDEATHHAWK.stamina = "+ ToString(FirstDEATHHAWK.stamina))
      </changedstamina>
    </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>
  <turnscript name="fight_until_dead_turnscript">
    <enabled />
    <script><![CDATA[
      if (HasAttribute(game.pov,"incombat")) {
        if (game.pov.incombat) {
          if (HasAttribute(game.pov,"opponent")) {
            if (game.pov.parent = game.pov.opponent.parent) {
              if (game.pov.opponent.stamina > 0) {
                combat (game.pov.opponent)
              }
            }
          }
        }
      }
    ]]></script>
  </turnscript>
  <function name="combat" parameters="mname" type="string"><![CDATA[
    // KV moved this next before the ShowMenu, so it will exist during the script
    if (not HasAttribute(game,"myTempShowMenuScript")) {
      game.myCombatShowMenuScript => {
        game.temp_mname.stamina = game.temporary_mname_stamina
        game.temporary_mname_stamina = null
      }
    }
    // added this next line for debbuging
    // BE SURE TO REMOVE IT!!
    Log ("Running combat function.")
    // END OF KV MOVING THINGS
    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)
    game.temporary_mname_stamina = mname.stamina
    game.temp_mname = mname
    if (proll > mroll) {
      msg ("You damaged your opponent for 2 Stamina!")
      game.temporary_mname_stamina = game.temporary_mname_stamina - 2
      if (mname.stamina>0) {
        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.myCombatShowMenuScript)
        }
      }
    }
    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)
    }
    // The next 6 lines are for debugging
    // BE SURE TO REMOVE THEM!!!
    Log ("opponent stamina:")
    stamina = ""
    if (mname.stamina<0) {
      stamina = "-"
    }
    stamina = stamina + mname.stamina
    Log (stamina)
    Log ("end of combat function")
  ]]></function>
  <function name="FightRounds" parameters="object, rounds">
    if (not TypeOf(rounds) = "int") {
      if (not IsInt(rounds)) {
        error ("FightRounds:  rounds parameter must be an integer")
      }
      else {
        rounds = ToInt(rounds)
      }
    }
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
    SetTurnTimeout (rounds+1) {
      game.pov.opponent = null
      game.pov.incombat = false
    }
  </function>
  <function name="FightUntilDead" parameters="object">
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
  </function>
</asl>

Close. But it doesn't stop when they reach less than 0. It still asks one extra time before stopping:

Enemy Health: 5
player hits for 2 (enemy at 3)
Do you wish to test luck for extra damage?
successful -2 more damage (enemy at 1)
player hits for 2 damage (enemy at -1)
Do you wish to test luck for extra damage? (it should have stopped here)
If you answer No then it stops.

I loved the Infocom games! I noticed the Zork reference in the Quest instructions. lol


I didn't change the way it worked this time. I just added (and changed) log entries for debugging.

Here's the combat function's script:

// KV moved this next before the ShowMenu, so it will exist during the script
if (not HasAttribute(game,"myTempShowMenuScript")) {
  game.myCombatShowMenuScript => {
    game.temp_mname.stamina = game.temporary_mname_stamina
    game.temporary_mname_stamina = null
  }
}
// added this next line for debbuging
// BE SURE TO REMOVE IT!!
Log ("Running combat function.")
// END OF KV MOVING THINGS
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)
game.temporary_mname_stamina = mname.stamina
game.temp_mname = mname
if (proll > mroll) {
  Log ("proll is greater than mroll")
  msg ("You damaged your opponent for 2 Stamina!")
  game.temporary_mname_stamina = game.temporary_mname_stamina - 2
  if (mname.stamina>0) {
    Log ("mname.stamina is greater than 0. Running ShowMenu for more damage")
    entry = "mname.stamina = "+mname.stamina
    Log (entry)
    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.myCombatShowMenuScript)
    }
  }
}
else {
  Log ("proll is than than mroll")
  msg ("You were damaged for 2 Stamina!")
  player.staminacurrent = player.staminacurrent - 2
  entry = "mname.stamina = "+mname.stamina
  Log (entry)
  Log ("mname.stamina is less than 0. Running ShowMenu for reducing player.staminacurrent")
  entry = "player.staminacurrent = "+player.staminacurrent
  Log (entry)
  // NOTE:  The following ShowMenu throws an error if called because it has no script!
  ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false)
}
// The next 6 lines are for debugging
// BE SURE TO REMOVE THEM!!!
stamina = "mname stamina ="
if (mname.stamina<0) {
  stamina = "-"
}
stamina = stamina + mname.stamina
Log (stamina)
Log ("end of combat function")

1/30/2018 9:25:25 AM Running combat function.
1/30/2018 9:25:25 AM proll is greater than mroll
1/30/2018 9:25:25 AM mname.stamina is greater than 0. Running ShowMenu for more damage
1/30/2018 9:25:25 AM mname.stamina = 5
1/30/2018 9:25:25 AM mname stamina =5
1/30/2018 9:25:25 AM end of combat function
1/30/2018 9:25:27 AM FirstDEATHHAWK.stamina = 3
1/30/2018 9:25:27 AM Running combat function.
1/30/2018 9:25:27 AM proll is greater than mroll
1/30/2018 9:25:27 AM mname.stamina is greater than 0. Running ShowMenu for more damage
1/30/2018 9:25:27 AM mname.stamina = 3
1/30/2018 9:25:27 AM mname stamina =3
1/30/2018 9:25:27 AM end of combat function
1/30/2018 9:25:29 AM FirstDEATHHAWK.stamina = 1
1/30/2018 9:25:29 AM Running combat function.
1/30/2018 9:25:29 AM proll is greater than mroll
1/30/2018 9:25:29 AM mname.stamina is greater than 0. Running ShowMenu for more damage
1/30/2018 9:25:29 AM mname.stamina = 1
1/30/2018 9:25:29 AM mname stamina =1
1/30/2018 9:25:29 AM end of combat function
1/30/2018 9:25:41 AM FirstDEATHHAWK.stamina = -3

(The last line is just after saying YES to the ShowMenu asking to try my luck for more damage.)


NOTE:

You get an error about ShowMenu sometimes because this ShowMenu function has no script:

else {
  Log ("proll is than than mroll")
  msg ("You were damaged for 2 Stamina!")
  player.staminacurrent = player.staminacurrent - 2
  entry = "mname.stamina = "+mname.stamina
  Log (entry)
  Log ("mname.stamina is less than 0. Running ShowMenu for reducing player.staminacurrent")
  entry = "player.staminacurrent = "+player.staminacurrent
  Log (entry)
  ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false)
}

Yeah. I never got to that showmenu yet because I was trying to get everything to work. Basically it works like the other Luck test. If it passes then the damage the player suffers is reduced by 1.


It's still not working properly. If you run it the combat is not stopping properly. The enemy starts off at 5 stamina. If the rolls work in your favor (which they do most of the time). You hit for 2 stamina, test luck to reduce it another 2. That's fine. The combat happens again. You hit it for 2 damage, the enemy should be at -1, there is no need for a second Luck test to happen because the enemy is dead. But the debugger is showing the enemy at 1 stamina still at this point. It's like its not updating the enemy stamina before asking the Luck roll question.


I didn't use the correct variables inside of the ShowMenu() script. (Whoops!)

Try this (too many changes to list):

combat (REVISED SINCE POSTING!)

// added this next line for debbuging
// BE SURE TO REMOVE IT!!
Log ("Running combat function.")
// END OF KV MOVING THINGS
msg ("<table style=\"width: 75%\"><tr><th>Combatant</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)
game.temp_mname = mname
entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
Log (entry)
if (proll > mroll) {
  Log ("proll is greater than mroll")
  msg ("You damaged your opponent for 2 Stamina!")
  Log ("You damaged your opponent for 2 Stamina!")
  game.temp_mname.stamina = game.temp_mname.stamina - 2
  entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
  Log (entry)
  if (game.temp_mname.stamina>0) {
    Log ("game.temp_mname.stamina is greater than 0. Running ShowMenu for more damage")
    entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
    Log (entry)
    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) {
            Log ("Dealt 2 more stamina damage")
            msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
            msg ("<table style=\"width: 75%\"><tr><th>Combatant</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\">" + game.temp_mname.alias + "</b></font></td> <td align=\"center\">" + game.temp_mname.skill + "</td> <td align=\"center\">" + game.temp_mname.stamina + "</td></tr> </table>")
            game.temp_mname.stamina = game.temp_mname.stamina - 2
            entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
            Log (entry)
            player.luckcurrent = player.luckcurrent - 1
          }
          else {
            Log ("Did not roll successfully.  No addition to stamina damage.")
            msg ("You luck roll was unsuccessful!")
            player.luckcurrent = player.luckcurrent - 1
          }
        }
      }
    }
  }
  Log ("ShowMenu ends.")
}
else {
  Log ("proll is than than mroll")
  msg ("You were damaged for 2 Stamina!")
  player.staminacurrent = player.staminacurrent - 2
  entry = "mname.stamina = "+mname.stamina
  Log (entry)
  entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
  Log (entry)
  Log ("mname.stamina is less than 0. Running ShowMenu for reducing player.staminacurrent")
  entry = "player.staminacurrent = "+player.staminacurrent
  Log (entry)
  ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
    msg ("FIX ME!!!  THIS IS NOT SETUP!")
  }
}
// The next 6 lines are for debugging
// BE SURE TO REMOVE THEM!!!
stamina = "mname stamina = "+ mname.stamina
Log (stamina)
entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
Log (entry)
Log ("end of combat function")

Ok. Looking great. Thanks for all the help. I have added the coding for testing Luck if you are damaged and added a room called "Game Over" where I'll do some stuff and end the game if the player dies. Here is the problem. I tested it with the enemy having a high Skill and played until the player died. It went to the Game Over room where I clear the screen and finish the game. The problem is that the showmenu for testing your luck still appears on the screen and doesn't look right.


<!--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">
      // KV moved FirstDEATHHAWK to this room to make testing easy, and \
      // replaced your while script with the next line:
      // FightRounds (FirstDEATHHAWK, 3)
      //
      // You could also put this line:
      FightUntilDead (FirstDEATHHAWK)
      //
      // OR, TO JUST ATTACK ONCE:
      // combat(FirstDEATHHAWK)
    </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 name="FirstDEATHHAWK">
      <inherit name="editor_object" />
      <stamina type="int">5</stamina>
      <skill type="int">24</skill>
      <alias>First DEATH HAWK</alias>
      <changedstamina type="script">
        // Added by KV for debugging
        Log ("FirstDEATHHAWK.stamina = "+ ToString(FirstDEATHHAWK.stamina))
      </changedstamina>
    </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>
  <turnscript name="fight_until_dead_turnscript">
    <enabled />
    <script><![CDATA[
      if (HasAttribute(game.pov,"incombat")) {
        if (game.pov.incombat) {
          if (HasAttribute(game.pov,"opponent")) {
            if (game.pov.parent = game.pov.opponent.parent) {
              if (game.pov.opponent.stamina > 0) {
                combat (game.pov.opponent)
              }
            }
          }
        }
      }
    ]]></script>
  </turnscript>
  <object name="Game Over">
    <inherit name="editor_room" />
    <description>Though you have fought valiantly, you, unfortunately, did not survive!</description>
    <enter type="script">
      ClearScreen
      finish
    </enter>
  </object>
  <function name="combat" parameters="mname" type="string"><![CDATA[
    // added this next line for debbuging
    // BE SURE TO REMOVE IT!!
    Log ("Running combat function.")
    // END OF KV MOVING THINGS
    msg ("<table style=\"width: 75%\"><tr><th>Combatant</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)
    game.temp_mname = mname
    entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
    Log (entry)
    if (proll > mroll) {
      Log ("proll is greater than mroll")
      msg ("You damaged your opponent for 2 Stamina!")
      Log ("You damaged your opponent for 2 Stamina!")
      game.temp_mname.stamina = game.temp_mname.stamina - 2
      entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
      Log (entry)
      if (game.temp_mname.stamina>0) {
        Log ("game.temp_mname.stamina is greater than 0. Running ShowMenu for more damage")
        entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
        Log (entry)
        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) {
                Log ("Dealt 2 more stamina damage")
                msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
                msg ("<table style=\"width: 75%\"><tr><th>Combatant</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\">" + game.temp_mname.alias + "</b></font></td> <td align=\"center\">" + game.temp_mname.skill + "</td> <td align=\"center\">" + game.temp_mname.stamina + "</td></tr> </table>")
                game.temp_mname.stamina = game.temp_mname.stamina - 2
                entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
                Log (entry)
                player.luckcurrent = player.luckcurrent - 1
              }
              else {
                Log ("Did not roll successfully.  No addition to stamina damage.")
                msg ("You luck roll was unsuccessful!")
                player.luckcurrent = player.luckcurrent - 1
              }
            }
          }
        }
      }
      Log ("ShowMenu ends.")
    }
    else {
      Log ("proll is than than mroll")
      msg ("You were damaged for 2 Stamina!")
      player.staminacurrent = player.staminacurrent - 2
      entry = "mname.stamina = "+mname.stamina
      Log (entry)
      entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
      Log (entry)
      Log ("mname.stamina is less than 0. Running ShowMenu for reducing player.staminacurrent")
      entry = "player.staminacurrent = "+player.staminacurrent
      Log (entry)
      ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
        switch (result) {
          case ("Yes") {
            lroll = DiceRoll ("2d6")
            if (lroll < player.luckcurrent) {
              Log ("Dealt 2 less stamina damage")
              msg ("Your luck roll was successful! You are dealt 2 less Stamina damage!")
              msg ("<table style=\"width: 75%\"><tr><th>Combatant</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\">" + game.temp_mname.alias + "</b></font></td> <td align=\"center\">" + game.temp_mname.skill + "</td> <td align=\"center\">" + game.temp_mname.stamina + "</td></tr> </table>")
              player.staminacurrent = player.staminacurrent + 2
              entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
              Log (entry)
              player.luckcurrent = player.luckcurrent - 1
            }
            else {
              Log ("Did not roll successfully.  No reduction to stamina damage.")
              msg ("You luck roll was unsuccessful!")
              player.luckcurrent = player.luckcurrent - 1
            }
          }
        }
      }
    }
    // The next 6 lines are for debugging
    // BE SURE TO REMOVE THEM!!!
    stamina = "mname stamina = "+ mname.stamina
    Log (stamina)
    entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
    Log (entry)
    Log ("end of combat function")
  ]]></function>
  <function name="FightRounds" parameters="object, rounds">
    if (not TypeOf(rounds) = "int") {
      if (not IsInt(rounds)) {
        error ("FightRounds:  rounds parameter must be an integer")
      }
      else {
        rounds = ToInt(rounds)
      }
    }
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
    SetTurnTimeout (rounds+1) {
      game.pov.opponent = null
      game.pov.incombat = false
    }
  </function>
  <function name="FightUntilDead" parameters="object">
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
  </function>
</asl>

Does it need to look something like this?

(CLICK TO WATCH THE VIDEO)

image


Not really sure what you are asking. Are you asking should the combatants be at the top of the screen? If so, that doesn't really matter. The combat seems to be working well. I just need to get player death looking right. Like I said, when the player dies and moves to Game Over room, I clear the screen and Finish the Game, but the Luck Roll question is still showing up. It just looks wrong.


> Not really sure what you are asking.

I don't think you're alone on that one.

(Just kidding. I know what you're asking now. I missed one of your posts.)


> Are you asking should the combatants be at the top of the screen?

Negative.

That just shows you the combatant's stamina changing. I put it up there so we could watch what was happening as it happened.


> If so, that doesn't really matter.

Oh, okay...

I made it work with the panes instead of that table, too, just in case it ends up mattering at a later date.

video link


> The combat seems to be working well.

Ha!

This is in between two big walls of text (one post was from each of us, but I've used a <details> element to tidy up things up things on my end now):

http://textadventures.co.uk/forum/quest/topic/occl0bwg2kklezad05hkeg/help-with-coding#ecf5d5a0-02ae-4dba-ba70-59dcabde9de8

I didn't even see it!

I shall investigate that problem.

I CAN POST THIS HERE!!!


ya, quest's 'order of operations' with it's Scripting can be annoying:


script 1
-> script 2A
script 2B

this is just showing that 'script 2A' and script '2B' can be happening at the same time


boolean_variable = true
script 1
-> show menu ("yes/no?", LIST, false) {
->-> boolean_variable = false
-> }
if (boolean_variable) {
-> msg ("I don't want this to show up, BUT IT DOES, argh!!")
}

and this is possible too


unfortunately, quest requires you to be creative with its scripting lots of times... due to not being able to stop/halt/break scripting from executing/activating/running...

the 'on ready' only works in some situations and 'wait' isn't always ideal or desired... and 'while' doesn't work with user input (typed-in nor with selected from: popup menu or hyperlink text)


Make a new game and replace it's full code with this:

<!--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.1</version>
    <firstpublished>2018</firstpublished>
    <author>Ian Livingstone</author>
    <category>Fantasy</category>
    <feature_advancedscripts />
    <customstatuspane />
    <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>
    <inituserinterface type="script"><![CDATA[
      JS.setCustomStatus ("### <br/>Stamina: !")
      JS.uiHide ("#customStatusPane")
    ]]></inituserinterface>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script">
      msg (" " + FirstDEATHHAWK.skill + " - " + FirstDEATHHAWK.stamina)
      // KV moved FirstDEATHHAWK to this room to make testing easy, and \
      // replaced your while script with the next line:
      // FightRounds (FirstDEATHHAWK, 3)
      //
      // You could also put this line:
      FightUntilDead (FirstDEATHHAWK)
      //
      // OR, TO JUST ATTACK ONCE:
      // combat(FirstDEATHHAWK)
      //
      // End of KV's changes
      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 name="FirstDEATHHAWK">
      <inherit name="editor_object" />
      <stamina type="int">5</stamina>
      <skill type="int">4</skill>
      <alias>First DEATH HAWK</alias>
      <usedefaultprefix type="boolean">false</usedefaultprefix>
      <changedstamina type="script">
        // Added by KV for debugging
        Log ("CHANGEDSTAMINA SCRIPT:   FirstDEATHHAWK.stamina = "+ ToString(FirstDEATHHAWK.stamina))
      </changedstamina>
    </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>
  <turnscript name="fight_until_dead_turnscript">
    <enabled />
    <script><![CDATA[
      if (HasAttribute(game.pov,"incombat")) {
        if (game.pov.incombat) {
          if (HasAttribute(game.pov,"opponent")) {
            if (game.pov.parent = game.pov.opponent.parent) {
              if (game.pov.opponent.stamina > 0) {
                combat (game.pov.opponent)
                JS.uiShow ("#customStatusPane")
                UpdateMnameStatPane
                // This is just to exit the function without a bunch of else statements.
                return (true)
              }
            }
          }
        }
      }
      JS.uiHide ("#customStatusPane")
    ]]></script>
  </turnscript>
  <function name="combat" parameters="mname" type="string"><![CDATA[
    if (mname.stamina>0) {
      game.temp_mname = mname
      JS.uiShow ("#customStatusPane")
      UpdateMnameStatPane
      // added this next line for debbuging
      // BE SURE TO REMOVE IT!!
      Log ("Running combat function.")
      // END OF KV MOVING THINGS
      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)
      entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
      Log (entry)
      if (proll > mroll) {
        Log ("proll is greater than mroll")
        msg ("You damaged your opponent for 2 Stamina!")
        UpdateMnameStatPane
        Log ("You damaged your opponent for 2 Stamina!")
        game.temp_mname.stamina = game.temp_mname.stamina - 2
        entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
        UpdateMnameStatPane
        Log (entry)
        if (game.temp_mname.stamina>0) {
          Log ("game.temp_mname.stamina is greater than 0. Running ShowMenu for more damage")
          entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
          Log (entry)
          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) {
                  Log ("Dealt 2 more stamina damage")
                  msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
                  game.temp_mname.stamina = game.temp_mname.stamina - 2
                  UpdateMnameStatPane
                  entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
                  Log (entry)
                  player.luckcurrent = player.luckcurrent - 1
                }
                else {
                  Log ("Did not roll successfully.  No addition to stamina damage.")
                  msg ("You luck roll was unsuccessful!")
                  player.luckcurrent = player.luckcurrent - 1
                }
              }
            }
          }
        }
        Log ("ShowMenu ends.")
      }
      else {
        Log ("proll is than than mroll")
        msg ("You were damaged for 2 Stamina!")
        ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
          if (LCase(result) = "yes") {
            msg ("FIX ME!!!  THIS IS NOT SETUP!  I'm just adding 4 to stamina.")
          }
          else {
            msg ("Okay.  Skipping that bit, then!")
          }
        }
        player.staminacurrent = player.staminacurrent - 2
        entry = "mname.stamina = "+mname.stamina
        Log (entry)
        entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
        Log (entry)
        Log ("mname.stamina is less than 0. AND: Running ShowMenu for reducing player.staminacurrent")
        entry = "player.staminacurrent = "+player.staminacurrent
        Log (entry)
      }
      UpdateMnameStatPane
      // The next 6 lines are for debugging
      // BE SURE TO REMOVE THEM!!!
      stamina = "mname stamina = "+ mname.stamina
      Log (stamina)
      entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
      Log (entry)
    }
    else {
      msg (CapFirst(mname.article) + " is already defeated!")
    }
    if (mname.stamina<1) {
      msg (CapFirst(GetDisplayName(mname)) + " has been defeated!")
      RemoveObject (mname)
      JS.eval ("setTimeout(function(){uiHide('#customStatusPane');},500);")
    }
    Log ("end of combat function")
  ]]></function>
  <function name="FightRounds" parameters="object, rounds">
    if (not TypeOf(rounds) = "int") {
      if (not IsInt(rounds)) {
        error ("FightRounds:  rounds parameter must be an integer")
      }
      else {
        rounds = ToInt(rounds)
      }
    }
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
    SetTurnTimeout (rounds+1) {
      game.pov.opponent = null
      game.pov.incombat = false
    }
  </function>
  <function name="FightUntilDead" parameters="object">
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
  </function>
  <function name="UpdateMnameStatPane"><![CDATA[
    JS.eval ("$('#customStatusPane').html('### <br/>Stamina: !');$('#customStatusPane').html($('#customStatusPane').html().replace(/###/,'"+CapFirst(GetDisplayName(game.temp_mname))+"').replace(/!/,'"+game.temp_mname.stamina+"'));")
  ]]></function>
</asl>

(You have added things since I've been changing this, and I don't want you to lose anything.)


Yep, HK.

I had to move a ShowMenu around in a lengthy script.

It gives you a chance to save yourself before you die, but the attribute changed before calling the menu. So, you died, then the menu popped up: "WOULD YOU LIKE A CHANCE TO LIVE?!?!?!?"

(Clicking anything was fruitless, of course. It was just post-death torture!)


Ok. So that is all working good. I have another problem. How do I test that the player actually has luck to test their luck? Once it gets to zero they shouldn't have the option to test luck anymore.


If the attribute is called luck:

if(player.luck>0){
  //Do the thing to test luck.
}
else{
  //Do something else (if you want to; you don't have to have an else).
}

Yeah, got that. But where do I put it into my code?


This is the part you don't want to run unless player.luckcurrent is greater than 0:

        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) {
                Log ("Dealt 2 more stamina damage")
                msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
                game.temp_mname.stamina = game.temp_mname.stamina - 2
                UpdateMnameStatPane
                entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
                Log (entry)
                player.luckcurrent = player.luckcurrent - 1
              }
              else {
                Log ("Did not roll successfully.  No addition to stamina damage.")
                msg ("You luck roll was unsuccessful!")
                player.luckcurrent = player.luckcurrent - 1
              }
            }
          }
        }

That is the script which uses luck to change stuff.

You need to nest that inside an if{} statement:

if (player.luckcurrent > 0 ){
  // Run the script to use luck to change stuff.
}

In this instance that would look like this:

      if (player.luckcurrent>0) {
        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) {
                Log ("Dealt 2 more stamina damage")
                msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
                game.temp_mname.stamina = game.temp_mname.stamina - 2
                UpdateMnameStatPane
                entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
                Log (entry)
                player.luckcurrent = player.luckcurrent - 1
              }
              else {
                Log ("Did not roll successfully.  No addition to stamina damage.")
                msg ("You luck roll was unsuccessful!")
                player.luckcurrent = player.luckcurrent - 1
              }
            }
          }
        }
      }

Making the entire combat script (the most recent version I know of) this:

if (mname.stamina>0) {
  game.temp_mname = mname
  JS.uiShow ("#customStatusPane")
  UpdateMnameStatPane
  // added this next line for debbuging
  // BE SURE TO REMOVE IT!!
  Log ("Running combat function.")
  // END OF KV MOVING THINGS
  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)
  entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
  Log (entry)
  if (proll > mroll) {
    Log ("proll is greater than mroll")
    msg ("You damaged your opponent for 2 Stamina!")
    UpdateMnameStatPane
    Log ("You damaged your opponent for 2 Stamina!")
    game.temp_mname.stamina = game.temp_mname.stamina - 2
    entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
    UpdateMnameStatPane
    Log (entry)
    if (game.temp_mname.stamina>0) {
      Log ("game.temp_mname.stamina is greater than 0. Running ShowMenu for more damage")
      entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
      Log (entry)
      if (player.luckcurrent>0) {
        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) {
                Log ("Dealt 2 more stamina damage")
                msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
                game.temp_mname.stamina = game.temp_mname.stamina - 2
                UpdateMnameStatPane
                entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
                Log (entry)
                player.luckcurrent = player.luckcurrent - 1
              }
              else {
                Log ("Did not roll successfully.  No addition to stamina damage.")
                msg ("You luck roll was unsuccessful!")
                player.luckcurrent = player.luckcurrent - 1
              }
            }
          }
        }
      }
    }
  }
  else {
    Log ("proll is than than mroll")
    msg ("You were damaged for 2 Stamina!")
    ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
      if (LCase(result) = "yes") {
        msg ("FIX ME!!!  THIS IS NOT SETUP!  I'm just adding 4 to stamina.")
      }
      else {
        msg ("Okay.  Skipping that bit, then!")
      }
    }
    player.staminacurrent = player.staminacurrent - 2
    entry = "mname.stamina = "+mname.stamina
    Log (entry)
    entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
    Log (entry)
    Log ("mname.stamina is less than 0. AND: Running ShowMenu for reducing player.staminacurrent")
    entry = "player.staminacurrent = "+player.staminacurrent
    Log (entry)
  }
  UpdateMnameStatPane
  // The next 4 lines are for debugging  BE SURE TO REMOVE THEM!!! (In fact, remove all lines using Log().)
  stamina = "mname stamina = "+ mname.stamina
  Log (stamina)
  entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
  Log (entry)
}
else {
  msg (CapFirst(mname.article) + " is already defeated!")
}
if (mname.stamina<1) {
  msg (CapFirst(GetDisplayName(mname)) + " has been defeated!")
  RemoveObject (mname)
  JS.eval ("setTimeout(function(){uiHide('#customStatusPane');},500);")
}
Log ("end of combat function")

Ok. So new problem. When I add that and the player's luck is zero, after the enemy attacks and does damage it goes to a prompt. If I type a command, like "look" the next round of combat happens. But, I don't want the combat to stop until it's over. So how do I fi that?


How about this?

<!--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.1</version>
    <firstpublished>2018</firstpublished>
    <author>Ian Livingstone</author>
    <category>Fantasy</category>
    <feature_advancedscripts />
    <customstatuspane />
    <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>
    <inituserinterface type="script"><![CDATA[
      JS.setCustomStatus ("### <br/>Stamina: !")
      JS.uiHide ("#customStatusPane")
    ]]></inituserinterface>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script">
      msg (" " + FirstDEATHHAWK.skill + " - " + FirstDEATHHAWK.stamina)
      // KV moved FirstDEATHHAWK to this room to make testing easy, and \
      // replaced your while script with the next line:
      // FightRounds (FirstDEATHHAWK, 3)
      //
      // You could also put this line:
      FightUntilDead (FirstDEATHHAWK)
      //
      // OR, TO JUST ATTACK ONCE:
      // combat(FirstDEATHHAWK)
      //
      // End of KV's changes
      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 name="FirstDEATHHAWK">
      <inherit name="editor_object" />
      <stamina type="int">5</stamina>
      <skill type="int">4</skill>
      <alias>First DEATH HAWK</alias>
      <usedefaultprefix type="boolean">false</usedefaultprefix>
      <changedstamina type="script">
        // Added by KV for debugging
        Log ("CHANGEDSTAMINA SCRIPT:   FirstDEATHHAWK.stamina = "+ ToString(FirstDEATHHAWK.stamina))
      </changedstamina>
    </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>
  <turnscript name="fight_until_dead_turnscript">
    <enabled />
    <script><![CDATA[
      if (HasAttribute(game.pov,"incombat")) {
        if (game.pov.incombat) {
          Log ("incombat")
          if (HasAttribute(game.pov,"opponent")) {
            if (game.pov.parent = game.pov.opponent.parent) {
              if (game.pov.opponent.stamina > 0) {
                combat (game.pov.opponent)
                JS.uiShow ("#customStatusPane")
                UpdateMnameStatPane
                // This is just to exit the function without a bunch of else statements.
                return (true)
              }
            }
          }
        }
      }
      JS.uiHide ("#customStatusPane")
    ]]></script>
  </turnscript>
  <function name="combat" parameters="mname" type="string"><![CDATA[
    if (mname.stamina>0) {
      game.temp_mname = mname
      JS.uiShow ("#customStatusPane")
      UpdateMnameStatPane
      Log ("Running combat function.")
      msg ("<table style=\"width: 75%\"><tr><th>Combatant</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)
      entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
      Log (entry)
      if (proll > mroll) {
        Log ("proll is greater than mroll")
        msg ("You damaged your opponent for 2 Stamina!")
        UpdateMnameStatPane
        Log ("You damaged your opponent for 2 Stamina!")
        game.temp_mname.stamina = game.temp_mname.stamina - 2
        entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
        UpdateMnameStatPane
        Log (entry)
        if (game.temp_mname.stamina>0) {
          Log ("game.temp_mname.stamina is greater than 0. Running ShowMenu for more damage")
          entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
          Log (entry)
          if (player.luckcurrent>0) {
            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) {
                    Log ("Dealt 2 more stamina damage")
                    msg ("Your luck roll was successful! You dealt 2 more Stamina damage!")
                    game.temp_mname.stamina = game.temp_mname.stamina - 2
                    UpdateMnameStatPane
                    entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
                    Log (entry)
                    player.luckcurrent = player.luckcurrent - 1
                  }
                  else {
                    Log ("Did not roll successfully.  No addition to stamina damage.")
                    msg ("You luck roll was unsuccessful!")
                    player.luckcurrent = player.luckcurrent - 1
                  }
                }
              }
            }
          }
        }
      }
      else {
        Log ("proll is than than mroll")
        msg ("You were damaged for 2 Stamina!")
        if (player.luckcurrent>0) {
          ShowMenu ("Do you want to test your Luck to reduce the damage?", Split ("Yes; No", ";"), false) {
            if (LCase(result) = "yes") {
              msg ("FIX ME!!!  THIS IS NOT SETUP!  I'm just adding 4 to stamina.")
            }
            else {
              msg ("Okay.  Skipping that bit, then!")
            }
          }
        }
        player.staminacurrent = player.staminacurrent - 2
        entry = "mname.stamina = "+mname.stamina
        Log (entry)
        entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
        Log (entry)
        Log ("mname.stamina is less than 0. AND: Running ShowMenu for reducing player.staminacurrent")
        entry = "player.staminacurrent = "+player.staminacurrent
        Log (entry)
      }
      UpdateMnameStatPane
      stamina = "mname stamina = "+ mname.stamina
      Log (stamina)
      entry = "game.temp_mname.stamina = "+game.temp_mname.stamina
      Log (entry)
    }
    else {
      msg (CapFirst(mname.article) + " is already defeated!")
    }
    if (mname.stamina<1) {
      msg (CapFirst(GetDisplayName(mname)) + " has been defeated!")
      RemoveObject (mname)
      JS.eval ("setTimeout(function(){uiHide('#customStatusPane');},500);")
    }
    Log ("end of combat function")
  ]]></function>
  <function name="FightRounds" parameters="object, rounds">
    if (not TypeOf(rounds) = "int") {
      if (not IsInt(rounds)) {
        error ("FightRounds:  rounds parameter must be an integer")
      }
      else {
        rounds = ToInt(rounds)
      }
    }
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
    SetTurnTimeout (rounds+1) {
      game.pov.opponent = null
      game.pov.incombat = false
    }
  </function>
  <function name="FightUntilDead" parameters="object">
    game.pov.opponent = object
    game.pov.incombat = true
    combat (game.pov.opponent)
  </function>
  <function name="UpdateMnameStatPane"><![CDATA[
    JS.eval ("$('#customStatusPane').html('### <br/>Stamina: !');$('#customStatusPane').html($('#customStatusPane').html().replace(/###/,'"+CapFirst(GetDisplayName(game.temp_mname))+"').replace(/!/,'"+game.temp_mname.stamina+"'));")
  ]]></function>
</asl>

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

Support

Forums