value and 1-value



  • Hey guys,
    Is there a doc that would help me understand the usage of value and 1-value ?
    I can see that when scripting buttons, value is equal to 1 and 1-value is equal to 0. But I'm unable to just use 1 or 0... or even true of false.
    For instance: this works

    inline function onButton5Control(component, value)
    {
        if(value)
            { 
    	// call function here
    	}	
    };
    
    Content.getComponent("Button5").setControlCallback(onButton5Control);
    

    But this doesn't:

    inline function onButton5Control(component, value)
    {
        if(Button5 == 0)
            { 
    	// call function here
    	}	
    };
    
    Content.getComponent("Button5").setControlCallback(onButton5Control);
    


  • @dustbro 1-value is just a bit of maths.

    When you click a button it will change state. So if it was 1 it will become 0, if it was 0 it will become 1.

    You use 1-value when you want to flip the result.

    So if the value of the button is 1 1-value = 0 because it's 1 - 1. If the value of the button is 0 1-value = 1 because 1-0 is 1.



  • @d-healey Ok thanks! that makes sense.
    Can you enlighten me on why if(Button5 == 0) doesn't work?



  • @dustbro Do you have a variable called Button5?



  • @d-healey yes.
    const var Button5 = Content.getComponent("Button5");



  • @dustbro said in value and 1-value:

    Could you share your whole script?

    Also why this Content.getComponent("Button5").setControlCallback(onButton5Control);? If you have it in a variable already, why not Button5.setControlCallback(onButton5Control);?



  • @d-healey said in value and 1-value:

    @dustbro said in value and 1-value:
    Also why this Content.getComponent("Button5").setControlCallback(onButton5Control);? If you have it in a variable already, why not Button5.setControlCallback(onButton5Control);?

    I think that's a better question for @Christoph-Hart. From the Interface Canvas, I select an object, right click and select "Create custom callback for selection", and then paste that into the script editor.
    For instance: when I right click on Button5 and select "Create custom callback for selection" it copies the following code into clipboard..

    
    inline function onButton5Control(component, value)
    {
    	//Add your custom logic here...
    };
    
    Content.getComponent("Button5").setControlCallback(onButton5Control);
    


  • Here's the full code. It's a simple test I'm using to show/hide objects.

    Content.makeFrontInterface(600, 500);
    
    const var Button1 = Content.getComponent("Button1");
    const var Knob1 = Content.getComponent("Knob1");
    const var Button2 = Content.getComponent("Button2");
    const var Button5 = Content.getComponent("Button5");
    
    const var Button3 = Content.getComponent("Button3");
    const var Knob2 = Content.getComponent("Knob2");
    const var Button4 = Content.getComponent("Button4");
    const var Button6 = Content.getComponent("Button6");
    
    // Save the controls into arrays
    
    const var page1 = [Content.getComponent("Button1"),
                       Content.getComponent("Knob1"),
                       Content.getComponent("Button2")];
    
                       
    const var page2 = [Content.getComponent("Button3"),
                       Content.getComponent("Knob2"),
                       Content.getComponent("Button4")];
                       
    const var page3 = []
                       
    inline function showPage(pageIndex)
    {
        for(k in page1) 
        {
            k.showControl(pageIndex == 0);
        }
        
        for(k in page2) 
        {
            k.showControl(pageIndex == 1);
        }
        
        for(k in page3) 
        {
            k.showControl(pageIndex == 2);
        }
    }
    
    showPage(2);
    
    inline function onButton5Control(component, value)
    {
        Button6.setValue(0);
        if(value)
            { 
    	    showPage(0); // just call the other function here
    	    }
        else if(1-value)
        {
            showPage(2);
        }
    	
    };
    
    Content.getComponent("Button5").setControlCallback(onButton5Control);
    
    
    
    
    inline function onButton6Control(component, value)
    {
        Button5.setValue(0);
        if(value)
    	    showPage(1); // just call the other function here
    	    else if(1-value)
        {
            showPage(2);
        }
    };
    
    Content.getComponent("Button6").setControlCallback(onButton6Control);
    


  • and... the above works just fine. But in some instances, I don't need to check the status of a button. I just wanna set it's value when an action happens.



  • inline function onButton5Control(component, value)
    {
        if(Button5 == 0)
            { 
    	// call function here
    	}	
    };
    

    You need to check the value not Button5, that's just the variable that stores the control so you need either Button5.getValue() or just value since you get the control's value from the function parameters (component, value).


  • administrators

    @dustbro said in value and 1-value:

    If you have it in a variable already, why not Button5.setControlCallback(onButton5Control);?

    Because the copy to clipboard function is not smart enough to know whether you defined the variable already so it uses this format to make sure that it works if you paste it like this. There's a minimal overhead because it has to look again for the control but this is only when loading the script and takes about 1-2ms so it shouldn't be too drastic.


Log in to reply
 

1
Online

283
Users

773
Topics

5.0k
Posts

Looks like your connection to Forum was lost, please wait while we try to reconnect.