P
pZq10chars
Guest
Hi,
I have a sprite consisting of 8 images of buttons. every 2nd button is off-state and next to i the on-state button.
So sprite
Then i have the sprite assigned into a obj_button And i have placed the 4 buttons into an instance layer.
So i have 4 visible buttons on screen.
In the obj_button create event i have the script to turn all buttons to its corresponding off state
And this seems to work ok. All buttons will get each corresponfing image / color that is drawn in the sprite.
Now the problem im having is, that when i try to randomize what button goes on (one at a time delayed by 1 second, the program goes weird)
So i have a step event for obj_button and there i have
then i have and alarm 0 event with only a comment and a new alarm[0] = room_speed *1; to get the alarm repeated... so eg
and i know, it could be without the *1 but its there since if i need to change it to a constant or #macro or similar...
So anyways the main problem is. That the buttons will not be turned on one at a time. They are turned on 1 to 4 at once and thats is the problem im trying to understand. Why does this do this ?
When i put a show_message(string(value)); before the with(instance...){} or after it, it will prompt 4 times a value, and after fourth time, the buttons will react based on what values it did randomly give. It may be 1, 1, 2, 3 and thus all other than first button will turn on. and so on. But why. What am i doing wrong ?
and to recap. I want that one button is turned on at a time -> wait 1 seconds. go off, wait 1 second, then an other random button on for 1 second and so on.
I have a sprite consisting of 8 images of buttons. every 2nd button is off-state and next to i the on-state button.
So sprite
Code:
image1 = button1OFF
image2= button1ON
image3= button2OFF
image3= button2ON
...
image8=Button4ON
So i have 4 visible buttons on screen.
In the obj_button create event i have the script to turn all buttons to its corresponding off state
Code:
#macro BUTTON1OFF 0
#macro BUTTON1ON 1
#macro BUTTON2OFF 2
#macro BUTTON2ON 3
...
randomise(); // create new random seed on every run.
// find first instance of obj_button and change the image_index of it to defined value. (4 separate withs)
with(instance_find(obj_button,0)) {image_index = button1OFF }
...
with(instance_find(obj_button,3)) {image_index = button4OFF }
Now the problem im having is, that when i try to randomize what button goes on (one at a time delayed by 1 second, the program goes weird)
So i have a step event for obj_button and there i have
Code:
var value = irandom_range(0,3);
with (instance_find(obj_button, value)) {
// eg. if instance 0 -> the image to show (turn on button for instance 0)
// we get 0x2+1 = 1 which means BUTTON1ON state sprite image. and so foth
image_index = (value*2)+1 ;
}
alarm[0] = room_speed * 1;
then i have and alarm 0 event with only a comment and a new alarm[0] = room_speed *1; to get the alarm repeated... so eg
Code:
/// comment
alarm[0] = room_speed *1;
So anyways the main problem is. That the buttons will not be turned on one at a time. They are turned on 1 to 4 at once and thats is the problem im trying to understand. Why does this do this ?
When i put a show_message(string(value)); before the with(instance...){} or after it, it will prompt 4 times a value, and after fourth time, the buttons will react based on what values it did randomly give. It may be 1, 1, 2, 3 and thus all other than first button will turn on. and so on. But why. What am i doing wrong ?
and to recap. I want that one button is turned on at a time -> wait 1 seconds. go off, wait 1 second, then an other random button on for 1 second and so on.
Last edited by a moderator: