Properties in tables

One thing you can do with a table is make a column of rules. So one thing you could do, if you really want to be able to change properties of objects from tables, is have the table run a rule that changes Property X of whatever object you want it to to value Y. Like this:

[code]Lab is a room. A rock is in Lab.

A thing has a number called weight. The weight of a thing is usually 5. Definition: A thing is heavy if its weight is at least 10.
Before printing the name of a heavy thing: say "heavy ".

Table of Happenings
subject happening
rock heavifying rule
rock lightifying rule
rock namecalling rule
yourself namecalling rule

Doing stuff from the table to is a thing based rulebook.

Doing stuff from the table to something (called the victim) (this is the heavifying rule):
say “[The victim] is now heavy.”;
now the weight of the victim is 10.

Doing stuff from the table to something (called the victim) (this is the lightifying rule):
say “[The victim] is now light.”;
now the weight of the victim is 1.

Doing stuff from the table to something (called the victim) (this is the namecalling rule):
say “[The victim] will now be called ‘dummyhead.’”;
now the printed name of the victim is “dummyhead”.

Every turn:
choose a random row in the Table of Happenings;
follow the happening entry for the subject entry.[/code]

Now something that makes this inconvenient is that every time you want to change a new property you have to add a new rule. In fact, with this code, every time you want to change a property to a new value you have to add a new rule – if you wanted to change something’s weight to 5 you’d need a rule for that. But you’ll never (I don’t think) be able to come up with a column that contains something like “the value I want to change the thing’s property to”; Inform doesn’t like table columns full of mixed stuff, so you can’t have 10 and “dummyhead” in the same column.

(Maybe you could rig something up with more tables? Have a table for number-based changes, a table for text-based changes, etc. etc., and your master table can call a row of one of the mini-tables – since you can have a column of table names. This is more annoying than anything I am willing to try to mock up right now.)

Anyway, this requires a lot of extra rules, but I don’t know if that has a big cost in overhead, because you’ll only be calling one at a time. And it’s a pain, but at least it can be done. If you want to add another row you can add another rule.

I don’t know anything about I7 tables, so maybe matt’s solution is best. I suppose my answer was to circumvent the property rules by creating classes of things, and assigning properties to the classes, then assigning the specific class properties when I “spawn” the item, or monster, using clone generation. So, an object-orientated approach that creates dynamic things. Then, when the things I want are created, I can cycle through their classes and figure out how to change the messages when I get to that level of the logic – the moment of resolution when the player looks at, affects, or is affected by, the object.

Does this help in any way? I don’t really want to post code examples, as I have a lot of code that is dependent on other code, so its a pretty big string to pull.

Well, you can’t do anything just any which way, of course. You can’t assign anything to anything, you have to create a framework with the expectations set for how you want to do things. I always try to make applications in C# that do allow for string manipulation of just about anything in the application. Inform, or at least Inform 7, still not sure if I understand if this is true of Inform 6 or not, does not appear to have been written this way. I may not be a master C# guru, but I know enough to be able to see the horizon such that you could make an application where you can set properties from strings… it’s pretty much certain. It doesn’t really matter though, because, again, I’m not going to be writing my own parser in C# any time soon… ever.

I am definitely going to play with this… if it doesn’t help with performance overhead, it misses the entire point, so I’ll find that out by trying it! I’m going to certainly have to add much more complexity to the base concept you have above, as you suggest, but here is one of those things I just didn’t know about Inform 7’s structure… that you can store rules in tables. I never thought to ask, and instead asked about storing properties. Even if the above ends up not solving this problem, I’ll consider this thread a success just because I at least learned this much! Thanks!

To be honest, it is a very generic description, but I don’t blame you in the slightest. My framework is only partially built as it is, and probably nowhere near as good as yours even as a function of how complete it is, but it would still be very difficult to paste and explain all of it as it stands. I expect it’s unreasonable for you to share it in any reasonable way in one forum post! I do wonder if you would be willing or able to give a slightly smaller glimpse into what you mean by “class” if by that you don’t mean either kind or property as already defined by Inform.

Had to double post… thank you again matt w, here is the beginning of the implementation based on your recommendation (using hair just as an example here, again, not necessarily as the basis for a real game).

Essentially, since properties cannot be manipulated or reference by strings, I’m giving them numeric “IDs” instead. This would have been of no use, however, if there wasn’t a good method for invoking assigning the ID to an object in the first place, but again, matt w’s suggestion provides just such a method.

