• 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!

issue with "other"

R

Rick-V

Guest
hello i'm pretty new on GMS and recently i found a problem:
i was trying to make a movement like chess, here is the code, casella_movimento stay for "movement_slot"

step event:
Code:
mb_left = mouse_check_button(mb_left);

///slots
if(mov == true){
instance_create(x+40,y,obj_casella_movimento);
instance_create(x,y+40,obj_casella_movimento);
instance_create(x-40,y,obj_casella_movimento);
instance_create(x,y-40,obj_casella_movimento);
    mov = false;
}
slot collision event:
Code:
///movement
if(mb_left){
    x = other.x;
    y = other.y;
    mov = true;
}
the problem is that the player doesn't move at the slot's x, y.
Could anybody help me please?
thanks a lot!
 
J

JFitch

Guest
mb_left is a built in constant. You can't use it as a variable.
 
R

Rick-V

Guest
actually in my code i wrote mb_left in italian (mb_sinistra), so the built in constant is not the problem:(
 
J

JFitch

Guest
Code:
if(mb_sinistra){
   x = other.x;
   y = other.y;
   mov = true;
}
Your code is saying "if the object calling this code is colliding with a slot and if the left mouse button is held with the mouse anywhere on the screen, move the object calling this code to the slot's position." Is that what you're trying to do?
 
R

Rick-V

Guest
thanks, i tried to fix it but it doesn't seem working anyway
Code:
///movimento
if(mb_sinistra){
    if(position_meeting(mouse_x,mouse_y,obj_casella_movimento)){
        x = other.x;
        y = other.y;
        mov = true;
    }
}
 

Paskaler

Member
You'll have to get the ID of the instance:

Code:
///movimento
if(mb_sinistra){
  var inst = instance_place(mouse_x, mouse_y, obj_casella_movimento);
 if(instance_exists(inst)){
       x = inst.x;
       y = inst.y;
       mov = true;
   }
}
Also, other is only usable from within a with statement to target the instance outside the statement and in the collision event to target the instance the instance that called the event collided with.
 
R

Rick-V

Guest
You'll have to get the ID of the instance:

Code:
///movimento
if(mb_sinistra){
  var inst = instance_place(mouse_x, mouse_y, obj_casella_movimento);
 if(instance_exists(inst)){
       x = inst.x;
       y = inst.y;
       mov = true;
   }
}
Also, other is only usable from within a with statement to target the instance outside the statement and in the collision event to target the instance the instance that called the event collided with.
thanks! now it works perfectly!
I have still a question: it's like the mask of the slot is moved from the center of the sprite(both sprites are centered)
 
Top