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
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
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!
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?
hmmm.. maybe that's the easy way for spaces to survive. Let's see... Code: if (true) { let ent = ents[i]; }
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.
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
Is there a private messaging feature on this forum? I see something called "conversations." Maybe that's how private works. ??