"If" commands with two or more conditions

Mareus
So again I am stuck and I have been trying for the last few days to make one of my starting rooms a bit more interactive visually. With that I mean, I am trying to add pictures which correspond with what is happening in the environment. The problem that I am having though is that there are many things happening and I keep messing up somewhere, to the point that I am completely lost now and have no clue what the hell is happening anymore. I am also out of ideas, so please help.

Its even difficult to explain, but but basically I have 5 conditions.

1. You start by lying on the bed and if I you are lying on the bed, I dont want the player to be able to do anything until he gets up. A message might appear something like: "You can't reach it while you are lying on the bed." The only thing that I can interact with from the bed is the alarm clock and there I want to be able to decide whether to pick it up or turn it off. If I turn it off, i want to skip point 2 and go directly to point 3. If I pick it up the clock is still ringing, but it is in my inventory.
2. If I get up, I have the second condition. Basically the alarm clock is ringing and you cannot focus on anything until you turn it off. So, although you can now reach certain stuff, you can't really interact with it in any meaningful way, until you turn the clock off. A message like this might pop out: "I can't focus!"
3. Once the clock is turned off and the player is up, I want to have full access to everything.
4. There is also a suitcase that needs to be moved to bed and back again, but I can interact with it only after point 3 is done. All of this I already managed to achieve, but here comes the tricky part where stuff gets messy.
5. I also have pictures involved. So, I want to be able to see the change happening when for example the clock is missing from the desk and the suitcase is lying on the bed. So, there are actually 4 pictures that have to be compatible with ShowRoomDescription based on the choices you make. Also the picture needs to change instantly as you make change to the environment:
a.)Picture of the clock ringing on the desk and the suitcase lying under the bed.
b.) Picture of the clock ringing on the desk and the suitcase on top of the bed.
c.) Picture of the clock missing from the desk and the suitcase lying under the bed.
d.) Picture of clock missing from the desk and the suitcase on top of the bed.

There are only 2 descriptions for this room. One is set before you enter the room and it basically just says that you woke up. The second kicks in when I turn off the clock and you get more details about the room.

Now, I don't expect anyone to code this for me. I know its hell of a job to do that, But any suggestions how to do it? I tried copying the same room a couple of times and moving the player around based on these conditions, but then I have so many items that are cloned that I cant make sense of it, and the worst part is that it doesn't work either. I usually get pictures mixed up and appearing at the wrong time in the wrong place. I tried having one room and two clocks (one that is ringing and one that is not ringing), same result. I have tried with setobject flag and if commands and the result is again the same.

jaynabonne
The trick is to identify what the conditions are, and then you can both key off them to update the picture and know which state to check for changes to know *when* to update.

When you listed the pictures, it seems you have "suitcase on bed" as one condition (where the alternative is not). The other condition is less clear, since the picture has it missing. Do you knock it off the desk when you turn it off? Is it still in the room? The reason I'm asking is that if the clock disappears, then you can just check its parent to see if it's still there. Otherwise, you can just have a boolean attribute on the clock for "ringing" or not.

One way to handle the picture is to have "if"'s. The other is to encode the state into the name. (This is all just to show the pattern. You can use whatever names you like.)

if ( GetBoolean(suitcase, "onbed") ) {
s1 = "onbed"
} else {
s1 = "offbed"
}

if (GetBoolean(clock, "ringing")) {
s2 = "ringing"
} else {
s2 = "silent"
}

picturename = "picture_" + s1 + "_" + s2 + ".jpg"


Then you'd have four pictures:
picture_ringing_onbed.jpg
picture_ringing_offbed.jpg
picture_silent_onbed.jpg
picture_silent_offbed.jpg

Though, I'm not sure why you would have the "ringing/onbed" case if you can't move the suitcase onto the bed until you have shut off the clock...

As far as updating the picture when they change, you can use "changed" scripts to automatically update the picture when the state changes (e.g. a "changedonbed" script on suitcase and "changedringing" on the clock).

HegemonKhan
just an example of how to do multiple condition checks:

