When I have in the script log('init'); I have no output in the log window. Does log() function, what I make wrong? Thanks for help.
I have a cube in the scene. The node "ChangeIt" is connected with the start-node. In the node ChangeIt I have this code: where is the error? Thanks for help (I am a learning newbie ;-) ) I have no log information in the log window.
Just comment your if condition and run, I am sure you will see log message. I suspect that if condition never allows going inside.
I commented it out, but nothing to see. Also the log in the init function do not print in the log window
Actually, init function is called and it's in the log, but scrolled very fast. So you thought it is not printing.
And you continuously got an error in update function at model.setColor(255,255,255); //It can find model to set color. Due to that error, its printing empty line, which not visible. Fix the model with right name then you wont see any error. let model = this.entity().component('ChangeColor');
You're not getting to your log call because there is an error in the code before it gets to it. I assume you are on a Mac and red errors are not printing out in the log window. There is no component "ChangeColor". "Changeit" is a component of the object ChangeColor. The code would execute if you put Changeit in place of ChangeColor, but that wouldn't work either because setcolor is a function of the entity, not the component, so your code should be as below: this.entity().setColor(255,255,255); _colorset = true; log('colorset');
I closed Buildbox and open the project new. Now I can see the init log. But not the update log. When I delete all other in the update I can also see that log. mmmmhhh what is false? I wanted change the color.
The code I gave you works and sets the color of the object to whatever you put in setColor()....unless you're trying to do something else that I don't understand.
I just want to clarify. Do you want to change the color of the object where you're making the setColor call, or are you trying to change the color of an object that's not the object you're making the call from?.
I want to find a way to change the color of all objects in the scene. Also I search a possibility to have the several objects (entity) with different colors from the same model. I can imagine, that I set a color attribute in the model, so I can on the set the color for each object in the scene. Or I have one object as colorChanger, and from this object script I change all object in the scene, or a mix from all of this. Short: I search the perfect solution for changing colors without duplicate objects. The colors in my game should change from scene to scene or level to level. Thanks for your help.
Here is the code example from the API that lets you loop through all the objects of a specific name and change the attributes of each one(I've changed the setPosition call to the setColor call that you would want). My guess is there's a way to use this.scene() to get a list of all objects, but it's not in the API. I suggest you need to write support or PM Nik directly and ask if there's a way to get a list of all objects in a scene. let ents = this.scene().find('Obstacle1'); for(let i=0; i<ents.length; i++) { let ent = ents; ent.setColor(R,G,B); } Of course if there's no solution right now from BB, the kludge way of doing it right now is write a function as below and call it for each object in your scene. I would also pass in the color to make the function more flexible, so if you aren't trying to set them all to the same color you could also do that with the same function. Of course the biggest drawback to this is not just that it's messy but you'd have to go back and add/delete a setObjectColor call to the node for every object you added/deleted to/from the scene. function setObjectColor(objectName, colorR, colorG, colorB) { let ents = this.scene().find(objectName); for(let i=0; i<ents.length; i++) { let ent = ents; ent.setColor(colorR, colorG, colorB); } } setObjectColor(object1, 125, 200, 5); setObjectColor(object2, 125, 200, 5); setObjectColor(object3, 100, 255, 10);
I made a cube "ChangeColors". In this cube I connect the node "ChangeColor" to the start-node. I added an attribute "Path" (Modelname). I will add this attribute later for all Models in the scene. I can put this cube "ColorChange" in all scenes and in the attributes I set the R,G,B for the colors I want in this scene. Future idea: I add in all Models the attribute "Color". When in an object (entity) there is a value, then the "ColorChange" script take this value otherwise the color set in ColorChange attribute.