Newbie to TADS3 - Inline functions...bit of help for what should be simples

I have the following defined, but can’t make it compile…any suggestions kind people? The compiler doesn’t like the first { after the switch. Tried all sorts…driving me nuts!

gordon: Actor ‘stone guardian gargoyle/gordon’ ‘Gordon the Gargolyle’ @herbGarden
"An animated stone statue of a winged creature. You created Gordon to guard the tower
and herb garden from pests. He has filler at the back where you can add fuel, and a
snout at the front to shoot through. "

isHim = true
isProperName = true
globalProperName = 'gordon'
fuelLevel = 5

;

currentFuelLevel ()
{
    Switch (self.fuelLevel)
               { 
                case 0:     "Empty";        break;
                case 1:     "Nearly empty"; break; 
                case 2:     "About middle"; break; 
                case 3:     "Fairly full";  break; 
                case 4:     "Quite full";   break; 
                case 5:     "Full";         break;
                default:    "Broken";       break;
                }
}

;

  • Component ‘gordon’s filler’ ‘filler’
    “A hole in the back of Gordon for the express purpose of adding fuel.
    A small gauge next to the filler reads <<gordon.currentFuelLevel())>>”
    ;

I can see two problems with your code:

  • The currentFuelLevel method must be inside the gordon object. Now it’s a static function, and it cannot refer to self.
  • The key word switch is written in lowercase. You’ve written Switch, and the compiler will think that it is the name of a class rather than a statement. This is why the compiler doesn’t like the { after Switch.

Also, you’ll find that you mustn’t use double-quoted strings inside the currentFuelLevel method. In TADS, these are self-printing. You want your method to return these strings so they can be included in the description of the “gordon’s filler” component, so write, for example, case 0: return 'Empty'; (no break needed).

Wow! Thanks Henck. I tried most of those but always with Switch not switch. Massive thanks. Reminds me of my first COBOL programme with “environment” spelt wrong…couldn’t work out why I have hundreds of compiler errors. :+1::grinning:

Is ‘globalProperName’ a custom property or is that supposed to be globalParamName? Just checking…
I don’t know if there’s any other way around it, but if you want a plus-sign to show up in your post, you may need to type (ampersand)plus(semicolon) instead of using the plus sign directly… Welcome to the TADS community!