Js Issue

Discussion in 'How Can I...?' started by OceSetThisCannotBeChanged, Feb 2, 2020.

  1. OceSetThisCannotBeChanged

    OceSetThisCannotBeChanged Boxer

    Joined:
    Sep 6, 2018
    Messages:
    21
    Likes Received:
    2
    Hey guys, I need a script node which runs this code

    Code:
    eventName = "XyZaBc.objPositionChanged";
    
    Event.fire(eventName, this.entity().position());
    
    }
    once every time the node is enabled. I really cant get it to work with my (nonexistent) js experience.

    Thanks in advance.
     
  2. jmp909

    jmp909 Boxer

    Joined:
    Feb 2, 2020
    Messages:
    28
    Likes Received:
    4
    if you want it every time the "Enabled" input is fired then I think this would do it...

    Code:
    function signal(name, value) {
      if(name == "Enabled" && value == true) {
        eventName = "XyZaBc.objPositionChanged";
        Event.fire(eventName, this.entity().position());
      }
    }
    
    if you only have one input pin, you don't need to check the name really
     
  3. OceSetThisCannotBeChanged

    OceSetThisCannotBeChanged Boxer

    Joined:
    Sep 6, 2018
    Messages:
    21
    Likes Received:
    2
    Yep, works great, thanks :)
     
  4. jmp909

    jmp909 Boxer

    Joined:
    Feb 2, 2020
    Messages:
    28
    Likes Received:
    4
    glad it worked!

    note if you want you can actually pass an object as the value parameter eg
    Code:
    Event.fire(eventName, { position: this.entity().position(), foo: "bar" });
    then in your event callback
    Code:
    otherPosition = value.position; otherFoo = value.foo;
    etc
     
  5. OceSetThisCannotBeChanged

    OceSetThisCannotBeChanged Boxer

    Joined:
    Sep 6, 2018
    Messages:
    21
    Likes Received:
    2
    Thanks for your input, unfortunately I am really not able to understand what you are trying to say (as I said I really dont understand much of programming). Can you recommend a resource to learn js?
     

Share This Page