How to use flags and attributes in this way?

Floating_Turtles
28 Mar 2021, 01:54

I'm starting a new game and I'm trying to learn how to change an outcome depending on what the player chose.

(I'm making a gamebook by the way!)

The player has to choose between a few options and I'm not sure how to mark which answers as 'right' or how to make the game tally it at the end.

Example:
Round 1
Dogs
Cats (right answer)
Monkey

Round 2
Panda
Lion
Giraffe (right answer)

Round 3
Human
Dinosaur
Eagle (right answer)

Only if the player chooses all of those right answers (3/3) they can continue, if not they'll get game over. (2/3 or 1/3)

Is that possible? Ty!


mrangel
28 Mar 2021, 11:04

I'm assuming you've got asking the question and allowing the player to choose an answer already. So it's just a case of using an attribute.

In this case, there's no object that the attribute seems to be associated with, so it's probably best to use game.

So before the first question (maybe in the script that displays the question), you create the attribute:

game.rightanswers = 0

Setting it to zero means that it's stored as an int (number), so you will be able to do arithmetic on it.

Then when the player gives a right answer, you increase it by 1:

game.rightanswers = game.rightanswers + 1

This is setting the attribute's value to its previous value plus 1.

Then at the end, you check if they got enough points:

if (game.rightanswers = 3) {
  msg ("Congratulations, 3 out of 3!")
  // any script to continue or move the player to the next location will go here
}
else {
  msg ("Sorry, you only got {game.rightanswers} out of 3 correct. You lose!")
  finish
}

(In text adventure mode, finish causes a game over and prevents the player entering more commands. If it's a gamebook you'd miss that line out and just don't give the player any options to carry on)

If you're more familiar with the script GUI, you can go into code view just long enough to paste the commands, and then switch back. Code view makes it a lot easier to share code on the forums.

Hope that helps. If there's anything I missed, please let me know.


Floating_Turtles
28 Mar 2021, 15:44

It works perfectly! Thank you !


hypnos97
29 Mar 2021, 09:10

Tks
It works perfectly