L
Lenchantin
Guest
Hey all.
We're trying to make something where, when an event is activated and a script is called, the script searches out all of the objects on a layer, they look for a specific variable inside of the variable, and if it's there, it changes the variable. The idea here is that the script disables specific code on ANY object with the variable. Here's how I have it set up:
Any object that I want to disable has this code:
Now, here's the event that calls the code. In this case, if you press a button, it moves a camera, and does several other things. If I press this one button object, any object with the above code disables or enables. The important lines here are the ones with 'layerDisable'.
And here's the script that's supposed to seek out the objects on any layer specified, and is supposed to change the value to either true or false, to make the code in the first two blocks above work or not work.
We've tried writing the code several different ways, but to no avail. The code in the script seems to pass null values. No crashes, though. At best, we get an array of several numbers, for instance 24, 15, 16, 17, when we debug. We can't separate the items in a layer with the obj_enabled value and the objects that don't.
What we need it to do:
We're trying to make something where, when an event is activated and a script is called, the script searches out all of the objects on a layer, they look for a specific variable inside of the variable, and if it's there, it changes the variable. The idea here is that the script disables specific code on ANY object with the variable. Here's how I have it set up:
Any object that I want to disable has this code:
Code:
// Create Event
obj_enabled = true;
Code:
// Code I want to be able to enable / disable. In this case, it's in a Left Down event.
if (obj_enabled) {
// whatever code happens here only if obj_enabled is true
}
Code:
// if you click on a menu button...
if menuCameraDart.x == 1460 {
menuCameraDart.x -=500;
global.c_menuOpen = true;
audio_play_sound(clickOn_a,0,0);
menuTriggerButton.sprite_index = menuButtonPressed_s;
menuTriggerButton.image_speed = 1;
menuScreenDim.y = 0;
layerDisable("gameObjectsTop", false);
}
else {
menuCameraDart.x +=500;
global.c_menuOpen = false;
audio_play_sound(clickOff_a,0,0);
menuTriggerButton.sprite_index = menuButtonClosePressed_s;
menuTriggerButton.image_speed = 1;
layerDisable("gameObjectsTop", true);
}
Code:
// Script which does... nothing
/// layerDisable("layer name", true or false)
layerName = argument0;
tOrF = argument1;
var a = layer_get_all_elements(layerName);
for (var i = 0; i< array_length_1d(a); i++;) {
if variable_instance_exists(a[i], "obj_enabled") {
obj_enabled = tOrF;
}
}
What we need it to do:
- Seek out any object in a specific layer that has a variable called obj_enabled
- If it has the variable, change the variable to either true or false
- If it doesn't have the variable -- then move along. Nothing to see here.