Two gadgets, one State

… whose isn’t of the Union !

joking aside, the trouble is indeed this:

let’s say that there’s a dial and a light, and turning the dial set the light of the dial to a colour, the dial’s states are, say: leftmost, centre-left, centre, centre-right, rightmost (NO political innuendo here) and the light’s states is red, green, white, blue, black (OK, now there’s political innuendo…), but from what I parse from the docs, a State can have only one set of adjectives.

There’s a solution derived from Exercise 13:

class Pencil: Thing 'pencil'
    "It's <<if isSharpened>> quite sharp<<else>> rather blunt<<end>>. "

replacing the if with a method whose return the consistent state via a switch…case construct, the issue should be solved, but I find this a rather cumbersome mechanism.

Someone has interesting ideas/suggestion on how to deal with this problem ?

Edit: I forget to specify that is under adv3Lite, albeit the State class is a giveaway…
Best regards from Italy,
dott. Piergiorgio.

3 Likes

… whose isn’t of the Union !

Is that a Yugioh reference? I used to play Yugioh online a lot, back when there was a MUD based on the YGOPro engine, and more recently (last year) when there was actually an accessibility mod of EDOPro.

2 Likes

Note, this is adv3 based solution. Not quite clear what you are after here? If the example is literal, I would approach using the LabeledDial and LightSource classes (which isn’t a true State on the Dial).

nonPoliticalDial : LabeledDial, Component
     '(non) (political) non-political ambivalent dial/knob'
     'non-political dial'
     "The dial can be turned to any of the settings
         <<stringLister.showSimpleList(validSettings)>>. It's
         currently set to <<curSetting>>.  It has no political opinions.  "
     validSettings = ['LEFTMOST', 'CENTRE-LEFT', 'CENTRE', 'CENTRE-RIGHT', RIGHTMOST]
     makeSetting(val) {
         // & etc, messaging and handling of switch turning, 
         // probably including invoking politicalLight.desc()  
     }
;
politicalLight : LightSource
     '(red) (green) (white) (blue) (black) (political) opinionated glowing bare light/bulb'
     'political light'
     "A bare bulb that seems to have strong political opinions.  "
     isLit = true
     allStates = [plRedState, plGreenState, plWhiteState, plBlueState, plBlackState]

     // the meat of it.  Map Dial to light states with LookupTable,
     // then set getState appropriately
     switchState = [
          'LEFTMOST' -> plRedState,
          'CENTRE-LEFT' -> plGreenState,
          'CENTRE' -> plWhiteState,
          'CENTRE-RIGHT' -> plBlueState,
          'RIGHTMOST' -> plBlackState
     ]
     getState = switchState[nonPoliticalDial.curSetting]
;
plRedState : ThingState 'glowing red'
     stateTokens = ['red']
;
// repeat for all colors

If this is just an example and you actually want parallel states to cycle, I think you would just change one line in politicalLight

     getState = switchState[nonPoliticalDial.getState]

after doing the work to nonPoliticalDial to correctly set its getState

Note, this is short of a working example, and untested… Learning TADS Section 10.2.3 and 12.2.2 have the detailed writeups.

EDIT: fixed typos pointed out below

2 Likes

Thanks. The mechanism seems viable, both adv3 and a3Lite.

Later I’ll refine this under one of my messing/fooling arena, and the porting to a3Lite seems linear, I’ll report in the next pair of days.

Thanks and
Best regards from Italy,
dott. Piergiorgio.

2 Likes

indeed works as designed, save a pair of coding typos (} instead of ; after getState and plRedState.

I noted that desc in ThingState can be exploited (as usual from myself…), that is, can be used as "extension of the stated item’s desc, but a snippet from the test code explain more clearly (tested, works):

// The actual test. should at least compile... corrected, that is.

/*dial code omitted; if someone is interested, pls ask*/

politicalLight : LightSource
     '(red) (green) (white) (blue) (black) (political) opinionated glowing 
bare light/bulb'
     'political light'
     "A bare bulb that seems to have strong political opinions that is, 
<<getState.desc>>."
     isLit = true
     location = startRoom
     allStates = [plRedState, plGreenState, plWhiteState, plBlueState, 
plBlackState]

     // the meat of it.  Map Dial to light states with LookupTable,
     // then set getState appropriately
     switchState = [
          'LEFTMOST' -> plRedState,
          'CENTRE-LEFT' -> plGreenState,
          'CENTRE' -> plWhiteState,
          'CENTRE-RIGHT' -> plBlueState,
          'RIGHTMOST' -> plBlackState
     ]
     getState = switchState[nonPoliticalDial.curSetting];
// } ???
plRedState : ThingState 'glowing red'
     desc = "glowing marxist red"
     stateTokens = ['red']
;
plGreenState : ThingState 'glowing green'
     desc = "glowing environmentalist green"
     stateTokens = ['green']
;
plWhiteState : ThingState 'glowing white'
     desc = "glowing christian democrat white"
     stateTokens = ['white']
;
plBlueState : ThingState 'glowing blue'
     desc = "glowing conservative blue"
     stateTokens = ['blue']
;
plBlackState : ThingState 'glowing black !?'
     desc = "glowing fascist black, but how is possible a glowing 
<b>black</b> ?!?"
     stateTokens = ['black']
;

Thanks again, JMcC, now in the CREDITS you got a plural ! oh, and the comments below the CREDITS code reminds me to ask you, do you want to be credited and, if yes, how you want to be credited ?

Thanks, and
Best regards from Italy,
dott. Piergiorgio.

3 Likes