I apologize again about the formatting… I’m on vacation and using a family member’s notebook, I’ll be back home tomorrow.

Include Plurality by Emily Short.

A person has a table name called data.

The changing number is a number that varies.

When play begins:
	repeat with P running through people:
		repeat through the data of P:
			now the changing number is the number entry;
			follow the rule entry for the object entry;

Changing the value for is a thing based rulebook.

Changing the value for something (called it) (this is the set size rule):
	now the size of it is the changing number;

Changing the value for something (called it) (this is the set color rule):
	if the changing number > 6:
		now the color of it is white;
	otherwise:
		if the changing number is:
		-- 1: now the color of it is white;
		-- 2: now the color of it is blonde;
		-- 3: now the color of it is brown;
		-- 4: now the color of it is black;
		-- 5: now the color of it is red;
		-- 6: now the color of it is grey;

A thing has a number called size.

A color is a kind of value. Colors are blonde, brown, black, red, grey, and white. A thing has a color. A thing is usually white.

A body-part is a kind of thing.

Some hair is a kind of body-part.

Some hair is usually a part of every person.

The description of some hair is usually "[The holder of the item described] [has-have] [the color of the item described] hair, which is about [the size of the item described] inches in length.";

The test room is a room.

The player is in the test room. Yourself is in the test room.

The data of yourself is Table of yourself.

Table of yourself
object	rule	number
your hair	set size rule	4
your hair	set color rule	3

I don’t know if it is going to kill or help performance when I plug it in to the rest of my framework, as it will take some time to wire in everything like this and get it running against all the objects properly, but the only way to find out is to try! This is only one piece of the puzzle, so if by itself it looks like a pointless exercise, I apologize, but combined with some other things I’m doing to isolate objects and limit the number of objects in the game using “dummies” this should really help with performance… we will see.

In the meantime, if there is anything anyone can say about what is here in this post as far as a way to accomplish the same effect, but in an even better way, please critique.

It looks to me like you’re trying to build a new language inside of Inform 7 inside of Inform 6. There’s no way that’s going to help performance; every level inward has to get slower.

I think Inform 6 might be a better fit for you. It’s lower-level and allows you to directly manipulate pointers and blocks of data.

Also, in I6 the property constants are exposed and can be applied to objects directly.

This is actually very close to what I was trying to get at: assigning numeric values to objects and then using functions to determine what those numbers mean. That is partially what I meant by classes. You have to know what those numbers mean, and keep your own reference.

To give a specific example, for this same function, (told you I was on the same road) I used this:

A hair_style is a kind of value. The hair_styles are red-haired, yellow-haired, bald, black-haired, gray-haired, brown-haired, etc…

And then when I spawn a character, I assign that character a class. This character is a type of “monster”, or type of “npc”. And those classes have their own specific reactions and A.I. When I spawn them, I assign them a random hair_style. Then use [hair style of the npc] to describe them in text. Which is a simple way of assigning and calling values on the fly, when you spawn the creature, instead of assigning variables to an “it” that doesn’t exist, except as a reference point. Instead of creating an abstract reference point, create an actual, physical model of your object by assigning a class, and send it in to the game world.

Well, I don’t mean to improve performance over the base engine haha… I mean, to improve performance of specific use of the engine given the number of objects. Again, there are some assumptions for Inform, and IF in general, that run counter to my ideas for games I want to make… or the other way around, I run counter to the established norm, is probably more fair to say. However, as I said, I don’t have the time or the inclination to make my own engine, so I’m trying to make the best compromise I can.

Specifically, the games I want to make are extraordinarily dynamic and have the need to have a huge amount of objects. Inform can’t handle this with good performance. So, what I’m working on is a way to use Inform’s engine in such a way as to present the player the illusion of a dynamic world with lots of objects, but for it not to really be so in the code. I explained this to a friend of mine in person, and they described what I was trying to do like trying to make Inform behave like an old-school Shakespearean actor’s company, where the same prop can be reused and the same actor can be many different characters.

Anyway, I don’t mean to “improve” performance… I guess I mean to “optimize performance given what I’m trying to do.”

That does it, I am going to study I6 dangit.

Ok, well, we arrived at similar conclusions after all! Numeric reference can’t fail as long as you know what the IDs are… which can of course become cumbersome, but the difficulty is on the human being during the process of coding, not so much on the application when it is running, which is what I’m concerned about. I don’t mind working hard, as long as it makes the application work less hard.

