Rulebook variables

Basically I’m trying to modify the variable of a K based rulebook by:

  1. following the rulebook on a subK A.
    …2. following the rulebook on a subK B (from within the subK A rule).
    …3. changing the rulebook variable (we’currently in the subK B rule).

[code]“A test area”

There is a room.

An animal has some indexed text called the name.

A cat is a kind of animal.
A frog is a kind of animal.

The test cat is a cat. The name of the test cat is “cat”.
The test frog is a frog. The name of the test frog is “frog”.

The Animal Testing rules is an animal based rulebook.
The Animal Testing rulebook has some indexed text called the current animal’s name.

Animal Testing for the test cat:
say “[bold type]begin cat[roman type][line break]”;
say " ";
showme the current animal’s name;
follow the Animal Testing Rules for the test frog;
say "[line break] ";
showme the current animal’s name;
say “[bold type]end cat[roman type]”;

Animal Testing for the test frog:
say " [bold type]begin frog[roman type][line break]";
say " “;
showme the current animal’s name;
say " [italic type]change the current animal’s name to the name of the test frog;[roman type][line break]”;
change the current animal’s name to the name of the test frog;
say " “;
showme the current animal’s name;
say " [bold type]end frog[roman type]”;

When play begins:
follow the Animal Testing rules for the test cat.[/code]

executes as follow

A quick look at the generated i6 code shows that

! [5: change the current animal's name to the name of the test frog]
       BlkValueCopy((MStack-->MstVO(365,0)), GProperty(OBJECT_TY, O33_test_frog,p13_name)); 

and the last

! [7: showme the current animal's name] #IFDEF DEBUG;print "~current animal's name~ = indexed text: ", (INDEXED_TEXT_TY_Say) (MStack-->MstVO(365,0)), "^";#ENDIF;

seem to share the same memory address : MStack–>MstVO(365,0)

what is happening ?

(it also works top down):

[spoiler][code]“A test area”

There is a room.

An animal has some indexed text called the name.

A cat is a kind of animal.
A frog is a kind of animal.

The test cat is a cat. The name of the test cat is “cat”.
The test frog is a frog. The name of the test frog is “frog”.

The Animal Testing rules is an animal based rulebook.
The Animal Testing rulebook has some indexed text called the current animal’s name.

Animal Testing for the test cat:
say “[bold type]begin cat[roman type][line break]”;
say " [italic type]change the current animal’s name to the name of the test frog;[roman type][line break]";
change the current animal’s name to the name of the test frog;
say " ";
showme the current animal’s name;
follow the Animal Testing Rules for the test frog;
say "[line break] ";
showme the current animal’s name;
say “[bold type]end cat[roman type]”;

Animal Testing for the test frog:
say " [bold type]begin frog[roman type][line break]";
say " “;
showme the current animal’s name;
say " [bold type]end frog[roman type]”;

When play begins:
follow the Animal Testing rules for the test cat.[/code][/spoiler]

An easier workaround may be to return the name from rulebook B to rulebook A.

The Animal Testing rules is an animal based rulebook producing indexed text.

Each invocation of the rulebook has its own copy of the variables. The code to access them is the same, but MstVO(365,0) will return different values depending on how far down the invocation stack you are.