Hi everybody,
In my game, I need to switch the position of two objects when a certain condition is met. The code below (from the step event of the object being switched) works most of the time, but sometimes doesn't. I can't figure out the reason for this inconsistency, but I think it has something to do with accessing the position value of the other object, as when I set the position values to arbitrary numbers it works every time. pos4 and pos5 are variables storing the id's of the objects I'm trying to switch with. Anyone have any ideas where my mistake could be?
In my game, I need to switch the position of two objects when a certain condition is met. The code below (from the step event of the object being switched) works most of the time, but sometimes doesn't. I can't figure out the reason for this inconsistency, but I think it has something to do with accessing the position value of the other object, as when I set the position values to arbitrary numbers it works every time. pos4 and pos5 are variables storing the id's of the objects I'm trying to switch with. Anyone have any ideas where my mistake could be?
GML:
if (abs(pos7.x-x) >= gapw/2){
//set temporary switch varaibles
tempx = initialx;
tempy = initialy;
if pos7.x-x >= 0{
//switch positions with one object
initialx = pos5.initialx;
initialy = pos5.initialy;
pos5.initialx = tempx;
pos5.initialy = tempy;
} else {
//switch positions with other object
initialx = pos4.initialx;
initialy = pos4.initialy;
pos4.initialx = tempx;
pos4.initialy = tempy;
}
}
Last edited: