Mixing a cocktail - need help with transformation logic

The player needs to make a cocktail, there is a glass and there are three ingredients they must put in the glass to create the cocktail.

I have made the glass a transparent container so you can see it contains each of the ingredients as they are added, but I want to transform the glass of items into a cocktail drink when all three ingredients have been added - the problem is they can be added in any order and you can remove them so I don't know how to set the logic, answer is probably object flags but I'm stumped!

Using online editor btw. Thanks!


I'm not sure how this works on the online version but here is how I do it with download version.

You need to set an integer attribute on the glass (or other object) and add 1 each time a correct ingredient is added.

Set Glass.IngredientCount to Glass.IngredientCount + 1

Add a changedIngredientCount as well and run an If script. If IngredientCount = 1 then print "blah"
Else If IngredientCount = 2, then print "blah".
Else If IngredientCount = 3, then make "finished glass" visible and remove glass.

You would have to subtract one from Glass.IngredientCount if you remove an Ingredient.

I know this will work as I've used it a bunch but I'm not sure if my syntax is correct. I'll check and give a better answer when I get home! Hopefully this will get you started.


Ah, OK that makes sense, I'll give it a go. Thank you!


Immediate problem is that I can't see where on the Object attributes to add the integer/script?


I think, using logic here, you should remove the "remove item" option on the glass.
(Ever tried removing salt from a drink?)
But you could have an option to discard the glass, empty it, and start over....
But if you have a limit of ingredients to start with, it would limit the players chances if he
uses trial and error...
(just a thought)
But you may need a "drink mix book" somewhere...


I don't see a 'remove item' option to change?


Oh boy. I'll look at the online version when I get home. Not sure what needs to be done there. I'll post in a couple hours.


Thanks, really appreciate it.


This will depend on how you have it set up. If there is only one instance of each ingredient in the world, then an integer is good. Otherwise, you would need a flag for each ingredient if you wanted to prevent the player adding the same ingredient twice, or an integer for each ingredient, if you want to let the player create any mixture.

The way to add attributes is in the start script on the game object. Eg:

drink.ingredient1count = 0

only one of each ingredient so that logic works, but I don't know how to increase the integer when item is placed inside container/glass? I could create a logic IF tree using 'object contains', but only if I can change the remove item on the glass container?

Thanks.


Sounds like a job for change scripts. As you are on the web version, you will need to set this up on the game start script. A change script fires when an attribute changes, and in this case we want that when the parent attribute of each ingredient changes. Say the first is called ingredient1, this code will give is a change script that will call a function, CocktailTest, whenever it is moved. You need to do that for each ingredient.

ingredient1.changedparent => {
  CocktailTest
}

Then create the function, CocktailTest. If has to add one to the running total (creating a running total if it does not exist yet), and not when it reaches 3.

if (not HasInt(glass, "count")) {
  glass.count = 0
}
glass.count = glass.count + 1
if (glass.count = 3) {
  msg("You made that cocktail.")
}

By the way, never do this for the player. It already has a change script for the parent attribute; if you add yours it will mess up big time.


Awesome! Thanks for this, will try it tomorrow with a clean head.


"No remove item"... that I did not know, it was just mentioned in the previous post...


Sorry... that was meant to be "Remove object" under the object tab. =/

I suggested removing the original glass object when the mix was complete as to eliminate any possible mistakes/conflicts with the finished product. After removing the old glass, the new glass takes on all new attributes so no more messing with the old stuff.

Looks like TP has given you good advice! I would suggest, however, to try to use the download version if possible. So much more versatile and reliable! =)

Best of luck!


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

Support

Forums