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: 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. 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. 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 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.
@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?
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.
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?
This is great @NikRudenko thanks for this. Really helpful. Im sure there is a whole suite of them coming with the beta
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.
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?
But isnt that the purpose of Nodes? You just select a pre-written Node called 'upward' or whatever and BOOM! done.
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.
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?
@NikRudenko is teasing us 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
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