Asking random topics

I have two commands: talking to (applying to 1 thing) and (the standard) asking it about (applying to 1 thing and 1 topic). When the player uses the talking to command, a random topic should be selected from a list and be mapped to the asking it about command.

I found two ways that work, but I’d like to know why my first approach doesn’t work.

The last line of this doesn’t work:

RandomTopics is a list of text that varies.
RandomTopics is {"depth", "eidolon", "sea", "betty", "rudolf"}.

Instead of talking to the radio:
	let i be a random number from 1 to number of entries in RandomTopics;
	let t be entry i of RandomTopics;
	try asking the radio about t.

And neither does it when I change the last line to this:

	try asking the radio about "[t]".

Why is that?

Here are the solutions that DO work:

RandomTopics is a list of text that varies.
RandomTopics is {"depth", "eidolon", "sea", "betty", "rudolf"}.

Instead of talking to the radio:
	try asking the radio about "[rato]".
	
To say rato:
	let i be a random number from 1 to number of entries in RandomTopics;
	say "[entry i of RandomTopics]".

The other working approach is from @StJohnLimbo:

Instead of talking to the radio:
	now SelectedWord is a random PsychedelicWords;
	try asking the radio about "[SelectedWord]".

(From this thread Text variable matching question (includes regex), which is beyond my horizon.)

EDIT: What I wrote here applies only to 6M62. It seems that 10.1.2 does not have the same limitation; see StJohnLimbo’s post below for more details.


The difference is whether or not the substitution used for the topic to be asked includes a variable.

Looking at the way the code for the asking it about action is generated for the working version:

! [3: try asking radio about ~[rato]~]
TryAction(32, player, ##Ask, I127_radio, TX_S_135);

Notice that the fifth parameter is a constant value, in this case involving the following code:

Array TX_S_135 --> CONSTANT_PACKED_TEXT_STORAGE R_TX_S_135;	! array to represent text in I7

[ R_TX_S_135 I7RBLK;
	@push I7SFRAME;
	StackFrameCreate(2);
	BlkValueCreateOnStack(0, TEXT_TY);
	I7RBLK = KERNEL_3();	! no parameter but KERNEL_3 is hardcoded to use the stack from just created
	BlkValueFreeOnStack(0);
	@pull I7SFRAME;
	return I7RBLK; ! nothing
];

[ KERNEL_3 ;
	#ifdef DEBUG; if (suppress_text_substitution) { print "~[rato]~"; rtrue; }
	#endif; ! DEBUG
	! [1: ~[rato]~]
	say__p=1;! [2: rato]
	ParaContent(); print (TEXT_TY_Say) (PHR_801_r46 (I7SFRAME)); .L_Say468; .L_SayX466;rtrue; ! uses subsidiary function PHR_801_r46()
];

! Request 46: phrase nothing -> text
! To decide which text is rato: ! a little different than yours but the principle is the same
[ PHR_801_r46  
	tmp_0 ! Let/loop value, e.g., 'N': number		! random number held in local variable
	;
	! [2: let n be a random number from 1 to 5]

			tmp_0 = R_DecimalNumber(1, 5);			! random number generation and assignment
	! [3: say ~[entry N of RandomTopics]~]
	say__p=1;! [4: entry n of randomtopics]
	ParaContent(); print (TEXT_TY_Say) LIST_OF_TY_GetItem((Global_Vars-->10),tmp_0); .L_Say467; .L_SayX465;return BC_180; ! prints the random text from global list variable
];

Under the covers, the compiler allows a text to hold a routine instead of a string. When the text is printed, the routine is executed, but in the context of trying asking... there is no path for passing any parameter (i.e. variable value) to the routine. The rato example sets up a routine with no input parameter that returns a text, so it does not need any variable input and is allowed.

If you wanted to pass a parameter surreptitiously, you could do it with something like:

Nonrato arg is initially 0.

To decide which text is nonrato:
	say "[entry nonrato arg of RandomTopics]".

Instead of talking to the radio:
	now nonrato arg is a random number from 1 to number of entries in RandomTopics; [modify to determine the parameter as you like]
	try asking radio about "[nonrato]".
2 Likes

That seems to work for me in I7 v10.1.2 (but not in I7 v9.3/6M62):

Instead of talking to the radio:
	let i be a random number from 1 to number of entries in RandomTopics;
	let t be entry i of RandomTopics;
	try asking the radio about "[t]".

The intermediate step via t can also be left out:

Instead of talking to the radio:
	let i be a random number from 1 to number of entries in RandomTopics;
	try asking the radio about "[entry i of RandomTopics]".
4 Likes