I'm currently building a choose your own adventure game. Now it's easy enough to have one outcome to every choice and create a linear flow, but is there a good algorithm for having all previous selections affect the next outcome? I could obviously store every previous selection and have big 'IF' statements to decide but I wondered if there was a better way?
Part of me wonders if every choice should have a 'score' and then I use this (maybe with a threshold) to determine what the next action should be and each action gets added to the score.
I'm primiarly doing this in swift/SpriteKit but I think it's more about the concept then the code at this point.
In response to Josh's comment below:
I suppose I'm still in the conceptual phase at the moment, but each 'page' would either be a custom object or a json file. I was thinking about your answer (now removed) and maybe having each ENUM option as a bit. Then each page could have a 'score'. Then using the previous options selected work out what bits are set and that determines what page. I guess I just wondered if there was an existing solution to this problem before I began to almost help decide how I should format the 'story'
Rough guess at format :
{ "text":"You arrive in the dungeon and there are 2 doors",
"options":[
1: "Go left",
2: "Go Right"
],
"score" : 0 // first page
}
{"text" "You went left and meet a dragon",
"options":[
0: "Game over, you were eaten" // something to handle game over
],
"score" : 1
}
{"text" "You meet a mushroom who tells you the princess is in another castle",
"options":[
4: "Give up, game over", // something to handle game over
8: "Jump down the pipe"
],
"score" : 2
}
Thanks
if
's,else
's,switch
's andcase
's hoping you will be finished before losing your sanity. \$\endgroup\$