Container that will only take specific items?

Benjymite
05 Aug 2016, 20:48

Hi, I'm fairly new to this program and have been fiddling around with containers. I made a coatrack, and was wondering if it was possible to limit the specific items a player can store on it. Since it's a coatrack, it doesn't make a whole lot of sense that the player can put their wallet on it. Can I somehow make it so that only certain items (a hat, a coat) can be placed on the coatrack, or is this not possible?

Thanks in advanced.


XanMag
05 Aug 2016, 21:49

I had a similar issue about a week ago. It is not a real simple solution but it's not too complex either.

Check this thread out and if you can't make sense of the solution, ask again and I'll give you a walk through. :)

http://textadventures.co.uk/forum/quest/topic/iujt33cap0masdrym25qyw/different-objects-in-a-container-raising-different-flags


Benjymite
05 Aug 2016, 22:29

Thanks for the response. I might need a little help interpreting the solution, yes. If I'm understanding what's going on here, my problem is a little bit simpler in theory (though I don't know if it's any simpler to be executed). All I need is to prevent players from putting most items EXCEPT for ones that make sense on the coatrack.

So if the player tries to put their keys or wallet on the coatrack, they would get a message like, "I can't put that on a coatrack."
But if they try something that makes sense like a coat or hat, it just lets them use the container normally.

Again, this might be just as complicated as your problem was when it comes to actual implementation. If you can help me figure this out, I would be very grateful.


XanMag
05 Aug 2016, 23:47

