ShowMenu script collage😁

I have a short equipping system and have reached a snag in the show menu script. I am attempting to give the player a choice of which hand a torch will go if both hands are holding something. I don't know what the result is to put in a condition for the result because of the way I patched the code together. No errors, just a blank response.

Not sure if I am using "StartsWith" correctly.
I used player.equipped = StringListSort (player.equipped) because I can then know the order of the list and pull them by position, knowing shield was before sword or short sword because they were in alphabetical order but could not get a working response using if (result = StringListItem (player.equipped, 0).
I have tried to get the value of result using msg(result) but where ever I put it in the script it will not print.

Can anyone see what I need to do?

This is the "light" verb for the torch.

if (Got(object)) {
  if (player.left_hand <> null and player.right_hand <> null and player.both_hands = null) {
    player.equipped = StringListSort (player.equipped)
    options = player.equipped
    game.temp = object
    ShowMenu ("Which will you unequip?", options, true) {
      object = game.temp
      get input {
        if (result = StartsWith("Shield")) {
          ClearTurn
          msg ("You shoulder your shield and use your flint and steel to light your torch, holding it out in front of you.")
          player.left_hand.listalias = player.left_hand.originalalias
          player.left_hand.equipped = False
          player.left_hand = this
        }
        else if (result = StartsWith(result, "Sword")) {
          ClearTurn
          ShowRoomDescription
          msg ("You sheath your weapon and use your flint and steel to light your torch, holding it out in front of you.")
          player.onehanded.listalias = player.onehanded.originalalias
          player.onehanded.equipped = False
          player.onehanded = this
        }
      }
      on ready {
        list add (object.inventoryverbs, "Snuff")
        list remove (object.inventoryverbs, "Light")
        object.listalias = object.listalias + " (lit)"
        object.burned = True
        object.lightsource = True
        EnableTurnScript (torchturnscript)
      }
    }
  }
}
Click for whole system code.
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <dynamictemplate name="DefaultSpeakTo">You get no response.</dynamictemplate>
  <game name="Equipping System 5-13-20">
    <gameid>ac896f77-268d-4e18-912b-bf01791b129e</gameid>
    <version>1.0</version>
    <firstpublished>2020</firstpublished>
    <feature_lightdark />
    <feature_limitinventory />
    <feature_annotations />
    <feature_advancedwearables />
    <feature_advancedscripts />
    <feature_devmode />
    <allowlookdirections />
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <isroom />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <attr name="empty_hands">fists</attr>
      <attr name="both_hand_item">fists</attr>
      <attr name="left_hand_item">fist</attr>
      <attr name="right_hand_item">fist</attr>
      <equipped type="stringlist" />
      <object name="short_sword">
        <inherit name="editor_object" />
        <one_handed_weapon />
        <equipped type="boolean">false</equipped>
        <attr name="can_equip_left" type="boolean">false</attr>
        <attr name="two_handed_weapon" type="boolean">false</attr>
        <one_handed_item />
        <attr name="one_handed_defense" type="boolean">false</attr>
        <attr name="two_handed_item" type="boolean">false</attr>
        <attr name="two_handed_defense" type="boolean">false</attr>
        <displayverbs type="stringlist">
          <value>Look at</value>
          <value>Take</value>
        </displayverbs>
        <inventoryverbs type="stringlist">
          <value>Look at</value>
          <value>Drop</value>
          <value>Equip</value>
        </inventoryverbs>
        <attr name="is_weapon" type="string"></attr>
        <alias>short sword</alias>
        <originalalias type="string"></originalalias>
        <listalias>Short Sword</listalias>
        <category type="script">
          ClearTurn
          EquipOneHandedWeapon (this)
        </category>
      </object>
      <object name="long_sword">
        <inherit name="editor_object" />
        <two_handed_weapon />
        <equipped type="boolean">false</equipped>
        <attr name="one_handed_weapon" type="boolean">false</attr>
        <attr name="one_handed_item" type="boolean">false</attr>
        <attr name="one_handed_defense" type="boolean">false</attr>
        <attr name="two_handed_defense" type="boolean">false</attr>
        <two_handed_item />
        <alias>long sword</alias>
        <listalias>Long Sword</listalias>
        <originalalias>Long Sword</originalalias>
        <inventoryverbs type="stringlist">
          <value>Look at</value>
          <value>Drop</value>
          <value>Equip</value>
        </inventoryverbs>
        <attr name="is_weapon" type="string"></attr>
        <category type="script">
          ClearTurn
          EquipTwoHandedWeapon (this)
        </category>
      </object>
      <object name="torch">
        <inherit name="editor_object" />
        <one_handed_item />
        <one_handed_weapon />
        <equipped type="boolean">false</equipped>
        <attr name="one_handed_defense" type="boolean">false</attr>
        <attr name="two_handed_item" type="boolean">false</attr>
        <attr name="two_handed_defense" type="boolean">false</attr>
        <attr name="two_handed_weapon" type="boolean">false</attr>
        <attr name="is_torch" type="string"></attr>
        <alias>torch</alias>
        <listalias>Torch</listalias>
        <originalalias>Torch</originalalias>
        <inventoryverbs type="stringlist">
          <value>Look at</value>
          <value>Drop</value>
          <value>Light</value>
        </inventoryverbs>
        <attr name="feature_switchable" type="boolean">false</attr>
        <feature_lightdark />
        <lightsource type="boolean">false</lightsource>
        <lightstrength>strong</lightstrength>
        <volume type="int">1</volume>
        <life type="int">50</life>
        <price type="int">1</price>
        <category type="script">
          ClearTurn
          LightAndUseTorch (this)
        </category>
      </object>
      <object name="shield">
        <inherit name="editor_object" />
        <one_handed_weapon />
        <equipped type="boolean">false</equipped>
        <attr name="two_handed_weapon" type="boolean">false</attr>
        <one_handed_defense />
        <one_handed_item />
        <attr name="two_handed_item" type="boolean">false</attr>
        <attr name="two_handed_defense" type="boolean">false</attr>
        <inventoryverbs type="stringlist">
          <value>Look at</value>
          <value>Drop</value>
          <value>Equip</value>
        </inventoryverbs>
        <attr name="is_shield" type="string"></attr>
        <listalias>Shield</listalias>
        <originalalias>Shield</originalalias>
        <category type="script">
          ClearTurn
          EquipOneHandedShield (this)
        </category>
        <lightsource type="boolean">false</lightsource>
      </object>
    </object>
  </object>
  <command name="equip">
    <pattern>equip #object#</pattern>
    <script><![CDATA[
      ClearTurn
      if (not (HasAttribute(object, "equipped"))) {
        msg ("That is not something you can equip.")
      }
      else if (object.equipped = True) {
        msg ("That is already equipped.")
      }
      else if (HasAttribute(object, "is_weapon")) {
        object.listalias = object.listalias + "<small> (equipped)</small>"
        object.equipped = True
        do (object, "category")
      }
      else if (HasAttribute(object, "is_torch")) {
        object.listalias = object.listalias + "<small> (lit)</small>"
        object.equipped = True
        do (object, "category")
      }
      else if (HasAttribute(object, "is_shield")) {
        object.listalias = object.listalias + "<small> (equipped)</small>"
        object.equipped = True
        do (object, "category")
      }
    ]]></script>
  </command>
  <command name="light">
    <pattern>light #object#; burn #object#</pattern>
    <unresolved type="string"></unresolved>
    <script><![CDATA[
      if (object.lightsource = True) {
        msg ("It is already lit.")
      }
      if (Got(object)) {
        if (player.left_hand <> null and player.right_hand <> null and player.both_hands = null) {
          player.equipped = StringListSort (player.equipped)
          options = player.equipped
          game.temp = object
          ShowMenu ("Which will you unequip?", options, true) {
            object = game.temp
            get input {
              msg (result)
              if (result = StartsWith("Shield")) {
                ClearTurn
                msg ("You shoulder your shield and use your flint and steel to light your torch, holding it out in front of you.")
                player.left_hand.listalias = player.left_hand.originalalias
                player.left_hand.equipped = False
                player.left_hand = this
              }
              else if (result = StartsWith(result, "Sword")) {
                ClearTurn
                ShowRoomDescription
                msg ("You sheath your weapon and use your flint and steel to light your torch, holding it out in front of you.")
                player.onehanded.listalias = player.onehanded.originalalias
                player.onehanded.equipped = False
                player.onehanded = this
              }
              else {
                msg (result)
              }
            }
            on ready {
              msg (result)
              list add (object.inventoryverbs, "Snuff")
              list remove (object.inventoryverbs, "Light")
              object.listalias = object.listalias + " (lit)"
              object.burned = True
              object.lightsource = True
              EnableTurnScript (torchturnscript)
            }
          }
        }
      }
    ]]></script>
  </command>
  <turnscript name="torchturnscript">
    <script>
      torch.life = torch.life - 1
      if (torch.life = 10) {
        torch.listalias = torch.alias + " (dimming)"
        if (torch.parent = player.parent) {
          msg ("{color:Red:Your torch is getting dimmer!}")
        }
      }
      if (torch.life = 5) {
        torch.listalias = torch.alias + " (dim)"
        if (torch.parent = player.parent or torch.parent = player) {
          msg ("{color:Red:The torch is about to burn out and the room is growing darker.}")
        }
      }
      if (torch.life = 0) {
        torch.listalias = torch.alias + " (burned out)"
        torch.lightsource = false
        torch.price = 0
        list remove (torch.inventoryverbs, "snuff")
        torch.lightsource = false
        DisableTurnScript (torchturnscript)
        torch.cannotswitchon = "You cannot light the torch, it has burned up."
        if (torch.parent = player.parent or torch.parent = player) {
          msg ("Your torch flickers and dies.")
        }
        if (room.dark = true) {
          msg (It is too dark to see!)
        }
      }
    </script>
  </turnscript>
  <function name="EquipOneHandedWeapon" parameters="object"><![CDATA[
    if (player.right_hand = null) {
      msg ("You equip your " + GetDisplayAlias(object) + " in your right hand.")
    }
    else if (player.right_hand <> null) {
      if (HasAttribute(player.right_hand, "is_torch")) {
        player.right_hand.lightsource = False
      }
      msg ("You put away your " + GetDisplayAlias(player.right_hand) + " and equip your " + GetDisplayAlias(object) + " in your right hand.")
      list remove (player.right_hand.inventoryverbs, "Unequip")
      list add (player.right_hand.inventoryverbs, "Equip")
      player.right_hand.listalias = player.right_hand.originalalias
    }
    player.both_hands = null
    player.right_hand = object
    list add (player.equipped, object.listalias)
    list add (object.inventoryverbs, "Unequip")
    list remove (object.inventoryverbs, "Equip")
  ]]></function>
  <function name="ClearTurn">
    ClearScreen
    ShowRoomDescription
  </function>
  <function name="EquipTwoHandedWeapon" parameters="object"><![CDATA[
    if (player.right_hand = null) {
      msg ("You equip your " + GetDisplayAlias(object) + " in both hands.")
    }
    else if (player.right_hand <> null and player.right_hand = player.left_hand) {
      msg ("You put away your " + GetDisplayAlias(player.right_hand) + " and equip your " + GetDisplayAlias(object) + " in both hand.")
      list remove (player.right_hand.inventoryverbs, "Unequip")
      list add (player.right_hand.inventoryverbs, "Equip")
      player.right_hand.listalias = player.right_hand.orignalalias
      player.right_hand.equipped = False
    }
    player.both_hands = object
    player.right_hand = object
    player.left_hand = object
    object.equipped = True
    list add (player.equipped, object.listalias)
    list add (object.inventoryverbs, "Unequip")
    list remove (object.inventoryverbs, "Equip")
  ]]></function>
  <function name="LightAndUseTorch">
  </function>
  <function name="EquipOneHandedShield" parameters="object"><![CDATA[
    if (player.left_hand = null and player.both_hands = null) {
      msg ("You equip your " + GetDisplayAlias(object) + " in your left hand.")
    }
    else if (player.left_hand <> null and player.both_hands = null) {
      msg ("You put away your " + GetDisplayAlias(player.left_hand) + " and equip your " + GetDisplayAlias(object) + " in your left hand.")
      list remove (player.left_hand.inventoryverbs, "Unequip")
      list add (player.left_hand.inventoryverbs, "Equip")
      player.left_hand.listalias = player.left_hand.originalalias
      player.left_hand.equipped = False
      // /needs torch worked in///
    }
    else if (player.both_hands <> null) {
      msg ("You put away your " + GetDisplayAlias(player.both_hands) + " and equip your " + GetDisplayAlias(object) + " in your left hand.")
      list remove (player.both_hands.inventoryverbs, "Unequip")
      list add (player.both_hands.inventoryverbs, "Equip")
      player.both_hands.listalias = player.both_hands.originalalias
      player.both_hands.equipped = False
    }
    object.equipped = True
    player.both_hands = null
    player.left_hand = object
    list add (player.equipped, object.listalias)
    list add (object.inventoryverbs, "Unequip")
    list remove (object.inventoryverbs, "Equip")
  ]]></function>
</asl>

You're running ShowMenu, getting a result in result, and then running get input, which also puts its result in result.

If the player types something that starts with neither Sword nor Shield, they'll be able to light a torch without using either hand.

if (result = StartsWith ("sword")) should be if (StartsWith (result, "Sword")).

You seem to be using a whole bunch of different variables, making the situation more complex than it needs to be. You initially check left_hand and right_hand, which makes sense. But then you're also checking both_hands, and I can't see any reason for that. And later on, you have player.onehanded, which I would expect to be right_hand.


Right about the player.onehanded deal. I copied an old script and was testing the shield part. hadn't changed the sword part yet.
The bothhands is for two handed items. I made extra attributes and some I will use and others delete. The both hands is getting deleted as I check that left and right are different or same to determine the two handed weapon.
Will check the fix later as I need some shut eye. Thank mrangel.


I think I would have the light command looking something more like:

if (not GetBoolean (object, "is_torch")) {
  msg (CapFirst (Conjugate (object, "be")) + "n't a torch.")
}
else if (GetBoolean (object, "lightsource")) {
  msg ("It is already lit.")
}
else if (not Got (object)) {
  msg ("You haven't got it.")
}
else {
  if (GetBoolean (object, "equipped")) {
    object.lightsource = true
  }
  else if (player.left_hand = null or player.right_hand = player.left_hand) {
    player.left_hand = object
  }
  else if (player.right_hand = null) {
    player.right_hand = object
  }
  else {
    msg ("Your hands are full.")
    options = NewStringDictionary()
    dictionary add (options, "left_hand", GetDisplayAlias (player.left_hand))
    dictionary add (options, "right_hand", GetDisplayAlias (player.right_hand))
    this.object = object
    ShowMenu ("Which object would you like to unequip?", options, true) {
      set (player, result, light.object)
      light.object.lightsource = light.object.equipped
    }
  }
  object.lightsource = object.equipped
}

(That's assuming that player.changedleft_hand and player.changedright_hand will set the equipped flag on the object that's placed in them, as I believe you mentioned in a previous thread; and that the torch's changedlightsource script can handle changing its inventoryverbs and alias)

My brain's not in the right gear right now; but breaking the code down like this seems simpler to me. Although as your "equip" command automatically lights an equipped torch, it might be easier to just have an "equip" function, and have the torch's changedequipped script light it.


This is the "light" verb for the torch.

That should be "command" not a verb.


At the core, I think here you have a system where you have two equipment slots right_hand and left_hand. A short sword goes in the right; a shield in the left; longsword in both; and the torch in either. It sounds like that should be a fairly simple system… but then I end up thinking about a couple of edge cases that might confuse players. For example, it seems awkward to ask the player which hand to hold a torch in when they don't have anything equipped; it should just pick it up in one hand by default. But if the player lights a torch and then equips a one-hand item, it should presumably move the torch to the other hand rather than dropping it.

Now the programming bit of my brain is intrigued by the idea of a "simple" system (made up of quite a large number of simple changescripts and functions) that will behave intuitively (from the player's point of view) in all cases. Not sure if it would wind up with more or less code than the monolithic equip functions; but I'd hope it would be more extensible.

And I really need to stick to the question you asked; because I have a lot of writing to do, and my book sales are starting to slump again.


I notice that you use a flag is_torch to check if an object is a torch; but your turnscript assumes that only one torch will ever exist.

It might be easier to do something like:

<turnscript name="objects">
  <script>
    foreach (object, AllObjects()) {
      if (HasScript (object, "everyturn")) {
        do (object, "everyturn")
      }
    }
  </script>
</turnscript>

then you could give the torch an attribute:

<attr name="everyturn" type="script">
  if (this.lightsource) {
    this.life = this.life - 1
    switch (this.life) {
      case (10) {
        // code
      }
      case (5) {
        // code
      }
      case (0) {
        // code
      }
    }
  }
</attr>

So you don't need a separate turnscript for every torch; and this way, you could use the same turnscript for any other object that has a lifespan or that does something every turn.

(Also, I'd note that in the script for the torch going out, you have if (room.dark = true) - this could lead to issues. You should probably have if (CheckDarkness()) instead, so that it doesn't say "It is too dark to see" if the torch goes out in a room containing another light source)


Originally, the first line of the "light " script equipped the torch if hands were null. I only posted the portion of the script that pertained to the issue I was having.

I like that turnscript. I also like using small scripts with more attributes containing fewer actions as this may allow for a crossover of other uses as you demonstrated.

Remember that the game script I posted here was a test game just for lighting a torch. The full game has many more related scripts, attributes, and commands, some relating still to torches. I am also allowing the player to use the torch as a weapon and when they make a hit it will drastically reduce the number of turns the torch has left to burn. I am working feverishly to integrate these new scripts you offer with mine and make as many improvements to mine using your advice and script parts.

I do like it when you go beyond any issues I am asking about and you cover other problems in the script or things further down the road that may cause conflict. I don't see things coming as you do.

I noticed you had not posted a video lately and was wondering what was happening. I'm guessing this forum is your drug of choice. And you are mostly single-handedly answering questions.

Writing demands focus but it is necessary to use some moderate procrastination to give the conscious brain a break and allow the subconscious a chance to behave creatively and offer eureka moments to issues and add to the creative process. After all, that is where the true power of the mind lies.

Ha, I have been watching clinical psychologist Jordan B. Peterson on YouTube this week...


I've got 3 more videos that need editing… keep putting it off. I'm keeping up with a little of the writing, but might not be enough to keep my patreon supporters satisfied; so keep trying to focus on that. Going back to coding is often a sign I'm struggling with anxiety, which seems to kill my creativity so I try to hide by working on something I can still do instead.

Will hopefully be back to productivity some time in the near future.


Could you explain this

 set (player, result, light.object)
 light.object.lightsource = light.object.equipped

Never seen anything like it before. Is this using the command "light" as a reference?


Never seen anything like it before. Is this using the command "light" as a reference?

Yes; commands have attributes just like any other object. The only attributes they have by default are script, scope, pattern, name, and parent, but there's nothing to stop you sticking more attributes on there.

I tend to use the command, rather than the game object, to store temporary variables for menus and similar; because it makes it harder for the variables from two scripts to get confused. It matches up with the this.object = object immediately before the call to ShowMenu.

(note: within a command script, this refers to the command)


(Also, I'd note that in the script for the torch going out, you have if (room.dark = true) - this could lead to issues. You should probably have if (CheckDarkness()) instead so that it doesn't say "It is too dark to see" if the torch goes out in a room containing another light source)

I really don't need anything here because the room will go dark automatically if the torch goes out if there are no other torches in the room, and will announce the room is dark or show dark room description I've set. As long as I have other torches in the room set up as light sources, the room will stay lit. Right?

If I useShowRoomDescription in a dark room, will it show the dark room description or the lit room?


I really don't need anything here because the room will go dark automatically if the torch goes out if there are no other torches in the room, and will announce the room is dark or show dark room description I've set. As long as I have other torches in the room set up as light sources, the room will stay lit. Right?

room.dark only specifies whether the room would be dark in the absence of other light sources. With your code as written, if the torch goes out the "It is too dark to see" message will appear regardless of other light sources.

If I use ShowRoomDescription in a dark room, will it show the dark room description or the lit room?

ShowRoomDescription uses CheckDarkness to determine which description to show; so checks both the room's dark flag and the presence of light sources.


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

Support

Forums