How to handle consumables

Hi

What is the normal way to handle consumable items like food? Ideally, I'd like to use clones and when the clone has been "eaten" destroy the clone, but I do not know how to destroy cloned items since they don't have a unique name.

So what I did was create a non-accessible room and put the consumables, like a piece of cheese, in there. When the player can get cheese, I move the cheese from the store room to the player's room, so he can pick it up. When the player eats it, I move it back to the non-accessible room. However, this means I can only ever one piece of cheese at any one time.

Any help appreciated

/Jason


Could you not use aliases to do this? i.e. if you want three pieces of cheese then create 3 items, call them cheese1, cheese2, cheese3, but give all of them the alias 'cheese' or 'piece of cheese'


Hi Jason I recently started a series of tutorials using the GUI Editor https://youtu.be/HD1Gj88KeQE
Basically I make a item, when pick up the clone I add made item to my inventory, remove 'this'(this will remove clone) add to item volume. Then if you already have said item just simply remove 'this' and add 1 to volume. In the tutorials I have part 2 is stacking items then part 3 is eating the item.

Hope it helps
Mike


Hi & thanks

@NecroDeath... yes, I considered that but I thought there might be a better way...

@onimike... great! This is what I was looking for.

/jason


Glad its helps :)

Mike


the one of best designs (if there's no un-fore-seen reasons that you need Clones):

make only a single Object (of each type of Object you need), and then reference that single Object, via using Object Attributes.

for an example (using equipment for this purpose):

<object name="global_data_object">
  <object name="global_equipment_data_object">
    <object name="global_weapon_data_object">
      <object name="global_sword_weapon_data_object">
        <object name="katana_sword_weapon_object">
          <attr name="damage_integer_attribute" type="int">50</attr>
        </object>
        <object name="claymore_sword_weapon_object">
          <attr name="damage_integer_attribute" type="int">40</attr>
        </object>
        <object name="short_sword_sword_weapon_object">
          <attr name="damage_integer_attribute" type="int">5</attr>
        </object>
      </object>
      <object name="global_unarmed_weapon_data_object">
        <object name="unarmed_unarmed_weapon_object">
          <attr name="damage_integer_attribute" type="int">1</attr>
        </object>
      <object>
      <object name="global_blunt_weapon_data_object">
        <object name="club_blunt_weapon_object">
          <attr name="damage_integer_attribute" type="int">10</attr>
        </object>
      <object>
    </object>
    <object name="global_armor_data_object">
    </object>
    <object name="global_clothing_data_object">
    </object>
  </object>
</object>

<object name="room">
</object>

<object name="player">
  <attr name="parent" type="object">room</attr>
  <attr name="right_hand_object_attribute" type="object">unarmed_unarmed_weapon_object</attr>
  <attr name="current_life_integer_attribute" type="int">100</attr>
</object>

<object name="HK">
  <attr name="parent" type="object">room</attr>
  <attr name="right_hand_object_attribute" type="object">katana_sword_weapon_object</attr>
  <attr name="current_life_integer_attribute" type="int">100</attr>
</object>

<object name="knight">
  <attr name="parent" type="object">room</attr>
  <attr name="right_hand_object_attribute" type="object">claymore_sword_weapon_object</attr>
  <attr name="current_life_integer_attribute" type="int">100</attr>
</object>

<object name="npc">
  <attr name="parent" type="object">room</attr>
  <attr name="right_hand_object_attribute" type="object">swort_sword_sword_weapon_object</attr>
  <attr name="current_life_integer_attribute" type="int">100</attr>
</object>

<object name="orc">
  <attr name="parent" type="object">room</attr>
  <attr name="right_hand_object_attribute" type="object">club_blunt_weapon_object</attr>
  <attr name="current_life_integer_attribute" type="int">100</attr>
</object>

<object name="player_2">
  <attr name="parent" type="object">room</attr>
  <attr name="right_hand_object_attribute" type="object">unarmed_unarmed_weapon_object</attr>
  <attr name="current_life_integer_attribute" type="int">100</attr>
</object>

<object name="player_3">
  <attr name="parent" type="object">room</attr>
  <attr name="right_hand_object_attribute" type="object">katana_sword_weapon_object</attr>
  <attr name="current_life_integer_attribute" type="int">100</attr>
</object>

// pretend we're doing a 'fight' scripting, just for examples-sake, this is what we'd get:

orc.current_life = orc.current_life - player.right_hand_object_attribute
// orc.current_life = 100 - 1 = 99

orc.current_life = orc.current_life - HK.right_hand_object_attribute
// orc.current_life = 100 - 50 = 50

orc.current_life = orc.current_life - knight.right_hand_object_attribute
// orc.current_life = 100 - 40 = 60

orc.current_life = orc.current_life - npc.right_hand_object_attribute
// orc.current_life = 100 - 5 = 95

player.current_life = player.current_life - orc.right_hand_object_attribute
// orc.current_life = 100 - 10 = 90

and, of course we can change the 'right_hand_object_attribute' too (in scripting example):

player.right_hand_object_attribute = katana_sword_weapon_object
player.right_hand_object_attribute = claymore_sword_weapon_object
player.right_hand_object_attribute = club_blunt_weapon_object
player.right_hand_object_attribute = short_sword_sword_weapon_object
player.right_hand_object_attribute = unarmed_unarmed_weapon_object

player.right_hand_object_attribute = unarmed_unarmed_weapon_object
player_2.right_hand_object_attribute = unarmed_unarmed_weapon_object
player_3.right_hand_object_attribute = unarmed_unarmed_weapon_object

player.right_hand_object_attribute = katana_sword_weapon_object
player_2.right_hand_object_attribute = katana_sword_weapon_object
player_3.right_hand_object_attribute = katana_sword_weapon_object

if you need/want to use Clones, then you can remove/delete the Clones via using the 'String Manipulation' Functions:

http://docs.textadventures.co.uk/quest/functions/ (scroll down to the very bottom, to the 'String Functions' section/cateogry)

and in particular: ( http://docs.textadventures.co.uk/quest/functions/string/startswith.html and also optionally: http://docs.textadventures.co.uk/quest/functions/string/lengthof.html )

Master/Original Object: potion
Cloned Objects: potion1, potion2, potion3, etc etc etc

thus:

if (StartsWith (NAME_OF_CLONE.name, "potion") and NAME_OF_CLONE.name > LengthOf ("potion") { // will be a clone, the 'LengthOf' is what prevents your Master/Original Object from being removed/deleted
  delete (NAME_OF_CLONE)
}

or

if (StartsWith (NAME_OF_CLONE.name, "potion") and not EndsWith (NAME_OF_CLONE.name, "potion") { // will be a clone, the 'not EndsWith' is what prevents your Master/Original Object from being removed/deleted
  delete (NAME_OF_CLONE)
}

// I'm too tired (or am just unable/not-knowledge'able-enough) to tell which is more efficient, and/or any other issues involved

and then there's:

Contains ( http://docs.textadventures.co.uk/quest/functions/contains.html )
and/or
ListContains ( http://docs.textadventures.co.uk/quest/functions/listcontains.html )

using lists ( http://docs.textadventures.co.uk/quest/guides/using_lists.html )
ListCount ( http://docs.textadventures.co.uk/quest/functions/listcount.html )
Got
StringListItem
AllObjects
the various 'Scope' Functions

and etc Functions/Scripts...

see, if you can figure it out first, and if not, let me know and I'll help further.