Buildbox 3.0 Javascript Api And Tutorials

Discussion in 'Official Announcements' started by NikRudenko, Sep 7, 2018.

  1. NikRudenko

    NikRudenko Administrator Staff Member

    Joined:
    Sep 25, 2015
    Messages:
    176
    Likes Received:
    487
    Hello everyone.
    Here is our API reference for all scripted nodes.
    http://download.buildbox.com/buildbox/assets/documentation/api-3.0.0.2250.html
    There is few tings I want to improve and maybe give for code snippets. So I'll continue working on it and improve over time.

    Also our friend Zack is back on track with new video tutorials.
    Here is brand new video tutorial on how to make your own node in Beta2

    We all can expect more videos from him very soon.... ;)

    PS. If you find some typo or error in API Ref please ping me in private and I'll fix it.
    Really appreciate :)
     
  2. Steddyman

    Steddyman Boxer

    Joined:
    Sep 3, 2018
    Messages:
    49
    Likes Received:
    28
    Brilliant. Thank you for the API documentation. I've been asking support for this all week and here it is. It will make the system so much more powerful.
     
  3. Steddyman

    Steddyman Boxer

    Joined:
    Sep 3, 2018
    Messages:
    49
    Likes Received:
    28
    Actually looking at the API it is missing some critical aspects, namely the in-built nodes where the script is not accessible (presuming these are written in a lower level language).

    For example the 'If Collide' component is used in this way in the Link component of the Pyramid object:

    Code:
    function signal(name, value){
    
        if(value){
            let collide = this.entity().component('If Collide');
            let obj = collide.collisionObject();
            obj.addChild(this.entity());
        }
    }
    I need to get from that collisionObject to the actual game object behind it, but it does not have an entity() sub object, so what is it? I would expect this kind of detail to be included in the API documentation. I actually need this information for a game I am making and if there is no way to get it I will unfortunately have to switch back Unity (which will take a lot more work).
     
  4. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    286
    Likes Received:
    193
    @NikRudenko Thanks Nik. How to ping you privately?
     
  5. LBPToo

    LBPToo Avid Boxer

    Joined:
    Nov 1, 2016
    Messages:
    233
    Likes Received:
    127
    Great job on the API Nik, this is going to be really helpful(understatement)!

    Bill
     
    particles likes this.
  6. NikRudenko

    NikRudenko Administrator Staff Member

    Joined:
    Sep 25, 2015
    Messages:
    176
    Likes Received:
    487
    Code:
            let collide = this.entity().component('If Collide');
            let obj = collide.collisionObject();
    }
    collisionObject will return Entity. collisionObject is little confusing name for it. I'll rename it to collisionEntity (that is why it is not in documentation yet).
    so that OBJ variable will be simply entity. and you can do all the magic you can do with any Entity (set position or look for a component)
     
  7. Steddyman

    Steddyman Boxer

    Joined:
    Sep 3, 2018
    Messages:
    49
    Likes Received:
    28
    LBPToo likes this.
  8. NikRudenko

    NikRudenko Administrator Staff Member

    Joined:
    Sep 25, 2015
    Messages:
    176
    Likes Received:
    487
    There is alternative way of sending data between nodes (aka components). Even if nodes are from different objects.
    You can find component from entity and call directly signal('name', entity) and catch it form other side.

    Code:
    //NODE A 
    let comp = this.entity().component('MyScriptB');
    comp.signal('MySignalFromA', this.entity() ); // second parameter can be anything
    
    //NODE B
    function signal(name, value){
       if(name=='MySignalFromA'){
         value.setPosition(0,1,0); // value is a Entity since we passed entity via Node A
       }
    }
    
    I'm using this approach for cross Entity communication. When I need to send signal to other Entity (like send signal to enemy about bullet hit)
     
    weboha and Mohamed Sakr like this.
  9. Mohamed Sakr

    Mohamed Sakr Boxer

    Joined:
    Aug 16, 2018
    Messages:
    18
    Likes Received:
    2
    great way of sending messages, I have a crash when I cloned a light entity (unless light isn't an entity)
    what I want to do: on collision, generate a light object for a period, then remove it.
    also how to access specific parameter in the entity? (parameter not attribute)

    some code:
    Code:
    function signal(name, value){
    log("val = " + value);
    if(value)
    {
    let light = this.scene().find('Light Sun');
    log(light);//prints "?", how to print data type and object methods?(I can do this in Python)
    if(light)
    {
    let collisionLight = this.scene().clone(light);//crash
    if(collisionLight)
    {
    let pos = collisionLight.position();
    collisionLight.setPosition(pos.x, pos.y, pos.z + 10);
    log("pos = (" + pos.x + ", " + pos.y + ", " + pos.z + ")");
    }
    }
    }
    
     
  10. Mohamed Sakr

    Mohamed Sakr Boxer

    Joined:
    Aug 16, 2018
    Messages:
    18
    Likes Received:
    2
    NikRudenko likes this.
  11. PendingFox

    PendingFox Boxer

    Joined:
    Aug 21, 2018
    Messages:
    12
    Likes Received:
    3
    Still waiting for at least some sort of Animation controlling and Simple mesh manipulating methods :| at least vertex manipulation
     
  12. Mohamed Sakr

    Mohamed Sakr Boxer

    Joined:
    Aug 16, 2018
    Messages:
    18
    Likes Received:
    2
    after more testing, I see that the entity object got only 1 method "object Entity", and if I used an object which got shared name (for example object named "Cube" and there are 3 cubes, there will be 3 methods for that entity variable, 1 for each cube entity)
    so no luck with getting methods' names
     
  13. Mohamed Sakr

    Mohamed Sakr Boxer

    Joined:
    Aug 16, 2018
    Messages:
    18
    Likes Received:
    2
    sorry for my dumb tests, at the end I found it, I was doing it wrong.
    here is the correct function to print every variable in the object.
    Code:
    function getMethods(obj) {//this is used on a list returned by  this.scene().find('object name');
      var result = [];
      var myobj = obj[0];//use only on first object of the list, I was missing this as I thought it is using a single object
      for (var id in myobj) {
            result.push(id + ": " + myobj[id].toString());
            last = result[result.length - 1]
            log(last);
      }
      return result;
    }
    
    and here is the print
    Code:
    component: function component() {
    [native code]
    }
    physics: function physics() {
    [native code]
    }
    position: function position() {
    [native code]
    }
    worldPosition: function worldPosition() {
    [native code]
    }
    rotation: function rotation() {
    [native code]
    }
    rotationQuat: function rotationQuat() {
    [native code]
    }
    transform: function transform() {
    [native code]
    }
    remove: function remove() {
    [native code]
    }
    addRemoveCallback: function addRemoveCallback() {
    [native code]
    }
    setTexture: function setTexture() {
    [native code]
    }
    setColor: function setColor() {
    [native code]
    }
    color: function color() {
    [native code]
    }
    setPosition: function setPosition() {
    [native code]
    }
    setRotation: function setRotation() {
    [native code]
    }
    setRotationQuat: function setRotationQuat() {
    [native code]
    }
    setScale: function setScale() {
    [native code]
    }
    scale: function scale() {
    [native code]
    }
    linkedEntities: function linkedEntities() {
    [native code]
    }
    children: function children() {
    [native code]
    }
    addChild: function addChild() {
    [native code]
    }
    setAnimate: function setAnimate() {
    [native code]
    }
    find: function find() {
    [native code]
    }
    name: function name() {
    [native code]
    }
    
     
    particles likes this.
  14. Mohamed Sakr

    Mohamed Sakr Boxer

    Joined:
    Aug 16, 2018
    Messages:
    18
    Likes Received:
    2
    ok now I found out why it was crashing on clone, I was passing a list instead of entity to the function. sorry for spamming the thread, but I hope no one else hit these mistakes as I got through them all :), still new to JavaScript
    though there is still one question:
    how to access specific parameter in the entity? (parameter not attribute) like "Light Color"
     
  15. MattWills

    MattWills Avid Boxer

    Joined:
    Nov 5, 2017
    Messages:
    217
    Likes Received:
    62
    Please can this be linked from within BB3 as the other tutorials are. Thanks
     
  16. Steddyman

    Steddyman Boxer

    Joined:
    Sep 3, 2018
    Messages:
    49
    Likes Received:
    28
    Thank NIk. Yes, I have seen those patterns in use and I can adapt my code to work this way.

    Is there any reason why it doesn't simply work setting the output of one node to be an object and the input of another node to an object on the same graph and then using emitSignal to output an object? It seems like it should and the benefit would be synchronised signals that are more logical on the same graph? I don't want the target to be active in the graph until the signalling event.
     
  17. PendingFox

    PendingFox Boxer

    Joined:
    Aug 21, 2018
    Messages:
    12
    Likes Received:
    3
    It shouldn't crash anyway, it should give a null reference or incompatible type error
     
    NikRudenko likes this.
  18. Mohamed Sakr

    Mohamed Sakr Boxer

    Joined:
    Aug 16, 2018
    Messages:
    18
    Likes Received:
    2
    true, but may be internally in that function it tries to access the entity without checking object type
     
  19. Mohamed Sakr

    Mohamed Sakr Boxer

    Joined:
    Aug 16, 2018
    Messages:
    18
    Likes Received:
    2
    after long testing, cloning works fine with any object, except the light object, then I realized I can't even clone it in the 3d view.
    any idea when will you add a light object to play with? (may be a cone light, an omni light, and a parallel light).
     
  20. NikRudenko

    NikRudenko Administrator Staff Member

    Joined:
    Sep 25, 2015
    Messages:
    176
    Likes Received:
    487
    Light is not supposed to be copied. There is one global Directional Sun Light that produce shadows and direct lightning. If you want some sort of flash light you can use dedicated object with Glow texture on it.
    BTW. Thanks for this Light case. Will add light check to prevent crashes.
     

Share This Page