• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM If statement problems

V

VansiusProductions

Guest
Hi guys,
This is my code. mouseTouch is a variable when it detects that the mouse is touching the object. groupHover is a variable that holds the value of the image_index of the touching object. It will be none if it's not touching any object. Then groupHover's value will be set to either groupSelectedA or groupSelectedB and create 2 instances. groupHover is automatically set to "none" when the object is not touching the mouse. When I click for the first time, the instance for A is created, when I click for the second time and so one nothing happens. Any help?
Code:
if (global.mouseTouch = 1 && global.groupHover != "none") {
if (global.groupSelectedA = "none") {
global.groupSelectedA = global.groupHover
with (instance_create(352,62,obj_group)) {image_speed = 0;image_index = global.groupSelectedA}

exit;
}
if (global.groupSelectedB = "none") {
global.groupSelectedB = global.groupHover
with (instance_create(352,222,obj_group)) {image_speed = 0;image_index = global.groupSelectedB}

exit;
}
}
 

Binsk

Member
A couple tips to help you get more help in the future:
1. Explain what you are trying to accomplish in your post. You gave code, which is good. You told us what is wrong and what you tried, which is awesome. You just left out what things are supposed to do which leaves us trying to decipher from your code. This also leads to my next point.

2. Make the code readable. I don't know if it is just me but holy cow, I had a really hard time finding where blocks ended and what blocks were in other blocks. It is fine to press "enter" on the keyboard a few more times when writing code. ;)

Looking at your code, I can't seem to see what could be going wrong. I am wondering if the problem may be elsewhere. Are you sure that group A is not being reset to none somewhere? Are you sure groupHover is being set correctly?

Would you mind giving us your mouse code so we can see when you set those variables? That way we can take a look just in case.
 
Z

zircher

Guest
Also, setting a break point and using the debugger to look at your variables might give you some insight to what's going on.
 
V

VansiusProductions

Guest
A couple tips to help you get more help in the future:
1. Explain what you are trying to accomplish in your post. You gave code, which is good. You told us what is wrong and what you tried, which is awesome. You just left out what things are supposed to do which leaves us trying to decipher from your code. This also leads to my next point.

2. Make the code readable. I don't know if it is just me but holy cow, I had a really hard time finding where blocks ended and what blocks were in other blocks. It is fine to press "enter" on the keyboard a few more times when writing code. ;)

Looking at your code, I can't seem to see what could be going wrong. I am wondering if the problem may be elsewhere. Are you sure that group A is not being reset to none somewhere? Are you sure groupHover is being set correctly?

Would you mind giving us your mouse code so we can see when you set those variables? That way we can take a look just in case.
What it's supposed to do is that when the player clicks on an instance that is to the left, if groupSelectedA is empty it will set groupHover to groupSelectedA and create an instance, if it is not then it will set it to groupSelectedB and create a different instance.
Sorry for the bad formatting, here's a better one:
Code:
if (global.mouseTouch = 1 && global.groupHover != "none") {
    if (global.groupSelectedA = "none") {
        global.groupSelectedA = global.groupHover
        with (instance_create(352,62,obj_group)) {image_speed = 0;image_index = global.groupSelectedA}
        exit;
    }
    if (global.groupSelectedB = "none") {
        global.groupSelectedB = global.groupHover
        with (instance_create(352,222,obj_group)) {image_speed = 0;image_index = global.groupSelectedB}
        exit;
    }
}
Here are the codes for the other events:
Mouse Enter:
Code:
global.mouseTouch = 1
if (x < 352) {global.groupHover = image_index}
the (x < 352) is to detect if the player is clicking the instances that are to the left and not the instances that we just created in the above code,
Mouse Leave:
Code:
global.mouseTouch = 0
global.groupHover = "none"
Room Start:
Code:
with (instance_create(32, 62, obj_group)) {image_speed = 0;image_index = 0;}
visible = 0;
global.groupSelectedA = "none"
global.groupSelectedB = "none"
The visible is to hide the main object itself
 
Top