Help with Syntax for Actions and Tables

To add some colour to a common game mechanic, I am creating dice which change their physical appearances depending on their roll. This will be made clear to the player early on, and the objects will still behave like dice. However, the various configurations of this idea I’ve tried just don’t seem to take in one way or another.

My notion is to have Inform check a table when the player rolls a die, or something which a die becomes. It will check the table against the result of the player’s throw, where it will select a random row with a result column that matches the result on the die, and swap itself in the player’s inventory with whatever the thing listed in the object column of that row is.

I would greatly appreciate any suggestions on how I might get this to happen, especially if this is not a good way of going about it. The recipe book lists plenty of examples on how to get objects to apparently transform, but if there were ones on how to make a decision like this, I must have missed them.

Hope everyone is well.

Are there a limited number of dice in this game (for example, the player only has one die, and never gains more)? Or are you expecting to have several dozen dice in the world?

I’m thinking of multiple dice, they’re part of their own puzzle system. They all behave in essentially the same way, though, in regards to transforming.

Every die has a table of variations, with a result column and an object column. The object will be a real thing in the world.

I’m fairly sure about how to set up the relationship between dice and their forms, I’m just struggling with how to get Inform to do something with the relationship between the result of a roll, and the thing specified as the outcome.

I gave a shot at coding an example for this. Your mileage may vary :slightly_smiling_face:

The code defines a morphing die as a thing with several properties as well as a table that contains an enumeration of the possible die property combinations desired within the game. Rolling the die results in a roll of the current die and after completing the roll the die randomly switches to a new type of die based on the data specified in the die property table. I hope it can be helpful!

A morphing_die is a kind of thing.
A morphing_die has a number called die_type.
A morphing_die has a number called die_sides.
A morphing_die has text called die_description.
A morphing_die has text called die_color.
Understand the die_color property as describing a morphing_die.
Understand the die_description property as describing a morphing_die.
Understand the die_sides property as describing a morphing_die.
The die_type of a morphing_die is usually 2.
The die_sides of a morphing_die is usually 6.
The die_description of a morphing_die is usually "6 SIDED DIE".
The die_color of a morphing_die is usually "orange".

Rule for printing the name of a morphing_die (called Md) while taking inventory: 
	say "[die_color of Md] [printed name of Md] with a total of [die_sides of Md] faces";
	stop the action;
	
Table 1 - Die Definitions 
die_type	die_sides	die_description	die_color
1	2	"2 SIDED DIE"	"silver"
2	4	"4 SIDED DIE"	"black"
3	6	"6 SIDED DIE"	"orange"
4	8	"8 SIDED DIE"	"green"
5	10	"10 SIDED DIE"	"red"
6	12	"12 SIDED DIE"	"yellow"
7	20	"20 SIDED DIE"	"purple"

Morphing_Die_Rolling is an action applying to one thing.
Understand "roll [morphing_die]" as Morphing_Die_Rolling.
Instead of Morphing_Die_Rolling:
	Let Rd be the noun;
	Let Fd be the die_sides of Rd;
	Let Vd be a random number from 0 to Fd;
	Let new_die_type be a random number from 1 to 7;
	Let new_die_sides be die_sides in row new_die_type of Table 1;
	Let new_die_description be die_description in row new_die_type of Table 1;
	Let new_die_color be die_color in row new_die_type of Table 1;
	Let prev_die_color be die_color of Rd;
	Now the die_type of Rd is new_die_type;
	Now the die_sides of Rd is new_die_sides;
	Now the die_description of Rd is new_die_description;
	Now the die_color of Rd is new_die_color;
	Say "You roll the [prev_die_color] die resulting in a: [Vd].    Before your eyes the die shimmers and wavers, morphing into a [die_color of Rd] die with a total of [die_sides of Rd] faces.[line break]";

Fortune Teller Sanctum is a room.  A morphing_die called a Tellers Die is in Fortune Teller Sanctum.

Here is what game play looks like when rolling the die and examining it inside the players inventory as it changes after each roll.

Fortune Teller Sanctum
You can see a Tellers Die here.

>take
(the Tellers Die)
Taken.

>i
You are carrying:
  an orange Tellers Die with a total of 6 faces

>roll
(the Tellers Die)
You roll the orange die resulting in a: 2.    Before your eyes 
the die shimmers and wavers, morphing into a green die 
with a total of 8 faces.

>i
You are carrying:
  a green Tellers Die with a total of 8 faces

>roll
(the Tellers Die)
You roll the green die resulting in a: 7.    Before your eyes 
the die shimmers and wavers, morphing into a purple die 
with a total of 20 faces.

>i
You are carrying:
  a purple Tellers Die with a total of 20 faces

>roll
(the Tellers Die)
You roll the purple die resulting in a: 19.    Before your eyes 
the die shimmers and wavers, morphing into a orange die 
with a total of 6 faces.
2 Likes

Thanks for this, it gave me some ideas!

1 Like