Menu

How to connect global changed signal with a specific global variable

Anonymous
2019-06-06
2019-06-06
  • Anonymous

    Anonymous - 2019-06-06

    I would like for the scriptThread.globalUnsignedChangedSignal.connect(functionName) signal to be called only when a specific global variable is changed in the global variable space rather than when any unsigned global variable is changed. Is this possible?

    Example below of what I'm attempting. Both functions are called in this case when value1 or value2 is changed.


    function value1Changed()
    {
    print('value 1 changed');
    }

    function value2Changed()
    {
    print('value 2 changed');
    }

    scriptThread.globalUnsignedChangedSignal.connect(value1Changed);
    scriptThread.globalUnsignedChangedSignal.connect(value2Changed);

    scriptThread.setGlobalUnsignedNumber("value1", 1);
    scriptThread.setGlobalUnsignedNumber("value2", 1);


     
  • Stefan Zieker

    Stefan Zieker - 2019-06-06

    Hi,

    no this is not possible (ScriptCommunicator use the standard QT signal/slot mechanism). But you can check for the name of the variable in your slot function:

    function valueChanged(name, value)
    {
        if(name == "value1")
        {
            print('value 1 changed');
        }
        else if(name == "value2")
        {
            print('value 2 changed');
        }
    }
    
    scriptThread.globalUnsignedChangedSignal.connect(valueChanged);
    scriptThread.setGlobalUnsignedNumber("value1", 1);
    scriptThread.setGlobalUnsignedNumber("value2", 1);
    
     

    Last edit: Stefan Zieker 2019-06-06

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.