Color-changing button

Hi there,

I’m trying to design a button (well, a colored light that can be pressed like a button) which cycles through colors when pressed. I’m having two problems. The simpler of the two is that, if I just make the object a Button, I can pick it up and pocket it, which is bad. But if I make it a fixture, then when I try to Push or Press the button, it says I can’t move that.

Second, as I said, I’m trying to have it cycle through colors. I coded the object as shown below, and it compiles fine, but it doesn’t have any effect – when I press the button, it just says “click,” which I believe is the default response for the Button class.

  • Button ‘four 4 button/light’ ‘button four’
    color = colorChange.doScript();
    “The button turns <>”
    desc = “The light glows <>, but emanates no heat. It looks like you could probably press it”
    color = ‘red’;

colorChange: CyclicEventList

Any idea what I’m doing wrong here?



There are a couple of issues. For one thing, you have “The button turns <>” outside of the action() block, so it’s not going to be used. Also, I’m not sure (my T3 is very rusty), but I don’t think you can use doScript() that way, because your single-quoted strings aren’t going to do anything. They’re not events that have a result. In other words, I’m pretty sure doScript() doesn’t return a value. (You can check the source code using the Library Reference Manual.)

Here’s a first approximation to how I would do it. Note that I’ve made the colorChange object a property object within the button.

+ colorButton: Button, Fixture 'red four 4 button/light' 'red button four' "The light glows <<color>>, but emanates no heat. It looks like you could probably press it. " color = 'red' dobjFor(Push){ action(){ cmdDict.removeWord(colorButton, color, &adjective); colorChange.doScript(); cmdDict.addWord(colorButton, color, &adjective); name = color + ' button four'; "The button turns <<color>>. "; } } colorChange: CyclicEventList {[ {: lexicalParent.color = 'yellow' }, {: lexicalParent.color = 'green' }, {: lexicalParent.color = 'red' }, {: lexicalParent.color = 'orange' }, {: lexicalParent.color = 'blue' } ]} ;
Note the use of cmdDict. This causes the vocabulary that can be used by the player to refer to the button to change, depending on its current color. Also, the printed name will change.

Also, I’ve made the events in the CyclicEventList into anonymous functions. These change the color property of the button.

By playing around with this, perhaps you can get it working the way you want.

That worked! I will study it and see if I can’t learn a little something :slight_smile:


So, kind of a corollary to this… Got the buttons working, tried to put in a random event list, but the random event list does the same order each time I restart the program. It’s not going down the list, but it’s always an identical “random” order.

Pasting in the entire code for this object below, in case it’s relevant, but you can see the RandomEventList near the bottom. Also, clearly, this is how I’ve been using it to test, but it will not wind up so redundant.

Any help you can provide would be greatly appreciated.


  • briefcase: Fixture ‘silver metallic metal case/briefcase’ ‘metallic briefcase’
    "The briefcase appears to be made of some type of metal, but you don’t think it’s one you’ve ever seen. It is warm to the touch – and
    completely impenetrable. "

    stage = ‘null’

    morseCode: CyclicEventList
    // {: lexicalParent.stage = 'The <<lexicalParent.lastButPush>> slowly fades to '},
    {: lexicalParent.slowChange.doScript()},
    {: lexicalParent.slowChange.doScript()},
    {: lexicalParent.slowChange.doScript()},
    {: lexicalParent.slowChange.doScript()}
    // {: lexicalParent.stage = ‘quickly changes to’}

    lastButPush = ‘null’

    slowChange: RandomEventList
    {: lexicalParent.stage = 'The <<lexicalParent.lastButPush>> slowly fades to '},
    {: lexicalParent.stage = ‘option b’},
    {: lexicalParent.stage = ‘option c’},
    {: lexicalParent.stage = ‘option e’},
    {: lexicalParent.stage = ‘option d’}


Page 157 of “Learning TADS 3” discusses the randomize() command. As noted there, you don’t need to use this, because the random values will be different on every run-through, except when you’re testing the game in Workbench. This is sensible from a development standpoint, as it insures that your auto-saved scripts will always produce the same output.

Thank you!