C
catchpharse
Guest
Hi there fellow coders,
I am totally new to GameMaker but not to programming in general, so please point me to a ressource of knowledge, if my question turns out to be pointless
I am trying to accomplish the following:
a) define a toggle object (here called obj_dice)
b) define a background object (here called obj_dice_bg)
c) generate two instances of toggles and two of background, such that the sprite of the first backgound is toggeled (on) by the first switch and the second by the second switch.
I did this by adding the following code to a step event of obj_dice:
Additional Info:
The stateIndex is currently computed mod 2, but there may be more states later than two.
My question is now:
Is there a smarter way to pass the key for matching the nth instance of object A to the nth instance of object B than changing a global variable? How do you guys do that? Write a third class with a member function/variable that takes care of that?
Thank you for your thoughts and ideas, I am looking forward to learn from your experience!
catchphrase
I am totally new to GameMaker but not to programming in general, so please point me to a ressource of knowledge, if my question turns out to be pointless
I am trying to accomplish the following:
a) define a toggle object (here called obj_dice)
b) define a background object (here called obj_dice_bg)
c) generate two instances of toggles and two of background, such that the sprite of the first backgound is toggeled (on) by the first switch and the second by the second switch.
I did this by adding the following code to a step event of obj_dice:
Code:
if (mouse_check_button_released(mb_left) && position_meeting(mouse_x,mouse_y,id)) {
global.checked_id=instance_id;
stateIndex+=1;
stateIndex = stateIndex mod 2;
global.key = key;
if (stateIndex==0) {
with(obj_dice_back)
if (key==global.key)
{ sprite_index=7; }
}
if (stateIndex==1) {
with(obj_dice_back) {
if (key==global.key)
{ sprite_index=6;}
}
}
}
The stateIndex is currently computed mod 2, but there may be more states later than two.
My question is now:
Is there a smarter way to pass the key for matching the nth instance of object A to the nth instance of object B than changing a global variable? How do you guys do that? Write a third class with a member function/variable that takes care of that?
Thank you for your thoughts and ideas, I am looking forward to learn from your experience!
catchphrase