Working with tables

I want to have a table 0 human 1 vampire and have it ask you which you want to be when game begins. I am just getting started so i have no clue

Have you read Chapter 16 in the Inform documentation about tables?

That will definitely help you get started. I’m not sure exactly why you want a table for this, though. You can ask the player what character they want to be without a table. Is it that you want it keep some kind of score?

A little more information about what you want to do would help us help you.

2 Likes

thank you, I’ll read that. Sorry to confuse you but just learning.

2 Likes

We’ve all been there! When you feel like you can describe what you want a little better, ask again. I still struggle with tables even after reading that chapter multiple times, so don’t feel bad about it if you still have a lot of questions.

1 Like

Just echoing Amanda to agree that tables can be a bit tricky, and from what you’ve described might not be needed in this situation – you can give the player a property that makes whether they’re human, a vampire, or whatever, which is much simpler. Here’s a bit of the docs that might be helpful.

2 Likes

Everyone learns. All the time. My little experiment this evening, trying to answer your question. Not perfect, but I learned too. I hope you’ll be able to pick up one or two good ideas here and there (and avoid the bad ones).

"Playground4" by Monsieur HUT

Lab is a room.
Incubator is a room."[line break]You are in the great character generator.".
Incubator is east of Lab.

Biotype is a kind of value.
Biotypes are Human, Vampire, Werewolf and IF-writer.
A person has a biotype.

Table of Biotypes
ID (text)  	Specie (Biotype)
"1"	Human
"2"	Vampire
"3"	Werewolf
"4"	IF-writer

After going to Incubator:
	try looking;
	launch the character choice;
	
To decide whether collecting choice of the biotype:
	if (the command prompt is "Choose wisely (1-4) >"), yes;
	no.
	
To launch the character choice:
	let LocalTable be the Table of Biotypes;
	let N be the number of rows in LocalTable;
	repeat with LocalOption running from 1 to N:
		choose row LocalOption in LocalTable;
		say "[ID entry] - [Specie entry][line break]";
	now the command prompt is "Choose wisely (1-4) >";

After reading a command when collecting choice of the biotype:
	let LocalTable be the Table of Biotypes;	
	if (the player's command matches the regular expression "^\d+$"):
		let LocalChoice be the player's command;
		if (a row with ID "[LocalChoice]" exists in LocalTable):
			choose row with ID of "[LocalChoice]" in LocalTable;
			now the biotype of the player is the Specie entry;
			try going west;
			now the command prompt is "You are a [biotype of the player] now >";
			reject the player's command;
		otherwise:
			reject the player's command;
	otherwise:
		reject the player's command;
				
To decide if a row with ID (ID - a text) exists in (T - a table name):
	repeat through T:
		if (the ID entry is ID), decide yes;
	decide no.

EDIT : removal of an useless statement.

3 Likes

thank you