Action code for setting attribute value OR resetting to 'normal' value

I’d like to change a note’s Badge and Color when it is $Checked, but inherit the prototype’s values otherwise.

The first part is straightforward, but I’m stuck on the second. The Displayed Attributes interface has a ‘normal’ value that I can use. Is there something analogous to use in action code?

Right now, I have this clumsy business, which doesn’t quite do what I want.

if ($IsPrototype==false) {
    if ($Checked==true) {
        $Badge="check";
        $Color="dark blue";
    } else {
        $Badge=$Badge("/Prototypes/Task");
        $Color=$Color("/Prototypes/Task");
    }
}

What’s not stated is what you do expect that the code doesn’t achieve, The logic I read from the code is

  • if this note has no prototype ( $Prototype==false):
    • Set $Badge to check and $Color to dark blue
  • else:
    • Set both the $Badge and $Colour to that of Prototype “Task”

You mention $Checked but don’t use in in your code . But why? Checing checked state is easy:

if($Checked==true){
   ...
};

Based on an incomplete description of the scenario, and assuming the prototype is ‘Task’, have you tried:

if($Checked==true){
   $Badge="check";
   $Color="dark blue";
}else{
   $Badge=$Badge("/Prototypes/Task");
   $Color=$Color("/Prototypes/Task");
};

Why are you checking $IsPrototype==false? It implies you haven’t fully described the test case.

Remember, it’s easy to state the result is ‘wrong’. The resolution is to check the logic of your tests. Normally the error is incorrect action code syntax or testing the wrong condition.

I think you missed my question. :wink: Here’s what I asked:

The Displayed Attributes interface has a ‘normal’ value that I can use. Is there something analogous to use in action code?

Using the Displayed Attributes interface to select a value for an attribute, you have the option of selecting the ‘normal’ value. As I understand it, selecting ‘normal’ removes any note-specific values so that a note will use the inherited value of its prototype or otherwise fall back on the default.

My question was, how do you accomplish the same thing in action code?

The method in my (and your) code examples isn’t ideal.

        $Badge=$Badge("/Prototypes/Task");
        $Color=$Color("/Prototypes/Task");

First, it hard-codes the prototype name, so if you change the name of the prototype you also need to change the code. And second, I believe that it copies the value from prototype instead of inheriting it, so that if you change the prototype’s Badge or Color, the note won’t inherit the new value.

So I thinking there must be a way to do this that I haven’t learned.

Please correct me if I’m wrong about any of that!

To reset an attribute to its inherited or default value, Tinderbox writes

$AttributeName=;

Further to the last: Setting an attribute to re-enable inheritance via code.

:person_facepalming: Thank you!