Snippets vs. Text (more skill system questions)

TL;DR: Unable to do text comparisons with the topic understood of an action because of the type conflict between text and snippets.

While skills are often used implicitly, as in the attacking example from my last thread, a proper skill system should allow the player to use them explicitly, so there needs to be a “use skill” verb, which is apparently very difficult. The basic system:

[code]The school is a room.

A person has a number called the Strength. The strength of a person is usually 3.
A person has a number called the Agility. The agility of a person is usually 4.
A person has a number called the Perception. The perception of a person is usually 5.
A person has a number called the Stamina. The stamina of a person is usually 2.

Table of Skill Difficulties
Skill Ability Difficulty
“Brawl” “Strength” 4
“Dodge” “Agility” 4
“Climb” “Strength” 5
“Spot” “Perception” 6
“Swim” “Stamina” 6

To decide which number is the score of (T - some text) for (P - a person):
if T is “Strength”, decide on the strength of P;
if T is “Agility”, decide on the agility of P;
if T is “Perception”, decide on the perception of P;
if T is “Stamina”, decide on the stamina of P;
decide on 0.

A person has a table name called the skill table. The skill table of a person is usually the Table of Generic Skills.

Table of Generic Skills
Skill Level
“Dodge” 1
“Brawl” 1[/code]

And a skill for using:

Using is an action applying to one topic. Understand "use [text]" as using.

The trouble begins with the check rules. We want to be able to check if the topic understood is on the skill list at all, if it’s on the player’s skill list specifically, and it would be nice to have arbitrary rules, too, but we can’t do any of those because the topic understood is a snippet, not a text, and can’t be directly compared to texts:

Check using: if the topic understood is not a skill listed in the table of skill difficulties, say "While I'm sure [the topic understood] is a fascinating field of study, it is not featured in this game." instead; if the topic understood is not a skill listed in the skill table of the player, say "In your youthful foolishness, you failed to pay attention during [the topic understood] class." instead; if the topic understood is "Toaster Repair", say "What, are you expecting to find broken toasters everywhere you go?" instead.

The first two check rules can be fixed by changing the Skill columns of the tables to Topic columns:

[code]Table of Skill Difficulties
Topic Ability Difficulty
“Brawl” “Strength” 4
“Dodge” “Agility” 4
“Climb” “Strength” 5
“Spot” “Perception” 6
“Swim” “Stamina” 6

A person has a table name called the skill table. The skill table of a person is usually the Table of Generic Skills.

Table of Generic Skills
Topic Level
“Dodge” 1
“Brawl” 1

Using is an action applying to one topic.
Understand “use [text]” as using.

Check using:
if the topic understood is not a topic listed in the table of skill difficulties, say “While I’m sure [the topic understood] is a fascinating field of study, it is not featured in this game.” instead;
if the topic understood is not a topic listed in the skill table of the player, say “In your youthful foolishness, you failed to pay attention during [the topic understood] class.” instead.[/code]

But we’ve still lost the toaster rule. More importantly, it’s just kicking the problem down the road: since the table columns are now snippets instead of text, now all the other rules that compare text to the skill tables won’t work, such as this:

[code]To decide if (P - a person) has mastered (T - some text):
if there is a skill of T in the skill table of P, decide yes;
decide no.

When play begins:
if the player has mastered “Dodge”, say “Dodging!”;
if the player has mastered “Climb”, say “Climbing!”[/code]

(Changing “a skill of T” to “a topic of T” makes it compile, but it still won’t work.) Solutions?

After last thread, is there a reason why you can’t drop the quotes and use a kind of value? You really are working against the grain, trying to use strings as internal value keys.

You’ve already got the decide phrase with one line per property, which is the thing you need to make the kind-of-value viable.

If you’re trying to get the text comparsion to work, then this should work.

[code]“Test”

The School is A Room.

A person has a number called the Strength. The strength of a person is usually 3.
A person has a number called the Agility. The agility of a person is usually 4.
A person has a number called the Perception. The perception of a person is usually 5.
A person has a number called the Stamina. The stamina of a person is usually 2.

Table of Skill Difficulties
Skill Ability Difficulty
“Brawl” “Strength” 4
“Dodge” “Agility” 4
“Climb” “Strength” 5
“Spot” “Perception” 6
“Swim” “Stamina” 6

To decide which number is the score of (T - some text) for (P - a person):
if T is “Strength”, decide on the strength of P;
if T is “Agility”, decide on the agility of P;
if T is “Perception”, decide on the perception of P;
if T is “Stamina”, decide on the stamina of P;
decide on 0.

A person has a table name called the skill table. The skill table of a person is usually the Table of Generic Skills.

Table of Generic Skills
Skill Level
“Dodge” 1
“Brawl” 1

Using is an action applying to one topic. Understand “Use [text]” as using.

Temporary is a truth state that varies.

Check using:
if the topic understood exactly matches the text “Toaster Repair”, case insensitively begin;
say “What, are you expecting to find broken toasters everywhere you go?” instead;
end if;
now temporary is false;
repeat through the table of skill difficulties begin;
if the topic understood exactly matches the text skill entry, case insensitively begin;
now temporary is true;
end if;
end repeat;
if temporary is false, say “While I’m sure [the topic understood] is a fascinating field of study, it is not featured in this game.” instead;
now temporary is false;
repeat through the skill table of the player begin;
if the topic understood exactly matches the text skill entry, case insensitively begin;
now temporary is true;
end if;
end repeat;
if temporary is false, say “In your youthful foolishness, you failed to pay attention during [the topic understood] class.” instead.

Report using:
say “This succeeds.”.

Test me with “use toaster repair / use speed / use swim / use spot / use climb / use dodge / use brawl”.[/code]

In general, comparing any text using “if A is B”, even if it is in a table, doesn’t work nicely. The best way is to compare them using “if A matches the text B” and “if A exactly matches the text B”.

However, I believe zarf makes a good point. It’s better to use kinds of value rather than strings.

There are less-than-general cases where it does work nicely. (If there are no indexed texts, topics, or snippets in sight, the texts do not have -substitutions, and the texts are not derived from the player’s input, then the comparison is both reliable and efficient. Except for that bug involving object names.)

However, if you’ve constrained your code that carefully, you might as well not be using texts for that purpose.