Ending The Game - Tables

I am trying to work out how best to structure the code to end the game.

What I have are different coloured tokens in various rooms and i would the game to end when the player has collected a certain number of them (not all of them).

I tried creating a table called Key Items and listed all the different coloured tokens in the table. It currently looks like this:

Table 101 - Key Items
Item	
"Yellow Crayon"
"Green Crayon"	
"Blue Crayon"	
"Red Crayon"	
"Purple Crayon"	
"Orange Crayon"	
"Brown Crayon"	
"White Crayon"	
"Grey Crayon"

I am lost from here though…the documentation wasn’t clear on how I point to a certain number of them. Any help would be appreciated.

Thanks

At the moment, your table is storing texts. A piece of text that says “Yellow Crayon”, then one that says “Green Crayon”, etc. These have no built-in connection to any crayon objects of the same name you’ve made in your game.

But let’s step back. You want the game to end when a person has collected a certain number of tokens (are they all crayons?). You won’t need a table unless you want to do something more complex with the tokens.

I’ve made a demo that creates a kind of thing called a token. Every turn a rule runs checking how many tokens the player has on them. If the number equals the winning score (a variable number set in the code), the game ends and says they won.

There are four rooms and four tokens, but you only need three to win.

Summary
"Tokens"

a token is a kind of thing.

lab is a room. "You can go east.".
lounge is east of lab. "You can go west or east.".
kitchen is east of lounge. "You can go west or east.".
hall is east of kitchen. "You can go west.".

a yellow crayon is a token. It is in the lab.
a green crayon is a token. It is in the lounge.
a blue crayon is a token. It is in the kitchen.
a red crayon is a token. It is in the hall.

the winning score is initially 3.

Every turn:
	let SCORE be the number of tokens enclosed by the player;
	if SCORE is the winning score:
		end the story saying "You found [SCORE] tokens! You win!";

Test me with "get crayon/e/e/get crayon/e/get crayon".
  • Wade
4 Likes

You can also make it an adjective, if you want.

A thing can be crucial. A thing is usually not crucial.
The endgame is a scene.
The endgame begins when the player carries every crucial thing.
3 Likes

Apologies…I should have been clearer.

I already have these items as objects in my game. they are scattered over the map and I am trying to set ip up so that when the player has gathered around half of them it’s enough to trigger the end of the game.

That scoring system you sent me looks interesting though, I’ll check that out now.

Thanks

ps Yes I think this token system could work. Thank you

This sounds like exactly what I need. Thank you

ps oh wait…no I don’t want them to need every item on the list…

…when the player carries at least five crucial things
2 Likes

Yes, I realised after @Draconis said ‘at least five’ in his example, that my code should also use ‘at least’ for safety (I had never used it before, but I’ve learned something!) in case there’s a way to collect multiple tokens at once. Because the player’s tally could go past the winning score in a single move, and my victory condition would not go off.

So if using my code, I would change that one line to

if SCORE is at least the winning score:

-Wade

1 Like