Yes, that’s the conclusion I came to. That will not only save the I7 compiler from having to match text strings (I think integers are easier, less memory intensive), but also give you an easy reference for testing, tweaking the game-play difficulty, and changing how things interact, just by changing a few variables.

When you define a kind of value (like color in this example), the values are handled internally as numbers. There’s no string comparison happening. So you might as well store a “changing color” instead of a “changing number”; it’s just as fast and easier to code.

I have to admit that I’m still a little confused, in particular about whether you’re looking to make Inform do something new or just to do something it already does in a different way. The impression I get is the latter, that you want to model what would ordinarily be several objects as one, overwriting its data so that it can fill the alternative roles, and that the prompting observation is

But if that’s the case, my first question would be about the link between cause and effect there—Inform ought to be able to handle rather dynamic stories with tens of thousands of objects just fine, so maybe it’s worth asking why that’s not the case here? At least it might suggest an avenue that’s less against the grain.

I think in this case the question is: do you want to hand model 10,000 objects, or create a script to generate them dynamically? You see the same problem in lots of AAA games, with reused assets and NPCs wandering around that you’ve seen and talked to before, yet they’re new characters. But if you’re dealing with a large scale world and lots of NPCs doing generic things that don’t have much interactivity, you would need some dynamic way of doing it.

I’m using assemblies and complex verbs and definitions, and I’ve simply experienced a dramatic performance issue already in my example framework, not even a real game. I shudder to think what the performance would be like in a real game expanding upon the basis I’m already using. I’ve explored other avenues of doing the what I’m doing, some of the issues in threads on this forum, and it just doesn’t seem like there are alternatives to some of the other pieces of the framework. For that reason, I’m looking for ways to optimize the number of objects.

In other words, Inform should be able to handle thousands of objects, but I’m doing things that are too complex with them such that it starts to slog at about 1000 objects… which my games using my framework will get up and surpass very easily. So, I need to be more clever about how to present the world to the player, and use “dummies”, but if I use dummies, I need a system for doing what you called “overwriting its data so that it can fill the alternative roles.”

This way, I can define the exact number of characters and objects the game has in it, and calibrate that value to a value at which my framework, given it’s other complexities, still performs well at. So, if I find that my framework can only handle 20 characters at once, but I want 1000 characters, I create 20 dummies, and swap their data in and out as they “enter stage as a character.”

This stuff in this thread is a large piece of that puzzle. The code to actual do the dummy swapping isn’t in this thread, and I’m still working on that (and I’m not on my main computer right now), but it will be directly interfaced with what is in this thread when it is done.

Sounds like you’re solving one problem by introducing another…

There are a lot of problems you run into when you increase the scope of a project, and a lot more problems when you give someone else the keys to change your parameters, so the planning stage of a project like this is real important.

I, too, often wish you could do metaprogramming in Inform. I long for closures. And closure, but that’s mostly because I suck at finishing my damn game.

Anyway, if you have kinds with consistent properties, you can create a table like so:

Table of Interesting Personages
Name   Description            Attitude
"Neo"  "Trenchcoat-wearing"  "Surly"

And swap out between the dummies. You would need a different function to swap properties for each kind, but Inform 7 supports a kind of function overloading. As such:


To swap (dummy - a person) for (target - some text):
  [...]

To swap (dummy - a phrenobulator) for (target - some text):
  [...]

So you can write code that doesn’t care about the type of the thing going into it and just transparently does the job according to the thing’s type. You can also use a rulebook, in which case you would have one rule for all objects (Swapping out generic properties like description, printed name, and so on), and another for each specific type of object. Keep in mind, if you feed an overloaded function something it doesn’t know how to handle, you’ll get a runtime error. But Inform will use the more specific definition of the function as you might expect; for example, this code:

Instead of touching something:
	evaluate the noun with "foo".
	
To evaluate (target - a thing) with (value - some text):
	say "It's generically [colour]."

To evaluate (target - a ball) with (value - some text):
	say "It's [colour]shly spherical."
	
To evaluate (target - a phrenobulator) with (value - some text):
	say "It phrenobulates [colour]fully."

Produces:

>touch ball
It's redishly spherical.

>touch phrenobulator
It phrenobulates bluefully.

>touch myself
It's generically red.