I am trying to figure out how to enable and disable variables.
Hi @ALUCARD!
// enable entity
TheEntity.enabled = true;
// disable entity
TheEntity.enabled = false;
// toggle between enable and disable
TheEntity.enabled = !TheEntity.enabled;
It’s not clear to me what you try to do with Deleto
.
you see, what im looking for is that every frame TheEntity will disable the object, But i want to be able to turn that variable off with another variable
Sorry, but I’m still not sure what you mean.
Something like this?
if (Deleto.enabled === true) {
TheEntity.enabled = false;
}
so my ultimate goal is that when triggered this script will disable an entity with a specific name, but that entity is in another scene. So I was planning on using a variable to disable a named entity every frame, but the variable is not enabled until activated by another variable.
think of it as a global lightswitch. If triggered then disable named entity every frame, but dont disable until triggered.
I don’t think you can disable an entity in another scene, because basically there is no other scene until you switch to it. Maybe you can create a global variable and disable the entity when you switch to it (so with an if statement in the initialize function), but I’m not sure if the global variable still exists.
To try this, you need to create a global variable after the first line of your script and not in the update function like you do in your code above. If this doesn’t work, there is also an ability to store a variable in the brower, but I’m not sure how to do this exactly.
Well thank you for trying
I create a quick test myself and it seems that the variable still exist in the other scene. You can create for example a global boolean to use as your swich like below.
1. Create your global boolean
var YourScript = pc.createScript('yourScript');
// create your global boolean
var globalSwitch = false;
// initialize code called once per entity
YourScript.prototype.initialize = function() {
};
// update code called every frame
YourScript.prototype.update = function(dt) {
};
2. Set your global boolean
var YourScript = pc.createScript('yourScript');
// initialize code called once per entity
YourScript.prototype.initialize = function() {
};
// update code called every frame
YourScript.prototype.update = function(dt) {
if (this.app.keyboard.isPressed(pc.KEY_SHIFT)) {
globalSwitch = true;
}
};
3. Use your global boolean in the other scene
var YourScript = pc.createScript('yourScript');
// initialize code called once per entity
YourScript.prototype.initialize = function() {
if (globalSwitch === true) {
this.app.root.findByName('YourEntity').enabled = false;
}
};
// update code called every frame
YourScript.prototype.update = function(dt) {
};
This is absolutely perfect. Thank you.