Simple question.

kabahaly
25 Aug 2013, 21:20
Alright, I'm making a text adventure game, and I have a question.. So, there's this water carton that I set as a container, already opened and can't be closed or opened, then there's this cup. If you try to drink the cup without pouring it with water from the carton, it will not work. Now here comes the question, how do I fill the cup with water, and if it was poured, you will drink and finish the game, if it's not, you will have to pour it?

jaynabonne
26 Aug 2013, 17:06
I can think of two ways (at least) to do it:

1) Make the cup a container as well and have a "water" object which is initially inside the carton. Then when the player types "pour water" or whatever command you wish, move the water object from the carton to the cup. That means you can only fill the cup once, as the entirety of the water will move to the cup and it won't be in the carton afterwards. Your end game condition would check that the water's parent is the cup.

2) Have a flag attribute on the cup which indicates whether it's filled or not. Then when the player does the right command, you simply set the flag to true (the cup is filled) and print some appropriate message. Then your end game would check whether the flag is set.