[SOLVED] Group References Strange Behaviour?

The place to post scripting ideas, questions or solutions to share with other scripters.
Post Reply
veryalien
Posts: 13
Joined: Wed Apr 16, 2014 am30 9:13 am

[SOLVED] Group References Strange Behaviour?

Post by veryalien »

I'm having a problem understanding what the following script is actually doing. It is a slight modification of a Regnus example in Part 12 of the tutorial - Group references.

The script is behaving the way it should do, but I'm not exactly sure why!

I've added some BLANK comments into the script that attempt to explain what I intended to happen.

Can anyone shed any light on whether this is actually correct, a bug or a feature in Regnus?

Code: Select all

GROUP ReferenceExample

BLANK The experiment here was to try nesting groups of ToolTypes to have one of the PowerTools or one of the ManualTools selected.
BLANK #+Tools; selects a PowerTools entry or a ManualTools entry.
BLANK #+SelectType; selects one of the Animals or a Tool type which, in turn selects one of the PowerTools or one of the ManualTools.

ENTRY <Example>I have a #+ToolTypes; and a #+SelectType;.

GROUP SelectType

BLANK The entry below was originally #+ToolTypes; but that caused errors.
BLANK Is ##ToolTypes; correct here? Why does it return a PowerTools or ManualTools entry?
BLANK I would have expected it to return exactly the text "PowerTools" or "ManualTools".
BLANK What is actually happening here and why? What, if anything, is recursing and why?

ENTRY ##ToolTypes;
ENTRY Animals

GROUP ToolTypes
ENTRY PowerTools
ENTRY ManualTools

GROUP PowerTools
ENTRY drill
ENTRY glue gun
ENTRY sander

GROUP ManualTools
ENTRY hammer
ENTRY nail
ENTRY saw

GROUP Animals
ENTRY cat
ENTRY badger
ENTRY dog
Last edited by veryalien on Sun Apr 20, 2014 pm30 1:21 pm, edited 1 time in total.

User avatar
Ryan
Site Admin
Posts: 144
Joined: Wed Nov 11, 2009 pm30 8:19 pm
Contact:

Re: Group References Strange Behaviour?

Post by Ryan »

The script seems to work as I would expect it to. :)

Starting from the "Example" label, the text returned from the expression in the first reference will be read from the "ToolTypes" group, and so will return either "PowerTools" or "ManualTools", which the group reference RTC will cause to then return an entry from the selected group in the usual way, so the options for the final result of the first reference would be "drill", "glue gun", "sander", "hammer", "nail" or "saw" (all with the same probability).

The text returned by the second reference is a little more complex, because it causes a deeper level of recursion. Firstly, the expression reads a result from the "SelectType" group. If this returns the text "Animals", then the group reference RTC will cause it to return an entry from the "Animals" group (so the final result would be "cat", "badger" or "dog") - but if the entry selected from the "SelectType" group is "##ToolTypes;", then that standard reference will return either "PowerTools" or "ManualTools" from the "ToolTypes" group, and then the group reference RTC will look up the group with that name and return an entry at random (so again, an equal probability of "drill", "glue gun", "sander", "hammer", "nail" or "saw").

The reason a second group reference RTC used in the first entry of the "SelectType" group wouldn't work is that this would then cause that second reference to return an entry from either "ManualTools" or "PowerTools", which would mean that the second group reference RTC in the line labelled "Example" would potentially find itself trying to return an entry from a group called "sander" or "hammer", etc. - which of course doesn't exist. :)

A more succinct example: the reference "##Example;" would be exactly functionally the same as "#+(Example);", but not the same as "#+Example;", which would first get an entry from the group "Example" because of the group expression, and then try to get an entry from a group with a name matching the returned text, due to the group reference RTC.

Ryan

veryalien
Posts: 13
Joined: Wed Apr 16, 2014 am30 9:13 am

Re: Group References Strange Behaviour?

Post by veryalien »

Ryan wrote:
A more succinct example: the reference "##Example;" would be exactly functionally the same as "#+(Example);", but not the same as "#+Example;", which would first get an entry from the group "Example" because of the group expression, and then try to get an entry from a group with a name matching the returned text, due to the group reference RTC.

Ryan


Ahhh now I see the way it works! Thanks very much for the detailed explanation!
From the way I read the tutorials, I didn't notice the subtle, but very important, functional difference between #+Example; where there are two references, and #+(Example); or, its equivalent, ##Example; where there is one only reference.

Post Reply