Help Custom Switch Node

Discussion in 'BBNodes' started by call_me_wei, Dec 30, 2021.

  1. call_me_wei

    call_me_wei Boxer

    Joined:
    Dec 15, 2021
    Messages:
    7
    Likes Received:
    2
    So... I was making a Math game by using " Smart Penguin's " math node .
    BTW : this is a 2D explore game , small map with little shop , can walk in and buy stuff.

    Now , I want a button (let call button A) with 2 function, one is buy (+) and one is sell (-) , of course it won't work with only button , so I make it as (+) in the first place . Now I try to do a button (let call button B) that can switch the button A from (+) to (-) .

    Here's the node part
    - All the node thing in button A
    - button B only send the signal to button A to switch (+) to (-)

    I want the function , like button A when I press it , it +1 then I press it again +1 and keep +1 ++++1 . Now , now , this button B switch the button A to -1 and when this button turn on , the button there will be -1 and -1 and so on ... Until it turn off , it switch it back to +1

    All asset was in 2D world not UI screen
    Can anyone help me just code a little bit on the switch or there was a better way to do it ?
     
  2. Elite Games

    Elite Games Avid Boxer

    Joined:
    Dec 18, 2019
    Messages:
    169
    Likes Received:
    81
    Its a very simple task

    Make script node add two input connections and two out put connections

    1st input for getting the input from A btn
    Other for getting input from B Btn.
    Inside script add variable on top for example
    let cs=true;
    Then in signal function do this
    For example your 1st input name was abtn
    If(name=="abtn" && value)
    {
    If(cs==true)
    {
    this.emitSignal("positive",true);
    }
    else
    {
    this.emitSignal("negative",true);
    }
    }
    Lets switch values when b btn is pressed
    Lets say 2nd input was bbtn
    Again below in signal function do this
    If (name=="bbtn"&&value)
    {
    If(cs==true)
    {
    cs=false;
    }
    else {
    cs=true;
    }
    }
     
    call_me_wei likes this.
  3. Elite Games

    Elite Games Avid Boxer

    Joined:
    Dec 18, 2019
    Messages:
    169
    Likes Received:
    81
    Check this
     

    Attached Files:

  4. call_me_wei

    call_me_wei Boxer

    Joined:
    Dec 15, 2021
    Messages:
    7
    Likes Received:
    2
    AH YES , Thank you so much . That what I'm looking for .
     
    Elite Games likes this.

Share This Page