Is it possible to assign a table to a person?

I created a table of parameters for body parts as well as others things and I want to assign a table to each person, the same way we say a person has a number called health.
So that any modification of a table would modify only the table of person to who it is attached.

Is there a way to do it?

I suppose it is not possible to create a list of lists as well.

mmh

You can do things like this if you like:

[code]“Breakfast for Champions” by Your Self

A Bowl of milk is a room

Every person has a table name called a Table of Stats. The Table of Stats of a person is usually the Table of General Conditions.

Table of General Conditions
Skill Stamina Luck
7 13 7

Snap is a person in a bowl of milk. The Table of Stats is the Table of Snap Conditions.
Crackle is a person in a bowl of milk. The Table of Stats is the Table of Crackle Conditions.
Pop is a person in a bowl of milk. The Table of Stats is the Table of Pop Conditions.

Tony the Tiger is a person in a bowl of milk.

Table of Snap Conditions
Skill Stamina Luck
8 8 8

Table of Crackle Conditions
Skill Stamina Luck
8 8 8

Table of Pop Conditions
Skill Stamina Luck
8 8 8

Every turn: choose row 1 in the Table of Stats of Crackle; now the Luck entry is a random number from 1 to 12; hoose row 1 in the Table of Stats of Tony; increment the stamina entry.

Every turn:
repeat with Kellogg running through persons:
choose row 1 in the Table of Stats of Kellogg;
say “[Kellogg]:[line break]Skill: [skill entry] Stamina: [stamina entry] Luck: [luck entry][paragraph break]”

Test me with “z/z/z/z/z”[/code]
You have to define the Table of Stats of people separately, as per above, if you want them to change independently. (As you see, changing Tony’s Table of Stats means changing the Table of General Conditions, which is also the player’s Table of Stats.) But having done that, you can access them all through the Table of Stats attribute.

Thank you very much for your answer, with a very clear example.

So I guess there is no way to create a single table of stats that can be attributed to every person when play begins for example?

I may have just a dozen characters in the present game so I could do it, but if I want to add a column for example, I would need to add it too all the tables. And if I want to use this stats system in another game it will be very difficult to adapt, and will never be usable if there are a lot of characters, or for example dynamically created characters.

I would like to find a workaround with lists or whatever will do…
I need to have table of lists, or lists of lists, or something that can store lists in arrays.

Do you think there is a way?

I’m not sure I understand exactly what you mean, but it sounds like you actually don’t want a table for every character. It sounds like you want to have all the characters’ stats in one single table:

Table of Character Stats NPC Skill Stamina Luck Snap 8 8 8 Crackle 8 8 8 Pop 8 8 8

You can just look up the stats for any given character in this centralized table using the standard table access commands given in Chapter 15 of the manual.

You can use lists too, I guess, those tables feel more natural to me for this purpose. You can nest lists as deeply as you like.

A list of numbers: {1, 2, 3, 4}
A list of lists of numbers: {{1, 2}, {3, 4}}
A list of lists of lists of numbers: { {{1,2}, {3,4}}, {{5,6}, {7,8}} }

–Erik

Thank you for your answer.
But I may have explained myself incorrectly.

I have a table of body parts with a column with names and other columns with a lot of parameters.
This is a big table.

I want at the beginning of the game all the persons to have a copy of this table as it is defined (everyone with the same values).
But during play for example if someone is wounded I want only this person to be wounded, so I want to be able to change the value of the table without having everyone’s value changing.

I don’t want to copy/paste the initial table as many times as there are people.

I would like to access it with
The table of body parts of character A
now the name corresponding to a xxxx of yyyyy in the table of body parts of character B is zzzz.
etc…

I’d lean toward properties, I guess. I can’t give a clear, tested example unfortunately, because I’m at work. But something like:

A left arm is a part of every person. A left arm can be lacerated. A left arm can be bruised. A left arm can be broken.

All of these are, of course, false by default.

It’s hard to really say. I avoid tables like the plague, so I can’t offer any advice on how to handle it using a table. Seems like a lot more work. The Basic Characters extension could probably handle health or I you could assign a number called health to all people.

I started with properties but I ended with too many parameters to track so a table was the way to go.
If I do this with properties I will need to have properties of properties… I guess this won’t be possible, or manageable…

As a last method I will do with lists since I know now that is technically possible. Though a lot more cumbersome and memory heavy than tables.

Yes, it sounds too complicated for a table, when you can just define all your stats as properties of a person. And it’s okay for properties to have properties - as you’ll see below, kinds-of-value can have properties too.

BUT, if you wanted to, you could do something like this:

[code]Body part is a kind of value. Some body parts are defined by Table of Body Parts.

Table of Body Parts
item (object) maximum damage (number) current damage (number)
head 10 0
torso 20 0
left arm 5 0
right arm 5 0
left leg 7 0
right leg 7 0

Table of Injuries
combatant (object) item (object) current damage (number)
with 12 blank rows

Arena is a room. The Black Knight is a man in Arena.

