Can NPC stats be linked?

I apologize if any of this comes off as extra ignorant or uninformed - I basically picked up Inform7 a month or so ago with no prior programming or game building experience and have been slowly, painfully learning the ropes by pouring over the source code of a game I had enjoyed playing.

That eventually turned into making what modifications I could understand, quite a few wasted hours running into road blocks and forcing my way around them - now though I was hoping I could find an easier or more elegant solution to something I have been doing by brute force.

Namely, in the game I have clones of NPCs, specifically to represent an NPC changing names after certain conditions are met. I tried using printed names to achieve this at first but because the NPCs in the game are fairly complicated with parts and stats and so on this quickly broke down. Another thread here suggested a better way might be to have a copy, basically, of an NPC off stage with a different name and then swap them in as appropriate. That’s all fine and well but I’m wondering if there is a rule or a shorthand way of linking the stats of an NPC to that NPC’s copy instead of writing out “now the strength of NPC-A is the strength of NPC-A’s Clone;” over and over etc (there’s like 80 stats per NPC and something like 20 NPCs)

Ideally I’d like to just be able to say “all the stats of NPC-A are the stats of NPC-A’s Clone” without having to type each one individually, just for tidiness’ sake. Can a rule be formatted to do that?

You might be looking for the repeat running through, which is a loop.

Also, I’m not 100% sure, but more than likely you will want to avoid apostrophes in the printed names of things. It could cause problems, so I’d just go with “NPC A Clone” instead of “NPC A’s Clone.”

When play begins:
	repeat with clones running through people:
		 repeat with originals running through people:
			let x be the printed name of clones;
 			let y be the printed name of originals;
			if x matches the text "[y] clone" and x is not y:
			        [foo]

As for foo, I don’t know what to write for you because I don’t know how the “stats” were created without example code, but you might be able to use another repeat loop on them. Otherwise, you could just write the 80 lines like this:

When play begins:
	repeat with clones running through people:
		repeat with originals running through people:
			let x be the printed name of clones;
			let y be the printed name of originals;
			if x matches the text "[y] clone" and x is not y:
				now statone of clones is statone of originals;
				now stattwo of clones is stattwo of originals;
				etc.

It might be easier just to change the “printed name” property of the NPC than to use a clone, depending on what needs to change.

dootdoot, so if I understand you correctly in creating the NPCs I’d have to define each of them as either a clone or original right? Something like:

John is an NPC. John is an original. John is in Room1. James is an NPC. James is a clone. James is in Stasis.

Would I also have to write:

A clone is a type of person. A original is a type of person.

In order for the game to understand those phrases? Can I link John and James specifically so that the game understands James is a clone of John? I’m trying to create a situation where the stats of John and James are identical so that when one is swapped out all that appears to change is the name. I have about 23 pairs of NPCs and was planning to add a third clone state to each for a total of 69 NPCs. Each set of three NPCs would be linked then but I don’t want the whole group linked, changing as one, if that makes sense.

Draconis, that actually was my first attempt but I ran into the same problems described here: https://intfiction.org/t/random-name-generation-for-npcs/857/1 wherein if I change John’s printed name to James then try to examine James’ hair or some other part of him the game doesn’t know what I’m talking about. So I took that threads advice and made clones instead which is a lot more work but seems to solve the issue.

Anyway I definitely appreciate the advice and will looking into the repeat running through order to see if I can get it to make sense to me (still learning!)

Kinds form a strict hierarchy, so you’d probably want

A clone is a kind of NPC.
A original is a kind of NPC.

Linking them together could be done with a property or a relation.

Ah, gotcha. I would solve this by using the new version of Shadow Wolf’s Possession and Ownership extension (with Dootdoot’s modifications), which gives the parser a better understanding of the apostrophe-S construction. To make the body parts print properly I’d define a “body part” kind (with everything else inheriting from it), then use “printing the name of” rules to remove the old possessive and add a new one. This might be a bit unclear, I’ll try some sample code tomorrow.

I’d definitely appreciate it! I don’t know if I am just super thick skulled at the moment or just over my head and out of my depth but, in trying to enact zarf’s suggestion I can’t seem to work out how to relate two NPCs to each other, let alone three. I’ve got as far as the code described in the document in part 13.7 where a transmutation is covered. Currently looks like this:

An NPC is a kind of person. Cloning relates NPCs to each other in groups. The verb to clone (it clones, they clone, it cloned) implies the cloning relation. Definition: an NPC is clonable if they become more than one NPC. An NPC can be a clone. An NPC can be an original. John is an NPC. John is in Room1. John is an original. James is an NPC. James is in Stasis. James is a clone. James is the clone of John.

You can probably guess that that doesn’t work, I know I need to do more/better defining but I’m struggling on how at the moment.

I wouldn’t mind going back to the printed name solution but the other issue I was running into with that, besides the body parts thing, was having the parser report the names incorrectly in play. So if you examined James (the clone of John) it would say James in the description, but if James entered the room with you it would say “John enters the room!”

Hmm…

In the interest of minimizing code and with an eye to future extensibility, you may want to use tables instead:

[code]Suspiciously Capacious Attic is a room. Ballroom is a room.

A diagnostic is a kind of value. The diagnostics are defined by the Table of Diagnostics.
A person has a diagnostic. The diagnostic of the Player is Personal.

Bob is a man in the Attic. The description is “Why, it’s Sir Robert!”
The diagnostic of Bob is Bobby.

After examining Bob:
now Sir Robert is in the location;
now Bob is off-stage.

Sir Robert is a man. Understand “Bob” as Sir Robert.
The diagnostic of Sir Robert is Bobby.

Last carry out examining someone:
choose row with index of the diagnostic of the item described in the Table of Diagnostics;
say “health: [health entry]
[line break]narrowness: [narrowness entry]
[line break]hops gathered: [hops entry]
[line break]phlegm: [phlegm entry]
[if depressed entry is true][line break]ERROR: subject is not right-thinking[end if]
[paragraph break]”

Table of Diagnostics
index health narrowness hops phlegm depressed happy place
Bobby 55 1 0 12 true Ballroom
Personal 43 50 3 1 false the Attic
Mook1 1 1 0 5 true Ballroom
Mook2 1 1 0 5 true Ballroom[/code]

(You’ll have to quote this post to copy the tabs properly.) Apparently not any more!

This way anyone can have an arbitrary number of any types of variables associated with them, and multiple people can share the same ‘diagnostic’ index, as in the case of the good Sir Robert. And you can change one person’s stats entirely so that a skeleton can double as a T-rex in case of random encounters, for example.

(If people can have DOZENS of values associated with them, it may help to break each of these types into its own table: Table of Body Armor, Table of Weapon1, Table of Weapon2, Table of Moods, and so on, each with its own index column of ‘diagnostic’ values.)

It looks to me as though you need to use the verb you defined, “to clone.” So instead of “James is the clone of John” you would write “James clones John,” and instead of “an NPC is clonable if they become more than one NPC” you would write “an NPC is clonable if they clone more than one NPC.”

Also, I suspect that you want to say “An NPC can be a clone or original”; as it is you are defining two on-off properties, “clone/not clone” and “original/not original,” when I think you want those to be alternatives to each other.

UPDATE: That said, I think ChrisC’s tables solution is probably more workable. By the way, you don’t have to quote the post to make sure the tabs copy correctly anymore.