Does Log() Function?

Discussion in 'Buildbox 3.0' started by fredi, Oct 25, 2018.

  1. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    typo... You want (in both chunks of code).
    Well, well.. it seems the forum post is our enemy, at bit.
    It eats square brackets that mean array instance instead of letting them pass because they contain no formatting command.

    @DanFarfan

    Okay, that's the trick.. space after the open square bracket and maybe space before the close square bracket
     
    Last edited: Oct 26, 2018
    LBPToo likes this.
  2. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    Well, there is one more design construct you can use in this situation... auto registration.

    Add a function to your common script (ChangeColor) that looks something like this


    var ent_name_arr = []; // entity name array

    function registerMe(ent) {

    if ( ! ent ) {
    log(`ChangeColor.registerMe ERROR: ent can't be null`);
    return;
    }
    if ( ent_name_arr.indexOf(ent.name()) == -1 ) {

    ent_name_arr.push(ent.name());
    log(`ChangeColor.registerMe this scene has ${ent.name()}`);
    }
    }
    component.registerMe = registerMe; // this line allows the function to be "seen" and called.

    //THEN, in the init() function of each entity you want to change colors of..

    function init() {

    // I usually break this line into several to be careful
    // this works for ground too, by the way.
    this.scene().find("ChangeColors")[0].component("ChangeColor").registerMe(this.entity());
    }

    Now, your game as a list of entity names that appear in the current scene. Looping through those names works great with the code LBPToo gave you.
    Also, arrange your objects so the color cube is last in the list (not the entities, the objects). That way all the objects will be init-ed and registered by the time the color cube is init-ed. The objects init-ed before the color cube WILL be able to both find and call the .registerMe() function before the color cube has been init-ed. (thank goodness!)

    There are a lot of very interesting things you can do after this is in place.
    Good Luck!

    @DanFarfan
     
    LBPToo, fredi and particles like this.
  3. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    @DanFarfan The way you explaining is soo good.
     
    DanFarfan likes this.
  4. fredi

    fredi Avid Boxer

    Joined:
    Feb 3, 2016
    Messages:
    100
    Likes Received:
    11
    cool, congrats!
     
  5. fredi

    fredi Avid Boxer

    Joined:
    Feb 3, 2016
    Messages:
    100
    Likes Received:
    11
    I can change the color of all objects now with my object ColorChange.

    BUT when I get the 'Path' objects with this.scene().find('Path') in the script from ColorChange, I get not only the objects in the actual scene, I get also the objects in the scenes before.

    I have this scenes A1, A2, A3. When I add the ColorChange in Scene A3 (I expect to change the colors from A3) then playing in scene A1 after some seconds the color change, because the ColorChange object in Scene A3 is created. How can I change only the objects in scene A3? Any idea? Thanks!
     
  6. LBPToo

    LBPToo Avid Boxer

    Joined:
    Nov 1, 2016
    Messages:
    233
    Likes Received:
    141
    Thanks for that @DanFarfan! Thanks for the catch on the brackets too, I'd never noticed that before. Maybe if I put the code in a code block it wouldn't do that?
     
    Last edited: Oct 27, 2018
  7. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    hmmm.. maybe that's the easy way for spaces to survive. Let's see...

    Code:
    if (true) {
       let ent = ents[i];
    }
     
  8. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    yep. That's the ticket. Well done. I didn't even notice that option before. (it's on the + icon... insert -> code )
    But the code block begin and end [ CODE ] [ /CODE ] can just be typed in.
     
    Last edited: Oct 27, 2018
    LBPToo likes this.
  9. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    Thanks! I appreciate the feedback.
    I like what you're doing with BB3.
    We seem to have complementary skills.
    Maybe we should figure out a way to work together and make some serious money in this mobile gaming market.
    I recently completed a contract job on a NASA satellite project. I haven't decided what project is next.

    @DanFarfan
     
    particles likes this.
  10. LBPToo

    LBPToo Avid Boxer

    Joined:
    Nov 1, 2016
    Messages:
    233
    Likes Received:
    141
    Figured it might. I've just been too lazy to use it, but now I have a reason to do it. Thanks.
     
    DanFarfan likes this.
  11. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    Thankyou @DanFarfan. Intersting, Sure.
     
    Last edited: Oct 28, 2018
    DanFarfan likes this.
  12. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    Is there a private messaging feature on this forum?
    I see something called "conversations." Maybe that's how private works. ??
     
    particles likes this.
  13. LBPToo

    LBPToo Avid Boxer

    Joined:
    Nov 1, 2016
    Messages:
    233
    Likes Received:
    141
    Yes, that's it.
     
    particles and DanFarfan like this.
  14. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    42
    thanks!
     
  15. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    Yes. conversation is for private messaging.
     

Share This Page