(obviously, your expressions' syntax will be different, depending on how you set up your conditions: as strings or booleans or etc)

if (color_1 = "red" and color_2 = "blue") {
color = "purple"
} else if (color_1 = "red" and color_2 = "yellow") {
color = "orange"
} else if (color_1 = "blue" and color_2 = "yellow") {
color = "green"
}


---------

I don't know if you're ready for this, but booleans quickly become too numerous...

it's much better to use Strings, or especially Stringlists, as you can change these, whereas you can't with booleans, for examples:

RPG Status Effects:

'unweildy' boolean usage:

player.poisoned = false
player.petrified = false
player.diseased = false
player.dead = false
player.asleep = false
player.stunned = false
player.confused = false
player.muted = false
player.blinded = false
player.crippled = false
player.cursed = false
player.paralyzed = false
player.silenced = false
etc etc etc

VS

if (player.status_effects_string = "poisoned") {
player.hp = player.hp - 50 // per turn, obviously this needs a lot more coding, so just pretend here as it's only an example
} else if (player.status_effects_string = "confused") {
// blah script
}

OR

player.status_effects_stringlist = NewStringList ()
list add (player.status_effects_stringlist, "poisoned")
list add (player.status_effects_stringlist, "confused")
list remove (player.status_effects_stringlist, "poisoned")
if (ListContains (player.status_effects_stringlist, "poisoned") {
player.hp = player.hp - 50 // per turn, obviously this needs a lot more coding, so just pretend here as it's only an example
}


an another example:

// this is just a full list of possible states of your character:
player.locomotion_stringlist = split ("walking;running;jumping;falling;floating;swimming;drowning;flying;bipedal;quadripedal;crawling;climbing;laying down;sitting;standing",";")

// hopefully this shows how useful strings and~or lists are, and then there's dictionaries too, hehe.

--------------

Jay wrote:if ( GetBoolean(suitcase, "onbed") ) {
s1 = "onbed"
} else {
s1 = "offbed"
}

if (GetBoolean(clock, "ringing")) {
s2 = "ringing"
} else {
s2 = "silent"
}

picturename = "picture_" + s1 + "_" + s2 + ".jpg"


I really need to get more accustomed to doing this more advanced coding concept with concatanating to determine what scripts or other stuff is done, as it's very powerful~useful

wow is this so cool, and you make it so simple to understand too, hehe:D
Thanks Jay !!! (I think I can implement this to make my time and date coding work, as I've been having problems with it, and I think this can solve my difficulties... hehe)

Mareus
jaynabonne wrote:The trick is to identify what the conditions are, and then you can both key off them to update the picture and know which state to check for changes to know *when* to update.

When you listed the pictures, it seems you have "suitcase on bed" as one condition (where the alternative is not). The other condition is less clear, since the picture has it missing. Do you knock it off the desk when you turn it off? Is it still in the room? The reason I'm asking is that if the clock disappears, then you can just check its parent to see if it's still there. Otherwise, you can just have a boolean attribute on the clock for "ringing" or not.

One way to handle the picture is to have "if"'s. The other is to encode the state into the name. (This is all just to show the pattern. You can use whatever names you like.)

if ( GetBoolean(suitcase, "onbed") ) {
s1 = "onbed"
} else {
s1 = "offbed"
}
if (GetBoolean(clock, "ringing")) {
s2 = "ringing"
} else {
s2 = "silent"
}

picturename = "picture_" + s1 + "_" + s2 + ".jpg"


Then you'd have four pictures:
picture_ringing_onbed.jpg
picture_ringing_offbed.jpg
picture_silent_onbed.jpg
picture_silent_offbed.jpg

Though, I'm not sure why you would have the "ringing/onbed" case if you can't move the suitcase onto the bed until you have shut off the clock...

As far as updating the picture when they change, you can use "changed" scripts to automatically update the picture when the state changes (e.g. a "changedonbed" script on suitcase and "changedringing" on the clock).

Well I read both of your comments and this is what I made so far:
if (GetBoolean(alarm clock, "taken")) {
ClearScreen
picture ("bedroom-cool-idea-of-dorm-room-nuanced-in-blue-and-white-even-wooden-furniture2.jpg")
msg ("You are standing in a small bedroom with glossy wooden floor and boring white walls. Despite its size the room is more than adequete for an aspiring student such as yourself and it offers everything you might need.<br/><br/>Not only do you have your own bed and your very own wooden desk with drawers both to the left and right, but there is also a sturdy old chair and a garbage bin next to it. The wardrobe on the opposite wall connects seamlessly with a nearby bookshelf and the room even has a big window which is decorated with beautiful red curtains and some flowers in a vase.<br/><br/>In short it really seems to be in mint condition, although it does suffer from that feminine touch that is so characteristic for your landlady.<br/>---")
}
else if (GetBoolean(alarm clock, "taken") and GetBoolean(suitcase, "moved")) {
ClearScreen
picture ("bedroom-cool-idea-of-dorm-room-nuanced-in-blue-and-white-even-wooden-furniture3.jpg")
msg ("You are standing in a small bedroom with glossy wooden floor and boring white walls. Despite its size the room is more than adequete for an aspiring student such as yourself and it offers everything you might need.<br/><br/>Not only do you have your own bed and your very own wooden desk with drawers both to the left and right, but there is also a sturdy old chair and a garbage bin next to it. The wardrobe on the opposite wall connects seamlessly with a nearby bookshelf and the room even has a big window which is decorated with beautiful red curtains and some flowers in a vase.<br/><br/>In short it really seems to be in mint condition, although it does suffer from that feminine touch that is so characteristic for your landlady.<br/>---")
}
else if (not GetBoolean(alarm clock, "taken") and GetBoolean(suitcase, "moved")) {
ClearScreen
picture ("bedroom-cool-idea-of-dorm-room-nuanced-in-blue-and-white-even-wooden-furniture4.jpg")
msg ("You are standing in a small bedroom with glossy wooden floor and boring white walls. Despite its size the room is more than adequete for an aspiring student such as yourself and it offers everything you might need.<br/><br/>Not only do you have your own bed and your very own wooden desk with drawers both to the left and right, but there is also a sturdy old chair and a garbage bin next to it. The wardrobe on the opposite wall connects seamlessly with a nearby bookshelf and the room even has a big window which is decorated with beautiful red curtains and some flowers in a vase.<br/><br/>In short it really seems to be in mint condition, although it does suffer from that feminine touch that is so characteristic for your landlady.<br/>---")
}
else if (IsSwitchedOn(ringing alarm clock)) {
msg ("You wake up to the sound of an alarm clock which keeps ringing annoyingly every half a minute! The sound it is making is intolerable, but at least you are awake for your first day at school.<br/>---")
play sound ("Old Alarm Clock Sound - Ringing - Made in Germany 1920's - 30's..mp3", false, true)
}
else if (not GetBoolean(suitcase, "moved") and not IsSwitchedOn(ringing alarm clock) and not GetBoolean(alarm clock, "taken")) {
ClearScreen
picture ("bedroom-cool-idea-of-dorm-room-nuanced-in-blue-and-white-even-wooden-furniture.jpg")
msg ("You are standing in a small bedroom with glossy wooden floor and boring white walls. Despite its size the room is more than adequete for an aspiring student such as yourself and it offers everything you might need.<br/><br/>Not only do you have your own bed and your very own wooden desk with drawers both to the left and right, but there is also a sturdy old chair and a garbage bin next to it. The wardrobe on the opposite wall connects seamlessly with a nearby bookshelf and the room even has a big window which is decorated with beautiful red curtains and some flowers in a vase.<br/><br/>In short it really seems to be in mint condition, although it does suffer from that feminine touch that is so characteristic for your landlady.<br/>---")
}

Unfortunately when I turn off the clock and I finally get to the point when the game opens, I keep getting the wrong picture and I don't understand why.

Mareus
Mareus wrote:

"jaynabonne"

The trick is to identify what the conditions are, and then you can both key off them to update the picture and know which state to check for changes to know *when* to update.

When you listed the pictures, it seems you have "suitcase on bed" as one condition (where the alternative is not). The other condition is less clear, since the picture has it missing. Do you knock it off the desk when you turn it off? Is it still in the room? The reason I'm asking is that if the clock disappears, then you can just check its parent to see if it's still there. Otherwise, you can just have a boolean attribute on the clock for "ringing" or not.

One way to handle the picture is to have "if"'s. The other is to encode the state into the name. (This is all just to show the pattern. You can use whatever names you like.)

if ( GetBoolean(suitcase, "onbed") ) {
s1 = "onbed"
} else {
s1 = "offbed"
}
if (GetBoolean(clock, "ringing")) {
s2 = "ringing"
} else {
s2 = "silent"
}

picturename = "picture_" + s1 + "_" + s2 + ".jpg"


Then you'd have four pictures:
picture_ringing_onbed.jpg
picture_ringing_offbed.jpg
picture_silent_onbed.jpg
picture_silent_offbed.jpg

Though, I'm not sure why you would have the "ringing/onbed" case if you can't move the suitcase onto the bed until you have shut off the clock...

As far as updating the picture when they change, you can use "changed" scripts to automatically update the picture when the state changes (e.g. a "changedonbed" script on suitcase and "changedringing" on the clock).

Well I read both of your comments and this is what I made so far:
if (GetBoolean(alarm clock, "taken")) {
ClearScreen
picture ("bedroom-cool-idea-of-dorm-room-nuanced-in-blue-and-white-even-wooden-furniture2.jpg")
msg ("You are standing in a small bedroom with glossy wooden floor and boring white walls. Despite its size the room is more than adequete for an aspiring student such as yourself and it offers everything you might need.<br/><br/>Not only do you have your own bed and your very own wooden desk with drawers both to the left and right, but there is also a sturdy old chair and a garbage bin next to it. The wardrobe on the opposite wall connects seamlessly with a nearby bookshelf and the room even has a big window which is decorated with beautiful red curtains and some flowers in a vase.<br/><br/>In short it really seems to be in mint condition, although it does suffer from that feminine touch that is so characteristic for your landlady.<br/>---")
}
else if (GetBoolean(alarm clock, "taken") and GetBoolean(suitcase, "moved")) {
ClearScreen
picture ("bedroom-cool-idea-of-dorm-room-nuanced-in-blue-and-white-even-wooden-furniture3.jpg")
msg ("You are standing in a small bedroom with glossy wooden floor and boring white walls. Despite its size the room is more than adequete for an aspiring student such as yourself and it offers everything you might need.<br/><br/>Not only do you have your own bed and your very own wooden desk with drawers both to the left and right, but there is also a sturdy old chair and a garbage bin next to it. The wardrobe on the opposite wall connects seamlessly with a nearby bookshelf and the room even has a big window which is decorated with beautiful red curtains and some flowers in a vase.<br/><br/>In short it really seems to be in mint condition, although it does suffer from that feminine touch that is so characteristic for your landlady.<br/>---")
}
else if (not GetBoolean(alarm clock, "taken") and GetBoolean(suitcase, "moved")) {
ClearScreen
picture ("bedroom-cool-idea-of-dorm-room-nuanced-in-blue-and-white-even-wooden-furniture4.jpg")
msg ("You are standing in a small bedroom with glossy wooden floor and boring white walls. Despite its size the room is more than adequete for an aspiring student such as yourself and it offers everything you might need.<br/><br/>Not only do you have your own bed and your very own wooden desk with drawers both to the left and right, but there is also a sturdy old chair and a garbage bin next to it. The wardrobe on the opposite wall connects seamlessly with a nearby bookshelf and the room even has a big window which is decorated with beautiful red curtains and some flowers in a vase.<br/><br/>In short it really seems to be in mint condition, although it does suffer from that feminine touch that is so characteristic for your landlady.<br/>---")
}
else if (IsSwitchedOn(ringing alarm clock)) {
msg ("You wake up to the sound of an alarm clock which keeps ringing annoyingly every half a minute! The sound it is making is intolerable, but at least you are awake for your first day at school.<br/>---")
play sound ("Old Alarm Clock Sound - Ringing - Made in Germany 1920's - 30's..mp3", false, true)
}
else if (not GetBoolean(suitcase, "moved") and not IsSwitchedOn(ringing alarm clock) and not GetBoolean(alarm clock, "taken")) {
ClearScreen
picture ("bedroom-cool-idea-of-dorm-room-nuanced-in-blue-and-white-even-wooden-furniture.jpg")
msg ("You are standing in a small bedroom with glossy wooden floor and boring white walls. Despite its size the room is more than adequete for an aspiring student such as yourself and it offers everything you might need.<br/><br/>Not only do you have your own bed and your very own wooden desk with drawers both to the left and right, but there is also a sturdy old chair and a garbage bin next to it. The wardrobe on the opposite wall connects seamlessly with a nearby bookshelf and the room even has a big window which is decorated with beautiful red curtains and some flowers in a vase.<br/><br/>In short it really seems to be in mint condition, although it does suffer from that feminine touch that is so characteristic for your landlady.<br/>---")
}

Unfortunately when I turn off the clock and I finally get to the point when the game opens, I keep getting the wrong picture and I don't understand why.


Ok, after many hours of hard and frustrating work, I think I finally managed to fix it. Although I have no clear idea why it seems to works now. Basically I renamed my descriptions into A, B, C,etc.. just so I could see easier what conditions are being met. Then with a bit of trial and error I fixed the problem. Obviously, not an ideal way to go about making an adventure game, but hey... its. Still I would like to know what exactly I did wrong. Maybe I am just tired and I cant see it at this particular moment. I don't know...

PS. I am also wondering if there is a way to just replace the picture without having to clear the whole screen and then adding a new one. I tried using clear picture frame, but then I get one picture under another and I have to scroll a lot to get back to text.

jaynabonne
I'm glad it's working for you. Just a small note about the code you posted. Perhaps it will help:

if (GetBoolean(alarm clock, "taken")) {
// Some code
}
else if (GetBoolean(alarm clock, "taken") and GetBoolean(suitcase, "moved")) {
// Some other code
}


If the alarm clock is taken, then it will always go down the first branch. It will never get to the second. You could solve it by reversing the blocks (so the more specific check happens first). You could also break it down like this:

if (GetBoolean(alarm clock, "taken")) {
// taken case
if (GetBoolean(suitcase, "moved")) {
// taken and moved case
} else {
// taken and not moved case
}
} else {
// not taken case
if (GetBoolean(suitcase, "moved")) {
// not taken and moved case
} else {
// not taken and not moved case
}
}

Mareus
jaynabonne wrote:I'm glad it's working for you. Just a small note about the code you posted. Perhaps it will help:

if (GetBoolean(alarm clock, "taken")) {
// Some code
}
else if (GetBoolean(alarm clock, "taken") and GetBoolean(suitcase, "moved")) {
// Some other code
}


If the alarm clock is taken, then it will always go down the first branch. It will never get to the second. You could solve it by reversing the blocks (so the more specific check happens first). You could also break it down like this:

if (GetBoolean(alarm clock, "taken")) {
// taken case
if (GetBoolean(suitcase, "moved")) {
// taken and moved case
} else {
// taken and not moved case
}
} else {
// not taken case
if (GetBoolean(suitcase, "moved")) {
// not taken and moved case
} else {
// not taken and not moved case
}
}

Oh! So the trick is to have the more specific check happening first. If I understood you correctly, that means I would always have to start with an "if" command that has the most checks, and then slowly narrow it down to only one check? That kind of explains what was the problem, because I did it other way around and then the command would not even get to the more specific ones.

But you still havent answered my question about pictures above.

Anyway, thanks a lot Jay. That was the piece of the puzzle I was missing. With this new knowledge, I think I can avoid similar problems in the future.

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

Support

Forums