How do I word this command?

So I have this command with a pattern of heal oran berry #object#. But the game says it can't see the player. How do I heal oran berry player? Or, how do I just heal the player with an oran berry?

I am also open to new names or patterns. This one is kind of long.

In the mean time I've just been typing "heal oran beery hat" or other objects.

This is the command's code, if that helps.

if (player.potion > 0) {
  if (player.hitpoints < player.max) {
    player.hitpoints = player.hitpoints + 30
    msg ("+30 health")
    if (player.potion > 0) {
      player.potion = player.potion - 1
    }
  }
}
else if (player.potion = 0) {
  msg ("You have no potions.")
}
else {
  msg ("You have full health.")
}
if (player.hitpoints > player.max) {
  player.hitpoints = player.max
}

just to fix up your code a bit (making it a bit more efficient, removing un-needed code lines):

(I am going to change it's behavior a bit, which you may not want, if you need help in changing it back to what you want, let me know)

if (player.potion > 0) {
  player.potion = player.potion - 1
  player.hitpoints = player.hitpoints + 30
  msg ("+30 health")
  if (player.hitpoints > player.max) {
    player.hitpoints = player.max
  }
} else {
  msg ("You have no potions.")
}

the Command's pattern, with the scripting you have for the Command, doesn't use/need the '#object#' Parameter VARIABLE at all

if the scripting is correct, then you can just do this for the pattern:

(if you want it to be 'heal oran berry', then just change my 'heal' to it, but I don't see why you couldn't just use 'heal', as people don't want to type out 'heal oran berry' when they could just type 'heal' instead)

(the below assumes you do in-fact are using a Player Object named 'player', if not, then you need to change all instances of 'player' in the scripting below, to the name your Player Object)

<command name="heal_command">

  <pattern>heal</pattern>

  <script>
    if (player.potion > 0) {
      player.potion = player.potion - 1
      player.hitpoints = player.hitpoints + 30
      msg ("+30 health")
      if (player.hitpoints > player.max) {
        player.hitpoints = player.max
      }
    } else {
      msg ("You have no potions.")
    }
  </script>

</command>

if you want your Command pattern to work on any/all Player Object/s:

<command name="heal_command">

  <pattern>heal</pattern>

  <script>
    if (game.pov.potion > 0) {
      game.pov.potion = game.pov.potion - 1
      game.pov.hitpoints = game.pov.hitpoints + 30
      msg ("+30 health")
      if (game.pov.hitpoints > game.pov.max) {
        game.pov.hitpoints = game.pov.max
      }
    } else {
      msg ("You have no potions.")
    }
  </script>

</command>

if you want your Command to handle both an inputted/dynamic 'item' (a potion, elixir, vial, etc) Object and an inputted/dynamic 'target' Object:

(you can change the wording of the pattern below, but you need the first 'word', which is your 'heal' in this case, to be unique and NOT a Parameter VARIABLE (NOT: #object#, NOR: #text#), which your 'heal' is already (I like to call this first word of a Command, the command's 'activator' word), and you need to use/have '#object#/#objectAAA#' and '#objectX#/#objectBBB#', but otherwise, you can have the pattern as whatever you want)

I'm using this for the Command's pattern:

heal #object1# with #object2#

heal: activator

#object1#: target (examples: player, HK, npc, etc)

#object2#: item (examples: oran berry, candy, chocolate, etc)

with: this isn't required at all (you could just do this as the pattern: heal #object1# #object2#, and an example input during game paly would be: heal player oran berry), as it's is just for my own nazi grammar usage, to make it "look/read" better, lol

both object1 and object2 must be Objects and for the Command to work, you must be in the same room as those Objects and/or have them within your inventory, else the Command can't find them (we can change the Command if you need it to be able to find Objects not in the same room as you and/or if not in your inventory)

example of what you'd type in during game play:

heal player with oran berry

// this of course would require that both the 'oran berry' and 'player', exists as an Object within the same room as you (or that it is you, lol) and/or within your inventory, and also that these Objects have the Attributes that the scripting uses for their Attributes

<command name="heal_command">

  <pattern>heal #object1# with #object2#</pattern>

  <script>
    if (object2.quantity > 0) {
      object2.quantity = object2.quantity - 1
      object1.hitpoints = object1.hitpoints + 30
      msg ("+30 health")
      if (object1.hitpoints > object1.max) {
        object1.hitpoints = object1.max
      }
    } else {
      msg ("You have no potions.")
    }
  </script>

  <unresolved>Quest can't locate/find those Objects within the game.pov 's parent room (game.pov.parent), nor within the inventory (game.pov), which could also mean that those Objects don't exist at all anywhere within the game or that you merely typo-ed/mis-spelled the Objects with your input during game play</unresolved>

</command>

if you're still having trouble...

it may be that the space for/within 'oran berry' is confusing/messing up the parser for the Command trying to match up your input with the pattern ... try removing the space or using an underscore instead (for example, you'd have to change all instances of 'oran berry' to 'oran_berry' within/throughout your ENTIRE GAME CODE and any libraries that use/have 'oran berry' within them as well


So I have this command with a pattern of heal oran berry #object#. But the game says it can't see the player. How do I heal oran berry player? Or, how do I just heal the player with an oran berry?

If an object has an alias, Quest will use that instead of the object's name when matching. So while the player object has the name object, Quest will not match that because it has an alias too. If you go to the Player tab of the player, you will see that the alias is "me", and typing HEAL ORAN BERRY ME should work.

If you want, you can add "player" to the list of other names on that tab.

I would also suggest HK's "heal #object1# with #object2#" is probably a better way to do it.


forgot the CDATA tags (if you want to use my code), fixed/corrected:


<command name="heal_command">

  <pattern>heal #object1# with #object2#</pattern>

  <script>

    <![CDATA[

      if (object2.quantity > 0) {
        object2.quantity = object2.quantity - 1
        object1.hitpoints = object1.hitpoints + 30
        msg ("+30 health")
        if (object1.hitpoints > object1.max) {
          object1.hitpoints = object1.max
        }
      } else {
        msg ("You have no potions.")
      }

    ]]>

  </script>

  <unresolved>Quest can't locate/find those Objects within the game.pov 's parent room (game.pov.parent), nor within the inventory (game.pov), which could also mean that those Objects don't exist at all anywhere within the game or that you merely typo-ed/mis-spelled the Objects with your input during game play</unresolved>

</command>

<command name="heal_command">

  <pattern>heal</pattern>

  <script>

    <![CDATA[

      if (game.pov.potion > 0) {
        game.pov.potion = game.pov.potion - 1
        game.pov.hitpoints = game.pov.hitpoints + 30
        msg ("+30 health")
        if (game.pov.hitpoints > game.pov.max) {
          game.pov.hitpoints = game.pov.max
        }
      } else {
        msg ("You have no potions.")
      }

    ]]>

  </script>

</command>

<command name="heal_command">

  <pattern>heal</pattern>

  <script>

    <![CDATA[

      if (player.potion > 0) {
        player.potion = player.potion - 1
        player.hitpoints = player.hitpoints + 30
        msg ("+30 health")
        if (player.hitpoints > player.max) {
          player.hitpoints = player.max
        }
      } else {
        msg ("You have no potions.")
      }

    ]]>

  </script>

</command>

My player's alias is Gold. So there is that.
In none of my other games can I type "Heal potion player" or something. I don't know why. I end up creating a potion bag because I can't type player, and it's just easier to click on an object instead of type.

So I opened my game. I typed "heal oran berry Gold" and that worked. I typed "heal oran berry me" and that worked. I typed "heal oran berry player" and it said it can't see that (player). I changed the command's name to heal1, and that worked.

The command uses the potion attribute I created, not an object.


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

Support

Forums