When play begins:
Repeat through Table of Body Parts:
Let item be item entry;
Let current damage be current damage entry;
Repeat with combatant running through people:
Choose a blank row in Table of Injuries;
Now combatant entry is combatant;
Now item entry is item;
Now current damage entry is current damage;
Repeat through Table of Injuries:
say “[combatant entry] [item entry] [current damage entry][line break]”;[/code]
Note that sometimes you can use a table to create objects, and then you don’t actually ever need to look anything up in it again. I could have said “repeat with item running through body parts” instead of using the table.

If you’re implementing the body parts as things, along the lines of I4L’s “A left arm is a part of every person,” then you can use a table to automatically give every body part of a certain kind a certain health (and other properties) to start with. [This is mentioned somewhat in passing in section 15.16 of the documentation, which is mostly about defining things with tables but also mentions that you can define kinds with tables too.]

Here’s an example that seems to work as far as it goes:

[code]The arena is a room. The black knight is a man in the arena. The white knight is a man in the arena.

A body part is a kind of thing. Some kinds of body part are defined by the Table of Body Part Health.
A left leg is part of every person. A right leg is part of every person. A right arm is part of every person. A left arm is part of every person. [As far as I know, there’s no neat way to say “every person has one of each kind of every body part” or "one of each kind of body part listed in the table of body part health.]

Table of body part health
body part health [This means that every body part defined in this table is automatically assigned a number called health as a property, and that is initially set to the value listed in the table.]
left leg 7
right leg 7
left arm 3
right arm 3

[And now let’s give some rules for examining and changing body part health, so we can see that it works.]

Instead of examining a person:
if the noun incorporates a body part:
repeat with limb running through body parts incorporated by the noun:
say “[The limb] has health [health of limb].”;
otherwise:
say “[The noun] is waddling around, limbless, threatening to bite your knees off.”

Instead of examining a body part:
say “[The noun] has health [health of noun].”

Instead of attacking a body part:
decrease the health of the noun by 1;
if the health of the noun is 0:
say “You strike [the noun] clean off!”;
remove the noun from play;
otherwise:
say “You deal [the noun] a cruel blow, reducing its health to [health of noun]!”

Instead of attacking a person:
if the noun is the player:
say “That’s not a good idea.”;
otherwise if the noun incorporates a body part:
try attacking a random body part that is part of the noun;
otherwise:
say “[The noun] is currently waddling around, limbless, threatening to bite your knees off. You haven’t the heart to attack him.”[/code]

Note that you can attack your own limbs, if you specify them precisely in the command.

Capmikee and Matt w thank you very much.
I think I have enough material now to implement the thing.

I guess the method of capmikee with a blank table may be more adapted to what I want to do since I can have several columns of properties. But i also need body parts objects incorporated to every person so I will use a mix of your 2 propositions.
I wanted to track not only health but also blood and bones, yes I am crazy but if there is a not so difficult way to do it, it is not so much work to have this added dynamic functionality.

Thank you very much, I may post again if I have other difficulties implementing a method or the other ^^

Oh by the way, in the example of Matt w, there is only the health column but it seems possible to add other columns with other properties right?

Yes, for every column you add, you will create a property with that name that all the kinds of body part have (at least the ones created by that table).

Wonderful!
You made my day ^^

I’m not too sure about this, but try moving “Some kinds of bodypart are defined by the table of bodyparts” to before the declarations like “A torso is part of every person” (though still after “A bodypart is a kind of thing”). It looks to me as though the problem is that when it hits “A torso is part of every person” it doesn’t yet know that you’re defining a torso as a kind of bodypart, because that happens when it hits the line “Some kinds of bodypart are defined…” So if you switch the order there, you might not get the error.

You wouldn’t need to move the table, just the “some kinds of bodypart are defined…” line.

Anyway, I’m not sure about that, but that’s a difference I notice between my code and yours – I’ve got things in a slightly different order.

EDIT: Whoops, the post I was responding to seems to have disappeared. I hope this means you solved the problem yourself!

Yes I have solved the problem just after have posted (lol)
Thank you it was exactly that.

I have a question.

I have a funtion that checks which body part has been hit, and I would like to write a switch/case like condition like

if the part-hit is: -- a head: -- a torso:

etc…
though I get an error message.

What is strange is that if I write:

if the part-hit is a head:

it works.
So at the moment I am doing it with a lot of “otherwise”, it is not very easy to read or to correct.

I’m pretty sure you have to use a cascade of otherwise-ifs there. The format you want to use only works when you’re checking the exact value of something. So you could use it if you wanted a series of things like “if the number of items held is 1,” “if the number of items held is 2,” etc., but not “if the number of items held is odd” or “if the number of items held is even.” (Assuming “even” and “odd” are defined.)

It has to be the “is” of identity rather than the “is” of predication, if that’s helpful. If that’s not helpful, which it probably isn’t, you can think of it that it only works when you might be able to substitute “equals” for “is” in English. (Though I don’t think Inform itself lets you use “equals” there.)

I suspect this might be related to the problem I had with using kinds as a column in a table (Testing if an object is a certain type - using tables). Basically sai is trying to switch on a kind just like I was trying to compare an object to a kind from a table.
I suspect you could solve it using the same solution you suggested for me. In other words, add some property to each body part (with a different value for each kind) that you can match on instead.

Oh yes I could do it, but I already have so much properties and tables I guess I will stay with a cascade of ifs and otherwises for now.

Thank you.