How to make choices influence the ending
Floating_Turtles
11 Feb 2021, 13:01The game I want to create has several choices!
For example 12 choices pushing towards a bad, neutral, or good ending.
How do I make the game calculate what ending the player got, based on their choices, on it's own?
mrangel
11 Feb 2021, 13:42You'll want to record which choices the player took, and use those to decide on the ending.
One option would be to set a flag for each of the choices, and then check for combinations of those flags to decide what ending to show.
Another option would be keeping some kind of bad/good counter; when the player makes a choice, it increases or decreases the counter, and then at the end the game uses the value of the counter to choose an ending.
Which method works best will depend on your game. And there are plenty of other choices.
If you want more advice on how to implement this system, you should first decide what you want the system to do and how it should make the decision.
Floating_Turtles
11 Feb 2021, 15:52Thank you, I'd like to do the first option with the flags. How would I go about implementing that?
jmnevil54
11 Feb 2021, 17:13I would use attributes. It's just numbers.
If (game.ending = 12) {
}
But using Booleans would be like this...
If (game.12 = true) {
}
If (game. 11 = true) {
}
I haven't used flags since I worked with Scratch and I don't plan on using flags ever again.
Floating_Turtles
12 Feb 2021, 01:26Thanks for the option! Once I try it out, I'll report any changes I see.
Floating_Turtles
14 Feb 2021, 20:28Now that I've begun working on the game, how would I go about using either the flag or attribute systems to influence the ending? (I'm a beginner so I'm grateful to any long explanations! :)
jmnevil54
15 Feb 2021, 00:59You need to set the flag before you use any if statements.
This is how you set a flag.
SetObjectFlagOn (player, "Flag1")
Then you need to use an if statement to do what you want or get the ending you want.
This is how you use an if statement.
if (GetBoolean(player, "Flag1")) {
msg ("Hello world!")
}
Floating_Turtles
15 Feb 2021, 11:43Thank you !! I think I'll experiment with it for a few days! If I need any help I'll start it under a more specific topic :D
mrangel
15 Feb 2021, 13:49Endings on a scale
One common way to do multiple endings is to use a single scale. If there's a number of choices in the game, and each one has a "right answer", then you can keep a count of how many right answers the player gave.
For example, at the start of the game you could give the game a right_choices
attribute. Either creating the attribute on the attributes tab (assuming you're using the desktop version – the online editor can't do this method) and making sure that its type is 'int', or creating it in the start script like this:
game.right_choices = 0
Then each time the player makes a right choice, you would have something like:
game.right_choices = game.right_choices + 1
and at the end of the game, you'd have something like:
if (game.right_choices >= 12) {
insert code for the good ending (12+ right choices) here
}
else if (game.right_choices >= 4) {
insert code for the neutral ending (4+ right choices) here
}
else {
insert code for the bad ending (less than 4 right choices) here
}
A similar system is used by games where you might have 'good', 'neutral', and 'evil' choices that influence the ending. In this case, you could add to the number for good choices and subtract from it for evil ones. In this case, the neutral ending would probably be for scores between -6 and 6 or similar.
You could also fine tune this system by having some decisions add more than one point onto the attribute, so they have more effect on which ending the player gets.
More granular ending options (using flags)
If your choices aren't just a straight scale, you might want to set flags instead, to keep track of which choices the player made.
For example, if one of the choices is whether or not you give a flower to an NPC, then in the 'give object' script you might have something like:
msg ("She takes the flower and thanks you")
RemoveObject (flower)
game.gave_jane_flower = true
You could alternatively put the flag on the npc:
jane.given_flower = true
or on the flower:flower.given_to_jane = true
Or you could choose to use the function SetObjectFlagOn, which does exactly the same thing but slightly less efficiently:SetObjectFlagOn (game, "gave_jane_flower")
- or
SetObjectFlagOn (jane, "given_flower")
(these functions do exactly the same as the lines above; they just look slightly prettier in the script GUI)
It doesn't matter which object you put the flag on, just so long as you use the same object everywhere you refer to it. And then at the end of the game, you'd choose an ending based on which choices have been made. For example:
if (GetBoolean (game, "gave_jane_flower") and GetBoolean (game, "fixed_roof") and not GetBoolean (game, "stole_weasels")) {
first ending goes here
}
else if (GetBoolean (game, "gave_jane_hammer") and (GetBoolean (game, "fixed_roof") or GetBoolean (game, "painted_spare_room"))) {
here's another ending, chosen by a different selection of choices
if (GetBoolean (game, "helped_danny")) {
doing it like this, you have the option to include optional parts of the endings based on which combination of options the player chose
msg ("And Danny will always be grateful for the help you gave him.")
}
}
else if (GetBoolean (game, "crashed_car") or GetBoolean (game, "stole_fish")) {
this one is probably a bad ending
}
else {
and finally we have a default ending, for if the player doesn't meet the criteria for any of the others
}
Hope that makes sense :)
It's worth noting that if you use the individual flags, you can replace GetBoolean (game, "name_of_flag")
with just game.name_of_flag
, which makes your code shorter. But if you do this, you will need to make sure to set the flag to false
if the player doesn't take that choice. It depends on the game whether it's simpler just to use GetBoolean
.
(GetBoolean basically asks "is this true" – it treats an undefined attribute (or an attribute with any value other than true
) as being `false)
Hope that makes sense and I'm not rambling too much.
Floating_Turtles
16 Feb 2021, 11:44TYSM! This is so helpful! I can really get started on it now