Attributes to the player

How do I make attributes to a player like

The player has numbers strength and health.

‘The player has numbers strength and health’ looked to me as if it might be trying to assign certain properties to something which is not allowed to have them.

How do I do this properly?

You can only (I think) assign properties to objects by assigning them to every object in a class. [EDIT: WRONG – see Skinny Mike’s post, below.] So you could say:

A person has a number called strength. A person has a number called health. 

If you don’t want to give other characters strength and health, you could define a special kind for the player, thus:

A PC is a kind of person. A PC has a number called strength. A PC has a number called health. Conan is a PC in Lab [or whatever the starting location is]. The player is Conan.

In this case, I don’t think you can directly declare “the player is a PC,” so you have to create a PC and say that the player is that person.

In these cases, you have to refer to “The strength of the player”; I keep typing “The player’s strength” which gives me a compiler error.

Which leads to another suggestion – if the player is the only character with strength and health, you can just fake it by defining numbers that aren’t actually assigned to the player:

The player's strength is a number which varies. The player's health is a number which varies.

Here you just have numbers named “the player’s strength” and “the player’s health” – even though “the player” is part of their names, they don’t have any technical association with the player (they could be called “foo” and “bar” with the same effect). But you can do what you want with them; in I7, variables don’t have to be attached to objects. I think the only practical difference, if the player is the only character with strength and health, is that when you type the debugging command “showme me” (which shows all properties of the PC) they won’t show up.

Thanks a lot!

Unrelated to your question, but if you are planning to set up a combat system, this might be of interest to you:

Thanks for the hint! I wrote the address down.

I just want to point out that you can add properties to individual objects (or instances of a class, if you prefer) rather than a whole kind. The problem with your original code is that “the player” is not an object but rather a variable which holds whatever person is the player at that moment. You can’t give properties to “the player” because code like “now the player is Jane” would mean that the game would have to create those properties for Jane on the fly (at runtime). The default object representing the player is “yourself,” which – like all objects – can be given unique properties.

I think Matt’s idea of giving the properties to all people in the game is probably more flexible and what you’re looking for (especially for combat, switching characters, etc.). However if you have some need for memory savings (like making a z-code game), here’s an example of what I mean:[code]Lab is a room. Sam is a man in the Lab.

Yourself has a number called strength. The strength is usually 10.

Instead of examining a person:
if the noun provides the property strength,
say “Str = [strength of the noun].”;
otherwise say “[The noun] has no discernible characteristics.”

test me with “x me / x sam / showme me / showme sam”.[/code]

Thanks for the clarification, and sorry for the misinformation – I’ve edited my original post.