# Equal objects with independent variables in Game Maker?

Think of a situation with two distinct runners with different speeds. They will have to walk a circuit in a straight line with two obstacles (police).

Below is an illustration of the situation:

The problem I'm having is the following:

Assuming that runner two is faster than runner one, it is certain that he will reach the first hurdle earlier. Upon reaching this obstacle (detection event) he will be stopped for five seconds, long enough for the runner to reach him.

However the runner one will go through this obstacle without any loss of time, since the policeman is already taking care of the runner two.

Runner one still manages to get to the second obstacle with runner two still standing ... Then the problem arises because as they are equal objects the game assumes that the policeman is already taking care of the runner two, so the runner one passes straight through.

I would like to know how to do each object independently (detection event).

Sorry for the translation errors! Thanks!!!

Codes:

Movement (obj_control) =>

move_towards_point(obj_runner_01.x,obj_runner_01.y-1,obj_runner_01.manSpeed);
move_towards_point(obj_runner_02.x,obj_runner_02.y-1,obj_runner_02.manSpeed);

Collision detection (detector) =>

event_colision...

if obj_detector.detector_runner_01==false{
randomize(); //in the original case, there is a chance the runner will not be stopped
numRandom=irandom(99)+1;
obj_detector.detector=true;
}

if manColision==false{
if numRandom<=manAtrat*0{ //test value
manColision=true;
}else{
time_runner_01+=1;
if time_runner_01<150{
if obj_detector.stopped==false{ //variable that indicates that there is a stopped runner
move_towards_point(x,y,0);
}else{
time=150;
}
}else{
if pos==1{
move_towards_point(x,y+1,manSpeed);
}
if pos==2{
move_towards_point(x-1,y,manSpeed);
}
if pos==3{
move_towards_point(x,y-1,manSpeed);
}
if pos==4{
move_towards_point(x+1,y,manSpeed);
}

obj_detector.stopped=true;
manColision=true;
}
}
}

OBS- THE ORIGINAL CODE DOES NOT AND SO, CONTAIN OTHER THINGS, I EDITED THE NAMES OF THE VARIABLES TO MAKE SIMPLES THE UNDERSTANDING

To see if it is possible to have independent variables between equal objects I did a test =>

obj_detector (box with star) create event =>

test=irandom(10);

obj_detector (draw event) =>

draw_self();
draw_text(x-10,y,test);

Three different values ​​for the same variable in the same object!!!

• How do you move runners and how do you stop them? Show the code. – Dmi7ry Feb 24 '18 at 5:25
• I've seen something about instance variables, but I can not seem to get it right – Boneco Sinforoso Feb 26 '18 at 23:12

There are many ways to do it. For example:

obj_runner Create

spd = 1;
passed = array_create( instance_number(obj_stop) ); // array of passed points
finished = false;


obj_runner Step

if alarm[0] = -1 and !finished
y -= spd;


obj_runner Collision with police

var point_index = other.index;

if alarm[0] < 0 and passed[point_index] = 0
{
passed[point_index] = true;
alarm[0] = other.time;
}


obj_runner Collision with finish

finished = true;


obj_runner Alarm 0

/// empty


obj_stop (police) Create

time = room_speed;  // 1 second

if !variable_global_exists("count_number")
global.count_number = 0;

index = global.count_number++;


I made a small example, check it.

• I could not see the example – Boneco Sinforoso Feb 27 '18 at 21:40
• Click on the link, close popup window (if not loginned in the dropbox), then press download button. Then import runner.gmz into GMS. – Dmi7ry Feb 28 '18 at 2:40
• Asks to log in to Steam... I have been able to solve my problem in a different way, in a way that I think is simpler. Thanks for your response. I'll post the solution soon. – Boneco Sinforoso Mar 1 '18 at 0:26

I got the desired result using just one variable from an ini file.

This variable served to feed the detector vector, so that at the time of executing the event, it only performed on what was taking care of a runner.

ini_open("info.ini");
ini_close();