Here's my "hacky" solution assuming the coat rack cannot be moved from room to room.

  1. Right click on the room containing the coat rack.
  2. Choose add command.
  3. Choose 'regular expression.
  4. Type this in the box under 'regular expression': ^(put|place|hang) (?<.object>.*) (in|into|on) (coat rack)$ - (note - you may want to change the verbs and prepositions and/or the noun there, I just wrote what I thought made sense). Also, remove the period before the word object in the code above! =)
  5. For the script, choose an If.
  6. Select expression.
  7. In the box next to that, type object = coat
  8. Then, print message indicating that the coat has been placed on the coat rack. Also add here the move object script to move coat to object coat rack.
  9. For every item that you want place on the coat rack, repeat the process above (changing object 'coat' to whatever object you wish.
  10. In the Else, you'll need to add a message indicating that the object being placed there does not make sense, example: "Why would you try and put that on a coat rack?"

NOTE: I have not tried this out. I know that everything up to the 'Else' script will work. I'm not sure exactly what to put in there. I will try this out when I get in front of my computer.

Someone more knowledgeable may come around and suggest an easier/more logical solution.

Good luck!


hegemonkhan
06 Aug 2016, 02:20

this is probably talked about in the other thread-link, maybe by me myself lol, but oh well, here it is (maybe again):

the basic idea/concept, is to have something that identifies/flags each Object as: what type of Object it is / what it is, which you can then use 'if' scripting to check if that type of items matches up (or doesn't match up) with what you want to go into the container object vs what you don't want to go into that container object.

or/also maybe try thinking of it like this:

let's say we've got two trash containers, such as one for trash and one for recycling (as everyone is probably familiar with):

you need to be able to tell/check whether each trash item is trash or recycle'able, to determine which trash container (trash or recycle) to put the trash item/object into.

in real life, we can just look at the trash item (and with our common knwledge) to see what type of trash it is and which trash container it goes into (ah, it's an aluminum soda can, that goes into the recycle bin. Ah, that's an old piece of food, it goes into the trash bin). Through our eyesight and common knowledge, this is our natural indicators/flags of what type of trash item it is, and thus which trash container (trash or recycle) it goes into.

with programming, we need to define an indicator, and then using conditional (if) scripting along with that indicator/flag, to determine where to put something (or not) / what to do (or not do).

So, for an example:

give every Object a String Attribute or Boolean Attribute (or Integer Attribute - but let's just use a String or Boolean here), which indicates what type of Object it is:

<object name="soda_can">
   // using a String Attribute:
  <attr name="our_indicator" type="string">recycle</attr>
  // or, using a Boolean Attribute:
  // <attr name="our_indicator_as_is_this_recycle" type="boolean">true</attr>
</object>

<object name="old_rotten_food">
   // using a String Attribute:
  <attr name="our_indicator" type="string">trash</attr>
  // or, using a Boolean Attribute:
  // <attr name="our_indicator_as_is_this_recycle" type="boolean">false</attr>
</object>

// let's say for this example, this is our: 'trash_bin' Object's 'put/putin/use/useon/whatever lol' Verb/Command:

// for with using the String Attribute:
object = (your_inputted_object: soda_can or old_rotten_food) 
if (object.our_indicator = "trash") {
  MoveObject (object, trash_bin)
} else {
  msg ("sorry, but you can only put trash into the trash bin.")
}

// or, for with using the Boolean Attribute:
object = (your_inputted_object: soda_can or old_rotten_food)
if (object.our_indicator_as_is_this_recycle = false) {
  MoveObject (object, trash_bin)
} else {
  msg ("sorry, but you can only put trash into the trash bin.")
}

// let's say for this example, this is our: 'recycle_bin' Object's 'put/putin/use/useon/whatever lol' Verb/Command:

// for with using the String Attribute:
object = (your_inputted_object: soda_can or old_rotten_food) 
if (object.our_indicator = "recycle") {
  MoveObject (object, recycle_bin)
} else {
  msg ("sorry, but you can only put recycle'ables into the recycle bin.")
}

// or, for with using the Boolean Attribute:
object = (your_inputted_object: soda_can or old_rotten_food) 
if (object.our_indicator_as_is_this_recycle = true) {
  MoveObject (object, recycle_bin)
} else {
  msg ("sorry, but you can only put recycle'ables into the recycle bin.")
}

XanMag
06 Aug 2016, 05:23

Does someone with some coding knowledge know if step 10 above works as I have written it or will the OP need something like If object = #object# then print desired message?


hegemonkhan
06 Aug 2016, 06:37

'else' does not care about anything except whether the same 'if' block's 'else if/s' and 'if' is met or not. If the same 'if' block's 'else if/s' and 'if' is not met, then the 'else' activates/runs, nothing stops/prevents/blocks it from running/activating at this point. So, it should work fine.

if (ball.color = "red") {
  msg ("red")
} else if (ball.color = "blue")
  msg ("blue")
} else {
  msg ("11111111111111111")
}

if (player.strength_integer > 66) {
  player.strength_string = "strong"
} else if (player.strength_integer > 33) {
  player.strength_string = "average"
} else {
  player.strength_string = "weak"
}

the '1111111111111' will be displayed if both the, 'if (ball.color = "red")' and 'else if (ball.color = "blue")', fails, regardless of the 2nd 'if block' below it. If 'red' or 'blue' is displayed, then the '1111111111' is NOT displayed.

the 'player.strength_string' will be set to 'weak', if both the, 'if (player.strength_integer > 66)' and 'else if (player.strength_integer > 33)', fails, regardless of whatever happens in/with the first/upper 'if' block. If 'player.strength_string' is not set to neither: 'strong' or 'average', then it IS set to 'weak'.

(also, the 2nd/lower 'if' block will always run, regardless of what happens in/with the first/upper 'if' block)

P.S.

when I say the 'if' block, I mean the entire block, not just the first 'if (.....)' code line of it (if it has the additional 'else ifs' and/or 'else' conditional code lines of it. If the 'if' block is just a/the single 'if (....)' code line, then that's the entire 'if' block)

the different forms/types of the 'if' block:

1. an 'if', 'if' block:

if (conditional) {
  // scripting
}

2. an 'if + else', 'if' block:

if (conditional) {
  // scripting
} else {
  // scripting
}

3. an 'if + else if', 'if' block:

if (conditional) {
  // scripting
} else if (conditional) {
  // scripting
} // optionally extra/more 'else ifs'

4. an 'if + else if + else', 'if' block:

if (conditional) {
  // scripting
} else if (conditional) {
 // scripting
} // optionally extra/more 'else ifs'
} else {
  // scripting
}

also, this is an important concept to understand about 'if' scripting:

why is an 'if' block important, why does this concept matter?

ball_1.color = "red"
ball_2.color = "blue"
ball_3.color = "purple"
ball_4.color = "green"

if (ball_1.color = "red") {
  msg ("red")
}

if (ball_2.color = "blue") {
  msg ("blue")
}

if (ball_3.color = "purple") {
  msg ("purple")
}

if (ball_4.color = "green") {
  msg ("green")
}

in the above design, we've got 4 ('if) 'if' blocks, which will result in this output:

red
blue
purple
green

because each ('if') 'if' block is independant of the other ('if') 'if' blocks.


but now let's change the design:

ball_1.color = "red"
ball_2.color = "blue"
ball_3.color = "purple"
ball_4.color = "green"

if (ball_1.color = "red") {
 msg ("red")
} else if (ball_2.color = "blue") {
 msg ("blue")
} else if (ball_3.color = "purple") {
 msg ("purple")
} else if (ball_4.color = "green") {
 msg ("green")
}

what happens now?

Answer:

red

this is because we now got a single ('if + else ifs') 'if' block, which means that since it's first condition of 'if (ball_1.color = "red")' is met, then the other conditions (the 3 'else ifs') are NOT even checked/run/activated. And so, despite that we're (still: unchanged model part) looking at 4 different Objects (ball_1, ball_2, ball_3, ball_4) and as well as having all of their conditions (still: unchanged model part) being true/met, it still will only display 'red', and not the: 'blue' (ball_2), 'purple' (ball_3), and 'green' (ball_4), as again it's a single 'if' block, once a condition is met, NONE of the following/after/latter/other conditions are looked at, and thus no displayment of 'blue', 'purple', and 'green' for this example.


let's change the design again:

ball_1.color = "red"
ball_2.color = "blue"
ball_3.color = "purple"
ball_4.color = "green"

if (ball_1.color = "red") {
 msg ("red")
} else if (ball_2.color = "blue") {
 msg ("blue")
} else if (ball_3.color = "purple") {
 msg ("purple")
} else if (ball_4.color = "green") {
 msg ("green")
}

if (ball_1.color = "red") {
 msg ("red")
} else if (ball_2.color = "blue") {
 msg ("blue")
} else if (ball_3.color = "purple") {
 msg ("purple")
} else if (ball_4.color = "green") {
 msg ("green")
}

if (ball_2.color = "blue") {
 msg ("blue")
} else if (ball_3.color = "purple") {
 msg ("purple")
} else if (ball_4.color = "green") {
 msg ("green")
}

if (ball_1.color = "red") {
 msg ("red")
} else if (ball_2.color = "blue") {
 msg ("blue")
} else if (ball_3.color = "purple") {
 msg ("purple")
} else if (ball_4.color = "green") {
 msg ("green")
}

if (ball_3.color = "purple") {
 msg ("purple")
} else if (ball_4.color = "green") {
 msg ("green")
}

if (ball_1.color = "red") {
 msg ("red")
} else if (ball_2.color = "blue") {
 msg ("blue")
} else if (ball_3.color = "purple") {
 msg ("purple")
} else if (ball_4.color = "green") {
 msg ("green")
}

if (ball_4.color = "green") {
 msg ("green")
}

if (ball_1.color = "red") {
 msg ("red")
} else if (ball_2.color = "blue") {
 msg ("blue")
} else if (ball_3.color = "purple") {
 msg ("purple")
} else if (ball_4.color = "green") {
 msg ("green")
}

now what happens?? (this hopefully isn't challenging...)

answer:

red
red
blue
red
purple
red
green
red


so, sometimes you want multiple if blocks for your conditions, and sometimes you want a single if block for your conditions, so it depends on what scripting logic (or rather just: logic) you want to happen, as to how to design your scripting.


so, pretend you're me (SCARY!), and thus you're super lazy!

would you rather have to do all of these chores:

clean your room, mow the lawn, take the trash out, wash your clothes, iron your clothes, and clean the dishes

or, would you rather get out of all the latter chores upon doing a prior choir? (that is, IF YOU CAN, of course)

as me, you like being able to get out of from doing all of the following chores upon doing whatever prior choir!

well, computers/processors/CPUs/software/quest is just like me, it doesn't want to do more chores (operations) if it can be helped / not have to do them. It wants to do as few as possible too. If humans had to do endless chores/work, they'd die. Well, when a computer/CPUs/prcoessors/software/quest has to do endless operations (such as an endless/infinite loop), it dies too! (there are safegaurds now, so you can't actually destroy your computer, but with the early computers, there weren't... and you would destroy your computer: even if pretending that a computer had infinite resources/storage/memory - which nothing has - it doesn't exist anywhere at least for our practical world - not getting into crazy stuff with blackholes/void:nothingness/pre-big-bang, the endless/infinite energy being produced/released from doing those endless/infinite operations would fry/melt/burn up the computer --- I never realized how hot computers can get until I learned about repairing them - opening them up and being able to touch the parts inside - burning my fingers lol - they get REALLY hot! And thus computers try to have as much cooling systems as they can and if you can afford it too, lol. Computers do catch on fire and melt/burn/fry up when the heat/energy exceeds the cooling systems or the cooling systems fail or there's no cooling systems, lol. It's actually similiar to nuclear power plants, as expensive powerful prcoessing computers even use, must use, a similiar liquid cooling system as do nuclear reactors for their radioactive rods). any action (operation) that a computer does, is actually just electrical circuitry/currents, and thus the more actions (operations) a computer does, the more electrical currents of flowing, and thus the hotter it gets, which is bad for computer performance, and ultimately the computer's physical existence itself too (as it actually catches on fire and burns up/melts).


Benjymite
06 Aug 2016, 07:51

Thanks guys, this is really helpful. By sort of looking at both of your answers I figured out how to get it setup, and now it works great! Now I just have to remember to add the attribute to all the items that can be picked up.


hegemonkhan
06 Aug 2016, 08:52

awesome, you understand! (my posts usually end up confusing people even more, lol. Good thing you had XanMag's post/s to read, lol)


just a quick note:

unfortunately the distinctions/indicators/flags of: 'Object Type: [Room Object]', 'Object Type: [Object]', 'Object Type: [Player Object]', '<inherit name="editor_player" />', '<inherit name="editor_room" />', and '<inherit name="editor_object" />' that you may have noticed in the GUI~Editor and/or in code, are deleted/removed when the game starts (they're merely for creating the GUI~Editor that you're using, providing you with its options/tabs/drop down menus/etc). So, if you thought that you could use scripting to check upon these as your indicators/flags as to what to do, you're going to have failure. You got to create your own indicator/flag Attribute on each of the Objects.

for example:

<object name="room_2">
  <attr name="alias" type="string">tavern</attr>
  <attr name="type_of_object" type="string">room</attr>
</object>

<object name="room_3">
  <attr name="alias" type="string">forest</attr>
  <attr name="type_of_object" type="string">room</attr>
</object>

<object name="room_99">
  <attr name="alias" type="string">final room of the final dungeon (you're going to die here! muahaha!)</attr>
  <attr name="type_of_object" type="string">room</attr>
</object>

<object name="orc_1">
  <attr name="parent" type="object">room_3</attr>
  <attr name="alias" type="string">orc</attr>
  <attr name="type_of_object" type="string">monster</attr>
  <attr name="dead" type="boolean">false</attr>
</object>

<object name="dragon_99">
  <attr name="parent" type="object">room_99</attr>
  <attr name="alias" type="string">Bahamut (King of Dragons)</attr>
  <attr name="type_of_object" type="string">monster</attr>
  <attr name="dead" type="boolean">false</attr>
</object>

<object name="tavernmaid_5">
  <attr name="parent" type="object">room_2</attr>
  <attr name="alias" type="string">Hag (an ugly old woman)</attr>
  <attr name="type_of_object" type="string">npc</attr>
</object>

<object name="tavernmaid_3">
  <attr name="parent" type="object">room_2</attr>
  <attr name="alias" type="string">Jasmine (a beautiful young woman)</attr>
  <attr name="type_of_object" type="string">npc</attr>
</object>

<object name="table_8">
  <attr name="parent" type="object">room_2</attr>
  <attr name="alias" type="string">table</attr>
  <attr name="type_of_object" type="string">furniture</attr>
</object>

// scripting, using a Command for quick example:

<command name="cheat_command">
  <pattern>cheat #text#</pattern>
  <script>
    foreach (object, AllObjects()) {
      if (object.name = text or object.alias = text) {
        if (object.type_of_object = "room") {
          player.parent = object
          msg ("You discovered a cheat input, allowing you to warp/teleport to whatever location you inputted! doh, I forgot to take this out upon releasing the game to the public, doh!")
        } else if (object.type_of_object = "monster") {
          object.dead = true
          msg ("You discovered a cheat input, killing the monster you inputted! doh, I forgot to take this out upon releasing the game to the public, doh!")
        } else if (object.type_of_object = "npc") {
          if (object.alias = "jasmine (a beautiful young woman)") {
            msg ("(you found a cheat input, which wins the game for you! doh, I forgot to take this out upon releasing the game to the public, doh!)")
            msg ("You marry Jasmine, and live happily ever after!")
            msg ("You won the game, congratulations!")
            msg ("GAME OVER")
            finish
          } else {
            msg ("No, you don't want to marry this person!")
          }
        } else {
          msg ("Wrong input, try again.")
        }
      } else {
        msg ("Wrong input, try again.")
      }
    }
  </script>
</command>