How To Pass Objects Between Nodes On Same Object?

Discussion in 'Buildbox 3.0' started by Steddyman, Sep 8, 2018.

  1. Steddyman

    Steddyman Boxer

    Joined:
    Sep 3, 2018
    Messages:
    49
    Likes Received:
    28
    I am trying to pass an object between two nodes in the same graph.

    I have created an output Object on one node and an input Object on another node in the same graph. However, the target nodes receives an object but it is not the object emitted from the source. It is the object received from collisionObject on the If Collide node, and if I call 'remove()' on the source node copy of the object it works. If I try and call that on the destination node, I get a runtime error that the object doesn't have a remove function.

    It doesn't matter if the object is defined as a var or a let in the source node.
     
  2. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    40
    Trying to emitSignal/signal an object from Script to Script delivers an empty 3D vector no matter what is emitted. {x:0, y:0, z:0}
     
  3. thatguyminib

    thatguyminib Serious Boxer

    Joined:
    Jul 1, 2017
    Messages:
    553
    Likes Received:
    304
    Not too sure on what your asking but my guess is that you will probably need to dive into some javascript. I don't think nodes are enough to get the job you want done.
     
  4. LBPToo

    LBPToo Avid Boxer

    Joined:
    Nov 1, 2016
    Messages:
    233
    Likes Received:
    127
    Hi Steddyman, I assume by "graph" you're referring to an object/enity? What type of "object" are you trying to pass? Another object/entity?

    You can pass anything (from or to) using the signal function. If you have already "found" the entity for the object you want to pass using the this.scene().find(objectName) function you can easily pass that to your second node with signal.
    ==================================
    /* in FirstNode */
    var theObjectToPass;

    /* This assumes the two nodes are in the same object, you can also find a node by name in another object*/
    /* you could call this in init() or update() depending on what you're trying to do */
    theObjectToPass = this.scene().find(objectName);/* or however you got the object */
    let comp = this.entity().component('SecondNode'); /*SecondNode is the name of your second node.
    comp.signal('SendTheObject', theObjectToPass ); /*SendTheObject is a name you make up to ID the signal in the second node*/
    ===================================
    /*in SecondNode */
    var _objectPassedFromOtherNode;

    function signal(name, value){
    if(name == 'Enabled') _enabled = value;
    if(name == 'SendTheObject') _objectPassedFromOtherNode = value;
    }
    ===================================
    That's it.

    Bill
     
    particles likes this.
  5. thatguyminib

    thatguyminib Serious Boxer

    Joined:
    Jul 1, 2017
    Messages:
    553
    Likes Received:
    304
    Kinda sucks that this can't be done using nodes alone. BB has really broken from their core of a codeless game maker with bb3 and it looks like there are no plans to change that in the near future, which is unfortunate.

    Don't get me wrong I love that we can do a bunch of things using code, since I am a professional developer. I just feel like they should be focusing more on this node system so everyone can do simple things like this without having to worry about coding.
     
  6. LBPToo

    LBPToo Avid Boxer

    Joined:
    Nov 1, 2016
    Messages:
    233
    Likes Received:
    127
    I get what you're saying, but you have to look ahead and see what this system will buy in the long run. It offers the flexibility that definitely gives an advantage to existing programmers right now....but, in the long run there will be hundreds of custom nodes developed and shared that will allow exactly what you're asking for. I really think it's the best of both worlds, it just happens that in the beginning it won't all be there for everyone, but it will be in the long run.
     
  7. fredi

    fredi Avid Boxer

    Joined:
    Feb 3, 2016
    Messages:
    100
    Likes Received:
    11
    @LBPToo : I can now send a signal to another object. But I can not send this object var = _data {Scene: 22, R:45, G: 44, B: 33} Is that not possible? I try to send 4 values. Thank you for your always generous help.
     
  8. LBPToo

    LBPToo Avid Boxer

    Joined:
    Nov 1, 2016
    Messages:
    233
    Likes Received:
    127
    You can send more than two parameters in the signal function. I would just break up the variables you're sending.
    Code:
    
    var scene = 22;
    var color = new Vec3(45,44,33);
    
    componentToSendto.signal("SendingData", scene, color);
    
    When you receive the signal "SendingData" in the "componentToSendto" signal function, you know there are three variables. You just need to make sure you declare your signal function with three variables.
    Code:
    function signal(name, value1, value2)
    {
      if (name == 'SendingData')
      {
          myLocalScene = value1;
          myLocalColor = value2;
       }
    }
    
     
    fredi and particles like this.
  9. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    286
    Likes Received:
    193
    Wow, I didn't know this.
     
  10. fredi

    fredi Avid Boxer

    Joined:
    Feb 3, 2016
    Messages:
    100
    Likes Received:
    11
    Wow, I will try it, thanks a lot!
     
  11. mxstudios

    mxstudios Boxer

    Joined:
    Aug 30, 2016
    Messages:
    50
    Likes Received:
    13
    @LBPToo, have you actually done this? Obviously it should not matter the names of the variables as long as I am sending the same number of vars I am receiving, right?

    I am sending this:
    this.emitSignal('Direction', direction, _value);
    and receiving this:
    function signal( name, value, value2)
    But value2 is undefined. I have confirmed with a log statement that I am sending a value in _value.

    Thoughts?
     
  12. LBPToo

    LBPToo Avid Boxer

    Joined:
    Nov 1, 2016
    Messages:
    233
    Likes Received:
    127
    I have never tried it with emitSignal. That function is not the same as the signal function. EmitSignal sends values to the declared node outputs that you define. It might work if you define two outputs named accordingly. It's worth a try if that's what you're trying to do.
     
  13. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    40
    I know you're asking LBPToo, but I'll jump in with this...

    You are close, but you missed the subtlety of this line of code from LBPToo:

    componentToSendto.signal("SendingData", scene, color);

    This is instead of using this.emitSignal !!
    Think of .emitSignal( ) as being "of the system." It is a function that's going to work the way the architect wants it too.



    Maybe this will help:
    Code:
    let componentToSendto = this.scene().find("EntityNameToSendTo")[ 0 ].component("componentNameToSendTo");
    componentToSendto.signal("SendingData", scene, color);
    
    A couple more things. Above in LBPToo's post, the forum software ate the "[ 0 ]". Gotta have that. The forum block [ CODE ] [ /CODE] prevents that from happening.

    Second, in order for any chunk of code to be able to call a function in another chunk of code, the name of the function called MUST be known to the component it is in. Specifically, consider this example:
    Code:
    function MyFunctionRocks(just, because) {
    // ... miracle happens here
    }
    // gotta have this next line even for the 3 standard functions, if they need to be seen from outside.
    component.myFunctionRocks = myFunctionRocks;  
    
    In your case the function is signal(). The need for component.signal = signal; still applies.

    Note: the variable named component is defined for free by the Buildbox environment. You can not declare it as in:
    let component;
    or var component;
    without messing everything up.


    Good Luck!

    @DanFarfan
     
    mxstudios and LBPToo like this.
  14. mxstudios

    mxstudios Boxer

    Joined:
    Aug 30, 2016
    Messages:
    50
    Likes Received:
    13
    Thanks!

    Thought it was too easy to assume that emitsignal could have number of param dynamically. I didn’t realize you could call a function in another component. I missed that he was calling signal directly. Got it!

    For this purpose I was able to just use a Vec3 since I needed to pass 3 numbers.

    Thanks for the response.
     
  15. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    40
    You are welcome, mxstudios. Happy to help.
     
  16. LBPToo

    LBPToo Avid Boxer

    Joined:
    Nov 1, 2016
    Messages:
    233
    Likes Received:
    127
    @DanFanfan, thanks for reminding everyone of the "eaten" brackets. Notice I am using CODE blocks now. :)
     
    DanFarfan likes this.
  17. mxstudios

    mxstudios Boxer

    Joined:
    Aug 30, 2016
    Messages:
    50
    Likes Received:
    13
    @DanFarfan ,

    Is component.myFunctionRocks = myFunctionRocks needed if you are only accessing it within the same script. I noticed it is. Wn't that be a problem if 2 nodes have the same function names? I assume not since they are only within that node?

    If component has 2 functions with same name, isn't that an issue?

    Or am i confusing component with entity?
     
  18. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    40
    To be honest, I'm not 100% confident that my understanding of the names of things is exactly the same as Nik's and his team.
    Listening to the videos, there seem to be some overloaded terms and inconsistencies.
    That's the main reason one of my first posts to the forum wasn't a BB3 Vocabulary Cheatsheet.

    But let me take a swing at a few things that might help.
    Inside one script, you can't have 2 functions with the same name. I haven't tried it. I would expect 1 of 2 results.
    Either the script doesn't load properly at all (so nothing in that script executes) or BB3 crashes.

    Scenes have entities (accessed like so: this.scene().find("entityName");
    And entities have components (accessed list so: this.entity().component("componentName");

    Non-coders ( and I don't mean that term as an insult ) seem to call components "nodes." There is support for that term, but not in the API.
    Coders are more likely to adopt the language defined by the API (which does not contain the word "node").

    Which raises the question.. wouldn't
    node.myFunctionRocks = myFunctionRocks;
    be superior?
    Which would in turn make this proper:
    this.entity().node("nodeName");
    (and a whole bunch more changes - improvements? - to the API )

    But, that's just one disconnect between the videos, the BB3 GUI and the BB3 API.
    A deep dive on this topic would be quite a bit of work and at the moment, the product is still in motion. It's impossible for us outsiders to tell what the end game looks like to Nik and his team.

    Hope that helped

    @DanFarfan
     
    nyamuk91 likes this.
  19. mxstudios

    mxstudios Boxer

    Joined:
    Aug 30, 2016
    Messages:
    50
    Likes Received:
    13
    @DanFarfan, I’m actually laughing out loud that you said the “Non-coders” part and mentioned not wanting to insult me. Mostly because I am trying to dummy down my questions to the terms used in Buildbox since it is not a programming platform, but rather a non programming tool. I’ve been developing software for over 30 years, every day of my life.

    That’s why I am a little frustrated with writing scripts in BB. The documentation is extremely lacking, and the only way to actually see some of the errors thrown appears to be to build it in Xcode since there is absolutely no feedback from BB. It’s like swimming with concrete blocks. It would be great if the debug window would at least do more than just not run code blocks when an error occurs. Maybe show an error. But I understand it’s beta.

    Rather than build games in Cocos or Unity, I am giving this a shot to cut down on dev time and focus on the game itself.

    Main reason I asked this was because I built a dual joystick which breaks the screen in half and uses touches to report what direction each half is doing, etc... I found that for some reason I was getting cross script issues on the TouchesEnded and have a feeling it’s because they both belong to the same entity possibly. It since they are different components, that’s probably not the case.

    It’s become a lot of trial and error, but I’ve managed to some cool stuff.

    Thanks for your feedback.
     
  20. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    40
    You're welcome.
    I wasn't referring to or even thinking about you personally when I mentioned coders and non-coders. I was characterizing the whole community!
    But, I'm glad you weren't offended. :)
    It's easy to tell from your forum posts you are a coder. That also makes it a plus to be able to share what I've pieced together, so far.
    It's a challenge sometimes, but I always try to remember that posts will be read for a long time and by people with very different backgrounds.

    Enjoy!

    @DanFarfan
     

Share This Page