Buildbox 3 Alpha3: Scene Search Tutorial

Discussion in 'Buildbox 3.0' started by NikRudenko, Jul 10, 2018.

  1. NikRudenko

    NikRudenko Administrator Staff Member

    Joined:
    Sep 25, 2015
    Messages:
    179
    Likes Received:
    493
    Hello guys. Just thought it might be interesting to have some extra fun with Alpha3.
    So here I prepared a mini tutorial on how to edit JavaScript code in BB3.

    We going to use Flap Template as foundation and put some extra stuff. Lets say we have a Key on level and If you picked up that key then doors will open.
    Something like this:
    [​IMG]

    Here is complete BBDOC file for you to have fun with:
    bb3_gate_key.bbdoc

    Whole logic with this Key-Door thing is happening inside Key Asset.
    [​IMG]
    What we need to do is find all Entities with name "Door" and move them up +2 units. And all that should happened on collision. For collision we can use If Collide (don't forget to select Character as Asset)
    When I need something custom in BB3 I just reusing stock nodes.
    Usually i grab Move Node, double clicked on it and then removed all code expect three functions. (those are essential lines of code and script will not work without them) Then I add my own code and ready to go.
    [​IMG]
    Init - will be triggered when object first time created
    Update - will be triggered every game loop (dt is a delta time)
    Signal - will be triggered every time Node receive signals from input connections. In this case it will be only Enabled attribute

    [​IMG]
    Here is final code. As you can see i'm using this.scene().find('Door'); as a way to find all objects on a scene and after that I just iterate objects through and move them up.

    Let me know if you guys have some questions.
    Cheers.
     
  2. thatguyminib

    thatguyminib Serious Boxer

    Joined:
    Jul 1, 2017
    Messages:
    552
    Likes Received:
    309
    @NikRudenko This is awesome! Is there any way to grab a variable that is created on an object and adjust it? Like if I had an int on the door would I be able to increase it or call a custom node or function on that door?
     
  3. NikRudenko

    NikRudenko Administrator Staff Member

    Joined:
    Sep 25, 2015
    Messages:
    179
    Likes Received:
    493
    yes. you can do that too. If you create a node inside that Door entity and call it 'Lift' your code might be like this.

    let doors = this.scene().find('Door');
    for(let i=0; i<doors.length; i++){
    let component = doors.component('Lift');
    component.signal('Move Up', 56);​
    }

    So what you do is you finding a component by calling "component" function. then you can call Signal to that component and pass any string as name of a signal and any variable (int, float, string, objects) as value. Similar how I receive signal from If Collision in a example above.
     
  4. thatguyminib

    thatguyminib Serious Boxer

    Joined:
    Jul 1, 2017
    Messages:
    552
    Likes Received:
    309
    Great! This was one of the things I was worried if we would be able to do lol

    Is there a documentation in the works for the javascript?
     
    Benfont likes this.
  5. AndyG

    AndyG Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,100
    Likes Received:
    915
    This is great @NikRudenko thanks for this. Really helpful. Im sure there is a whole suite of them coming with the beta :rolleyes:
     
  6. AaroArts

    AaroArts Miniboss Boxer

    Joined:
    Jun 22, 2016
    Messages:
    1,546
    Likes Received:
    826
    This is awesome @NikRudenko.
    Super excited for BB3. Great work!
     
  7. jmiller8031

    jmiller8031 Avid Boxer

    Joined:
    Feb 23, 2018
    Messages:
    218
    Likes Received:
    82
    I was wondering what Signal did. You really simplified things. Well done.
     
  8. thatguyminib

    thatguyminib Serious Boxer

    Joined:
    Jul 1, 2017
    Messages:
    552
    Likes Received:
    309
    Has anyone tried the component? I would love to see it in action? :D
     
  9. Christoph

    Christoph Miniboss Boxer

    Joined:
    Oct 4, 2015
    Messages:
    2,807
    Likes Received:
    2,309
    Now I just have to forward time a little so I can grab that beta already... :)

    @NikRudenko: I have no clue about JavaScript, any cool tip where I could find a good tutorial for rookies that would help me to understand the JavaScript used with Buildbox? I really would appreciate it.
     
  10. AppNasty

    AppNasty Miniboss Boxer

    Joined:
    Apr 14, 2016
    Messages:
    1,485
    Likes Received:
    890
    Been playing with Alpha 3 all day. Much more stable for sure. I can tell it's going to be one of the most popular game development softwares out.
    I know jack about java script myself but bb3 is encouraging me to learn up.
    Question: to make an object move upward is simple to do in bb2...but you're showing code to do it in bb3. Will simple functions like this be easy in bb3's future or will we HAVE to code?
     
  11. AndyG

    AndyG Miniboss Boxer

    Joined:
    Sep 25, 2015
    Messages:
    1,100
    Likes Received:
    915
    But isnt that the purpose of Nodes? You just select a pre-written Node called 'upward' or whatever and BOOM! done.
     
  12. jmiller8031

    jmiller8031 Avid Boxer

    Joined:
    Feb 23, 2018
    Messages:
    218
    Likes Received:
    82
    Don’t you just use the move node and put a value in whatever direction you want?
     
  13. NikRudenko

    NikRudenko Administrator Staff Member

    Joined:
    Sep 25, 2015
    Messages:
    179
    Likes Received:
    493
    Yes. In real life you would set a Position Animation node that will move my Door nice and smoothly.
    Example above was just illustration of how things works under the hood.
    Just so to be cleat. You don't have to code. But in case you want you can :)

    Eventually we will share API references and learning materials for BB3.

    And there is also one little surprise waiting on your guys during Beta Event. There is one Core feature we didn't showed yet.
    So stay tuned.
     
  14. MattWills

    MattWills Avid Boxer

    Joined:
    Nov 5, 2017
    Messages:
    223
    Likes Received:
    66
    This is fantastic. Thanks @NikRudenko can't wait to see what will be revealed at the event.
     
  15. AaroArts

    AaroArts Miniboss Boxer

    Joined:
    Jun 22, 2016
    Messages:
    1,546
    Likes Received:
    826
    Can’t wait for the event!
     
  16. jmiller8031

    jmiller8031 Avid Boxer

    Joined:
    Feb 23, 2018
    Messages:
    218
    Likes Received:
    82
    Something isn't adding up here. Why use an array if there is only one door in the scene? Are you just doing that just in case there is more than one? Couldn't you just find the tag and manipulate that object? Also, since this is a looping single scene example, I'm guessing scenes just go back to their default state once they leave the view. Correct?
     
  17. Rebel Studios

    Rebel Studios Avid Boxer

    Joined:
    Sep 25, 2015
    Messages:
    466
    Likes Received:
    280
    @NikRudenko is teasing us :p LMAO!! Can't wait for it. Seriously hope it still maintains the simplicity of things which makes Bbox so loveable for non programmes like us who don't know jack about coding or javascript. At the very least some node templates where we can learn some javascript whilst making games :)
     
  18. NikRudenko

    NikRudenko Administrator Staff Member

    Joined:
    Sep 25, 2015
    Messages:
    179
    Likes Received:
    493
    Function scene().find() is always return array. Sometimes it might be one or maybe hundreds of entities or maybe zero. Imagine you have enemies called "Alien" and you picking up powerup that will send them in to another dimension. So there is 145 Aliens currently on screen. When you call "this.scene().find("Alien")" and that will return 145 entities that you can send in to another dimension.
    In our Door case it was just a one door but the same script will work with hundreds doors as well
     
    AaroArts likes this.
  19. jmiller8031

    jmiller8031 Avid Boxer

    Joined:
    Feb 23, 2018
    Messages:
    218
    Likes Received:
    82
    Thanks for clarifying. That knowledge will come in handy.
     
  20. wesam_badr

    wesam_badr Miniboss Boxer

    Joined:
    Oct 10, 2015
    Messages:
    1,065
    Likes Received:
    479
    did you set a date for the event is it coming this week
     
    thatguyminib likes this.

Share This Page