Hi All, In my WIP I am using custom scoring. I was curious how to actually use scoring in my game and had a look at the examples mentioned in the documentation.
See also the Let’s Play/Read: Inform 7 manuals - Playing / IF Reviews and Essays - The Interactive Fiction Community Forum (intfiction.org) post by @mathbrush on Chapter 9 - Time.
Some examples introduce a new full score
command, but I want to basically re-use the standard commands:
score
notify [on]
notify off
The examples basically do the following when custom scoring is involved:
The custom announce the score rule is listed instead of the announce the score rule in the carry out requesting the score rules.
The custom print final score rule is listed instead of the print final score rule in for printing the player’s obituary.
In my case the text which needs to be printed will be the same for both cases, so I create two small rules referring to a say phrase which I can then define to say whatever I want. Here is my initial version:
Curiosity got the better of me however and I wanted to see how the Standard Rules do it. So down the rabbit hole I went…
- Define
use scoring
anduse no scoring
.
Home > Extensions > srules > Preamble
Use scoring translates as (- #IFNDEF USE_SCORING; Constant USE_SCORING = 1; #ENDIF; -).
Use no scoring translates as (- #IFNDEF USE_SCORING; Constant USE_SCORING = 0; #ENDIF; -).
- Define commands
score
,notify [on]
, andnotify off
.
Home > Extensions > srules > Command Grammar
Understand "score" as requesting the score.
Understand "notify" or "notify on" as switching score notification on.
Understand "notify off" as switching score notification off.
Let us ignore the notification commands for now and concentrate on score
.
- Define the
requesting the score
action.
Home > Extensions > srules > Actions
Requesting the score is an action out of world and applying to nothing.
The requesting the score action is accessible to Inter as "Score".
The announce the score rule is listed in the carry out requesting the score rulebook.
The announce the score rule is defined by Inter as "ANNOUNCE_SCORE_R" with
"[if the story has ended]In that game you scored[otherwise]You have so far scored[end if] [score] out of a possible [maximum score], in [turn count] turn[s]" (A),
", earning you the rank of " (B),
"[There] [are] no score in this story." (C),
"[bracket]Your score has just gone up by [number understood in words] point[s].[close bracket]" (D),
"[bracket]Your score has just gone down by [number understood in words] point[s].[close bracket]" (E).
The actual generated documentation page is showing incorrect code in several places (sometimes it drops [<some-char>
in the output).
Wait a sec… whats this ANNOUNCE_SCORE_R
??? More digging…
- Inform6 code coming up…
Home > Kits > WorldModelKit > OutOfWorld Template
[ ANNOUNCE_SCORE_R;
if (actor ~= player) rfalse;
if (KIT_CONFIGURATION_BITMAP & USE_SCORING_TCBIT == 0) {
ANNOUNCE_SCORE_RM('C'); new_line;
} else {
ANNOUNCE_SCORE_RM('A'); PrintRank();
}
];
So in the end it uses response messages A or C defined earlier:
announce the score rule response (A): "[if the story has ended]In that game you scored[otherwise]You have so far scored[end if] [score] out of a possible [maximum score], in [turn count] turn[s]"
announce the score rule response (C): "[There] [are] no score in this story."
Now for completeness I also checked the code path producing the score at the end of the game:
- Posthumous activities
Home > Extensions > srules > Activities
The print final score rule is listed last in for printing the player's obituary.
The print final score rule is defined by Inter as "PRINT_FINAL_SCORE_R".
- More Inform6 code coming up…
Home > Kits > WorldModelKit > OrderOfPlay Template
[ PRINT_FINAL_SCORE_R;
if (KIT_CONFIGURATION_BITMAP & USE_SCORING_TCBIT) ANNOUNCE_SCORE_R();
rfalse;
];
So this confirmed my suspicions: here we re-use the same ANNOUNCE_SCORE_R
function we saw earlier. But then I do not need to replace standard rules at all, I only need to replace response message A actually doing the work of announcing the score!
Here is my revised code:
One lil thing was still missing though. I also wanted the player to be able to switch score notifications on and off. But with custom scoring I also use custom notifications. So I needed a way to find out whether notifications have been enabled. Back to digging…
- Global Variables
Home > Kits > WorldModelKit > Miscellany Template
Global score; = I7 "score"
Global last_score; = I7 "last notified score"
Global notify_mode = 1; score notification on or off
OK so the source also tells me the I7 names of the score
and last_score
variables. But the one I actually need (notify_mode
) is MIA. Ouch.
Fortunately the documentation offers a way out: 27.22. Inform 6 variables, properties, actions, and attributes (ganelson.github.io)
So then I can create a new I7 variable and map it to the existing I6 variable with the following code:
The notify mode is a truth state that varies.
The notify mode variable translates into I6 as "notify_mode".
Nice. Now I can test in my score updating code with if notify mode is true
…