IF everything is eaten THEN proceed with game

djbriandamage
12 Mar 2013, 14:05
I'm writing a game using the web-based tools. I have a scene in a restaurant where the player must eat appetizers before the main course is brought.

I tried making this test script:

If object does not contain parent: object inside the restaurant Does not contain child: object beef print message BEEF GONE

Where "inside the restaurant" is a room and "beef" is an object inside the room. This test should evaluate whether beef exists. I would like to make a script with 4 if statements, each testing whether one of the 4 appetizers has been eaten, and if none exist then trigger the next scene.

Does anyone have any advice for me on how to accomplish this?

Also, am I limiting myself by using the web-based tools instead of the downloadable fat client?

Thanks much!

Asyranok
12 Mar 2013, 14:17
I would recommend that you copy and paste the four if statements at the end of the script for eating each item. That way the game checks if all items have been eaten after each dish and moves you along naturally.

TriangleGames
12 Mar 2013, 14:25
There are still a one or two features in the download version of Quest that are not in the web version (yet), such as an attributes tab on objects and a full code view of the entire game at once. Script specific code views were actually just added recently.

As for the IF statements, you can nest IF's, but I believe full boolean expressions with AND and OR are supported for them now in v5.4. So, you should be able to use a single IF statement that check's for all the appetizers at once, something like this

IF: restraunt does not contain appetizer1 OR appetizer2 OR appetizer3 OR appetizer4
__THEN: print (msg) "All appetizers are gone."

I have not used AND or OR yet myself, but they should be supported. You might want to test that out before deleting any IF's you already have working, just to make sure.

EDIT: Just to be clear, to use boolean modifiers you'd want to set the main IF "condition" to expression and write out the whole thing.

levicki
12 Mar 2013, 14:55
Basically, you should have something like this

if (beef.parent <> table) { // restaurant, table, plate, depending on where the beef is located
// todo: beef is gone, proceed with wine
if (wine.parent <> table) {
// todo: wine is gone, proceed with event
}
else {
// wine is still there
}
}
else {
// beef is still there
}


By the way, "fat" client is not that fat. I think it is more comfortable to work in it, not to mention that you can see all the Quest libraries and analyze their code in case you get stuck with something.

jaynabonne
12 Mar 2013, 17:38

IF: restraunt does not contain appetizer1 OR appetizer2 OR appetizer3 OR appetizer4
__THEN: print (msg) "All appetizers are gone."



I would be surprised if that works. AND and OR combine expressions. So you'd need:

IF: restraunt does not contain appetizer1 AND restraunt does not contain appetizer2 AND restraunt does not contain appetizer3 AND restraunt does not contain appetizer4
__THEN: print (msg) "All appetizers are gone."


I'm not saying that's the best way to do it, but that's the syntax for that approach (roughly), as far as I know.

jaynabonne
12 Mar 2013, 17:42
Beyond the above for the test itself, the question comes in: where do you put this code? If you have four appetizers, it would be a pain to have to put the code in four different places (one for where each place is eaten). You could create a common function that all those places call to handle the case.

Alternatively, you could create a temporary turn script which would make the check for you after each turn (e.g. while in the restaurant). That way it's a bit more automatic and will happen whenever the condition comes true, without you having to put the code in all those specific places.

Hope that helps a little. :)

djbriandamage
13 Mar 2013, 12:55
I was also thinking I could declare an "appetizers.eaten" variable and increment it every time one is eaten, and then have a condition "if appetizers.eaten = 4 then proceed" kind of thing, but levicki's idea is very similar.

Jaynabonne's idea is interesting as well, about a temporary turn script. Is there such a thing? Using my idea of a variable maybe I need to do something like "if appetizers.eaten = 4 then proceed and appetizers.eaten = 100" to keep the condition from being true in subsequent turns.

I'll see if I can use custom script using the web UI, otherwise I'll play around with these concepts. Thanks guys! I'll update if I have more questions. I really appreciate the quick, creative responses.

jaynabonne
13 Mar 2013, 13:03
I suppose by "temporary" I just meant one that is only active in the context of the restaurant. You can easily define a turnscript and then enable/disable it as needed (e.g. enable on room enter and disable on room exit or when the condition is true).

Your idea about a count works well, too. I've done something similar (though I couched it under the guise of "level of confidence").

djbriandamage
13 Mar 2013, 13:56
My issue is that the restaurant is the last room of my game so the turn script will have to run until the game ends. I'll fiddle around and try to stave off false positives.

jaynabonne
13 Mar 2013, 14:10
What I meant was (to paraphrase and combine):

"if appetizers.eaten = 4 then disable turn script so it no longer runs and then proceed" :)

HegemonKhan
13 Mar 2013, 19:32
this is an interesting discussion! would there be any way to code in an "all" coding?

err, this method is the same as dj already mentioned, oops. Of course the other mentions of enabling~disabling and~or using the turnscripts, applies as well.

// the variables or attributes need to be made global of course if they need to be made so, lol

<eat type="script">
this_or_object_name.eatened = true
</eat>

// for whatever room (or container object), create an objectlist of the items in that room (or whatever) or if player inventory, then use ScopeInventory ()

<function name="obj_eatened_total_function">
foreach (obj,objectlist) {
if (obj.eatened = true) {
obj_eatened_total = obj_eatened_total + 1
}
}
</function>

<script>
if (obj_eatened_total = 5) {
some_script
}
</script>

// OR, you could just add in the total counter to eat verb, lol

<eat type="script">
this_or_object_name.eatened = true
obj_eatened_total = obj_eatened_total + 1
</eat>

// as then you wouldn't need the: "obj_eatened_total_function"


djbriandamage
18 Mar 2013, 18:51
I got this working with an ugly hack!! Yay! It's only acceptable because the player doesn't need to use the inventory in my game.

I set each of the 4 appetizers to "cannot be eaten" and created a custom "eat" verb. The verb puts the appetizer in the player's inventory. My burgertime turn script checks whether each item is in the player's inventory (with a series of nested if statements) and if yes then remove appetizers and make the main course visible and print a message.

Just one more bug to squash and my game will be playable!

Thanks for your help, all. I think my next game will use the local client so that I have more freedom to customize the code.

if (Got(beef)) {
if (Got(bun)) {
if (Got(cheese)) {
if (Got(lettuce)) {
MakeObjectVisible (hamburger)
msg ("hamburger revealed!")
RemoveObject (beef)
RemoveObject (bun)
RemoveObject (lettuce)
RemoveObject (cheese)
}
}
}
}


Got beef? :D