Q: how to make 3 objects do the same thing?

mutazoid

Member
I have 3 objects. When one is clicked on how do I make it and the other 2 do the same kind of movement?
I was thinking making when left mouse clicked on
make a global.variable = a number
then
each object in the step event if global.variable = number { run script }

Is there a better way to do this idea?
Thanks for any tips :)
 
R

Ryzzax

Guest
hmmm... Well, what kind of movements? Rotation or just moving like left, right, up and down? Or both?

Edit: Or something else?
 

Bingdom

Googledom
You can store the instances into a array

Create event
Code:
object[0] = instance_create(x,y,clone);
object[1] = instance_create(x,y,clone);
Trigger event
Code:
for (var i = 0; i < array_length_1d(object); i++) {
    with(object[i]) {
        //Run Script
    }
}
Edit:
If they are all the same object, and you have only 3 in the room, then you simply can do this
Code:
with(clone) {
    //Run Script
}
 

mutazoid

Member
actually one will make them both rotate 90 degree then when another is clicked they will both move forward
 

M. Idrees

Member
Do like this
if mouse_check_pressed(mb_left)
{
object2.rotation = self rotation; // for example
object2.x += 2; // for example
}
 
Last edited:
R

Ryzzax

Guest
well, in the first object, you could say;
Code:
image_angle = image_angle + 90; // for the object you are running this code
other.id.image_angle = image_angle + 90; // for any other object
in the second object;
Code:
hspeed = 1; //for the object you are running this code
other.id.hspeed = 1; // for any other object
Of course, my lines of code are not complete, since I don't really know your game, but I think you get the idea how to set a speed,image_angle, direction, etc , to another instance. Right? Hope so ^^
 

mutazoid

Member
Ya that would work and that is my general understanding level how I could do this but Id rather have the rotation of the object to be smooth. So for the first object I did this but I have no idea how to make the second object do this too.


Create Event:
execute code:
var_rspeed = 5; //the speed of rotation, how fast it rotates
var_point_dir = 0; //the variable that will store what direction to rotate to
var_is_rotating = 0; //is it rotating, used in the STEP event to rotate the object

Step Event:
execute code:
// for smooth rotation
if (var_is_rotating == 1) //if its set to rotate the object
{
image_angle += var_rspeed;

if var_point_dir=image_angle
{
var_is_rotating=0;
}
}

Mouse Event for Left Pressed:
execute code:
// for smooth rotation
if var_is_rotating=0
{
var_is_rotating = 1; //set to true
var_point_dir = image_angle + 90; //the angle to rotate to, add 90 degrees to current angle
}
 

Tsa05

Member
Stealing a snippet from Bingdom,
Mouse left pressed would have the stuff you already have, plus this:
Code:
for (var i = 0; i < array_length_1d(object); i++) {
    with(object[i]) {
        var_is_rotating = 1;
        var_point_dir = image_angle+90;
    }
}
 
Top