alarm problemes

9 replies to this topic

#1 mihashi

mihashi

GMC Member

• GMC Member
• 40 posts
• Version:GM8

Posted 13 August 2012 - 02:39 AM

hi every one
i m trying to make a simple AI for an ennemi
it has to move a certain distance to the right/left (hspeed =+-4),
than stops (hspeed = 0);
choose to go right or left a certain distance, stops etc.

when it stops (hspeed = 0) an alarm is triggered to choose left/right and calculate the distance to go;

the problem is: the alarm event is not triggered when hspeed = 0;
so my hspeed stays equal to 0.
and my variable" a" does not change from the one calculated in the "create event"

here is the code

event create

facing = 1;//facing right
a = x+random(room_width-x); //random distance to move to the right

event step

if facing == 1 //moving right
{
if(x<a) hspeed = +4;
else {hspeed = 0;alarm[10]=30;}
}
else
if facing == -1 //moving left
{
if(x>a) hspeed = -4;
else {hspeed = 0;alarm[10]=30;}
}

alarm10 event

facing = choose(+1,-1);
switch facing
{
case +1 : a = x + random(room_width-x); //move right
case -1 : a = x - random(x); //move left
}

i don't understand where the problem lies thks for helping me
• 0

#2 willowvayle

willowvayle

Hello World!

• GMC Member
• 412 posts
• Version:GM8.1

Posted 13 August 2012 - 02:49 AM

? I don't know if these are your problems but... Wouldn't hspeed be set like 'hspeed += 4' not 'hspeed = +4'?

Edited by willowvayle, 13 August 2012 - 02:49 AM.

• 0

#3 mihashi

mihashi

GMC Member

• GMC Member
• 40 posts
• Version:GM8

Posted 13 August 2012 - 02:53 AM

? I don't know if these are your problems but... Wouldn't hspeed be set like 'hspeed += 4' not 'hspeed = +4'?

no
the problems is with this alarm that doesn't work
• 0

#4 willowvayle

willowvayle

Hello World!

• GMC Member
• 412 posts
• Version:GM8.1

Posted 13 August 2012 - 03:00 AM

Go to debug mode and check to see if hspeed ever equals 0
• 0

#5 mihashi

mihashi

GMC Member

• GMC Member
• 40 posts
• Version:GM8

Posted 13 August 2012 - 03:41 AM

when x > a hspeed = 0 but the alarm event is not triggered

that's the problem the alarm event

Edited by mihashi, 13 August 2012 - 03:41 AM.

• 0

#6 TheouAegis

TheouAegis

GMC Member

• GMC Member
• 4714 posts
• Version:GM8

Posted 13 August 2012 - 04:36 PM

Looks to me like the alarm IS being set.

EVERY STEP

Change your conditional so that doesn't happen.
• 0

#7 johnkapid

johnkapid

• GMC Member
• 143 posts
• Version:GM:Studio

Posted 13 August 2012 - 06:20 PM

Make a check on alarm since it's being called on every step.
Simple solution.

alarm[10]=30;

Use

if (alarm[10] == -1) alarm[10]=30;
• 0

#8 mihashi

mihashi

GMC Member

• GMC Member
• 40 posts
• Version:GM8

Posted 13 August 2012 - 06:25 PM

thks very much for the hint, iy worked verywell.
• 0

#9 mihashi

mihashi

GMC Member

• GMC Member
• 40 posts
• Version:GM8

Posted 13 August 2012 - 06:29 PM

how can i get this topic to be "solved"
• 0

#10 johnkapid

johnkapid

• GMC Member
• 143 posts
• Version:GM:Studio

Posted 13 August 2012 - 06:30 PM