Login
Remember
IF Answers
Ask a Question

# How do I set up an "If" for a container to have multiple objects?

0 votes
190 views
asked May 19 in Authoring by Scoticis (1 point)
edited May 20 by Alex

I am wanting to make a if script in my game were you make a kettle of tea. I have it that you put the tea in the kettle then when you put it on the fire it tells you you have made tea. I want to make it that you need tea and water for it to say you have made tea. How do I put two objects into the if?

- programming
- quest

commented May 20 by Scoticis (1 point)
That's great! Thank you all for the help. :)
commented May 21 by Scoticis (1 point)
This is what I now have. It is a fraction of the size it will end up as there will be up to 60 herbs dried and fresh.
The problem I am now having is that when it makes tea it comes up with the text that you need water and herbs every time.
And ideas?
if (Contains (Kettle,Dried Thyme)) {
if (Contains (Kettle,Water)) {
IncreaseScore (10)
msg ("You make a nice pot of Thyme tea")
RemoveObject (Dried Mint)
play sound ("Bubbling Cauldron-SoundBible.com-144527974.wav", false, false)
play sound ("", false, false)
}
msg ("You need water and herbs to make tea.")
}
else if (Contains (Kettle,Dried Mint)) {
if (Contains (Kettle,Water)) {
IncreaseScore (15)
msg ("You make a nice pot of mint tea")
RemoveObject (Dried Mint)
play sound ("Bubbling Cauldron-SoundBible.com-144527974.wav", false, false)
play sound ("", false, false)
}
msg ("You need water and herbs to make tea.")
}
else if (Contains (Kettle,Dried Fennel)) {
if (Contains (Kettle,Water)) {
IncreaseScore (5)
msg ("You make a nice pot of Fennel tea")
RemoveObject (Dried Fennel)
play sound ("Bubbling Cauldron-SoundBible.com-144527974.wav", false, false)
}
msg ("You need water and herbs to make tea.")
}
else if (Contains (Kettle,Thyme1)) {
if (Contains (Kettle,Water)) {
IncreaseScore (10)
msg ("You make a nice pot of Thyme tea")
play sound ("Bubbling Cauldron-SoundBible.com-144527974.wav", false, false)
RemoveObject (Thyme1)
}
msg ("You need water and herbs to make tea.")
}
else if (Contains (Kettle,Mint)) {
if (Contains (Kettle,Water)) {
IncreaseScore (10)
msg ("You make a nice pot of Mint tea")
play sound ("Bubbling Cauldron-SoundBible.com-144527974.wav", false, false)
RemoveObject (Mint)
}
msg ("You need water and herbs to make tea.")
}
else if (Contains (Kettle,Fennel)) {
if (Contains (Kettle,Water)) {
IncreaseScore (5)
msg ("You make a nice pot of Fennel tea")
play sound ("Bubbling Cauldron-SoundBible.com-144527974.wav", false, false)
RemoveObject (Fennel)
}
msg ("You need water and herbs to make tea.")
}
CloneObjectAndMove (Kettle, Fire)
commented May 22 by Alex (486 points)
Please don't ask new questions in comments as nobody will answer. Just post a new question.

## 2 Answers

+1 vote
answered May 20 by The Pixie (121 points)

The easiest way is to have one if inside the other. The first if can check whether the water is in there, the second if can check if the tea is in there.

In code:

    if (Contains (teapot,water)) {
      if (Contains (teapot,tea)) {
        msg ("You make some tea")
      }
      else {
        msg ("You need tea leaves in the water to make tea.")
      }
    }
    else {
      msg ("Want to put some water in there first?")
    }

0 votes
answered May 19 by hegemonkhan (161 points)
edited May 19 by hegemonkhan

the easiest way for a new person:

conceptually:

you want the 'if' Script to check whether your 'player' Player Object has both your 'tea' Object and your 'water' Object in its inventory.

Objects:
1. the 'player' Player Object
2. the 'kettle' Object
3. the 'water' Object
4. the 'tea' Object
5. the 'fire~stove' Object (but I'm excluding this factor from within the examples below)

so, when you have the 'water' Object and the 'tea' Object in your inventory (inside~held within the 'player' Player Object), then you'll boil~make the tea, as it satisfies the 'kettle' Object's (for example) 'boil' Verb's 'if' Script's checking, otherwise, it doesn't satisfy it (else), and you get a different message in response.

practically (in code):

I'm not that familiar with the GUI~Editor, as I do most stuff in code, so hopefully you can figure it out how to do this below via the GUI~Editor's Script options and drop down menus:

(sorry for the code, hopefully it won't scare you, but it should be instructional for what you need to roughly do~find in the GUI~Editor's Script options and drop down menus, as it does read quite non-code friendly, which is how I was able to learn it, laughs)

(this code will be more extensive, all~most scenario combinations, than probably what you will do, but it's good to see it ~ to learn the 'if' logic mentality required that you need to start training your brain in doing as it's not natural for most people, regardless of whether you work with code or within the GUI~Editor, to make games)

    if (Contains (player, water) and Contains (player, tea) ) {
      msg ("You boil the tea on the stove's fire, and after it cools a bit, you take a sip, delicious!")
    } else if (Contains (player, water) and not Contains (player, tea) ) {
      msg ("Silly, you can't make tea without tea!")
    } else if (not Contains (player, water) and Contains (player, tea) ) {
      msg ("Silly, you can't make tea without water to boil it in!")
    } else if (not Contains (player, water) and not Contains (player, tea) ) {
      msg ("Silly, you don't have either water nor tea, so you need to go get them, first!")
    }

practically (in~via the GUI~Editor):

in the GUI~Editor... I'm not sure on this, but it should be something like this:

(minimal scenario combination example, as opposed to my above code)

'kettle' Object -> 'Verb' Tab -> Add -> Name (custom: not a pre-existing Verb): 'boil', Scripts: (see below)

add a script -> scripts -> 'if' Script -> ~ [Object has another object] or ~ [player inventory has object] -> [player] [tea] and [player] [water]
-> then, -> add a script -> output -> print a message -> [MESSAGE] -> (your message ~ whatever you want to say)
else,
-> add a script -> output -> print a message -> [MESSAGE] -> (your message ~ whatever you want to say)

make sure that you click on the correct 'add a script' circle buttons... as this matters (it determines the 'order of operations' of the code~script lines, just like how in math, you got an 'order of operation's procedure to use for correctly calculating a math expression), and it's not easy to see what are the correct buttons to click on... argh (one of the reasons I moved to the code, laughs).

commented May 19 by hegemonkhan (161 points)
You could alternatively have the 'tea' and 'water' be able to be put into the 'kettle' itself instead, but you'd then have to set up the scripts correctly for using the 'kettle' instead of the 'player' (your 'inventory' ).
if you would rather have this design, and you need help with it, then let me~us know, and we'll help.
----------
P.S.
someone else will give you a better guide~help, so if you can't figure out what to do from my post, just wait for them to help you. As I'm not as familiar with the GUI~Editor, whereas they will be, giving you a step by step guide via using the GUI~Editor, and very clearly too. I'm not very good at it, as can be seen, laughs.

## Related questions

- How do I move an item I have more of in the world (since it's a kind of thing)?
- How to set up a condition involving the presence of a character.
- How do I give an object to a character and receive something back?
- How do I make verbs synonymous for only certain objects in Quest 5.6.1?
- How do I set a variable by asking the player a question in Quest?

...