Do until for a period of time
#1
Posted 15 July 2011 - 07:41 PM
I need an object to do something until a variable is true.
This is what I did, and it freezes the game. What should I do? (I want the object o move around, looking for the closest instance of z, until Me>=9. Each time it destroys a X, Me+=1.. What should I Do?
do
{if instance_exists(z) then
{
Hum = instance_nearest(x,y,z)
mp_potential_step_object(Hum.x,Hum.y,3,y)
}
}
until Me>=9
#2
Posted 15 July 2011 - 07:48 PM
replace the do...until structure with a if Me < 9 statement , this will achieve the desired result.
#3
Posted 15 July 2011 - 10:33 PM
Object chases nearest instance of X, when it catches it, it destroys it and makes Me+=1. When Me>=9 it goes to another object(Z), where it creates object Y, and makes Me-=10.
I have tried everything and it doesn't work
N.B, thanks for the help
#4
Posted 15 July 2011 - 10:46 PM
if Me<9
{if instance_exists(z) then
{
Hum = instance_nearest(x,y,z)
mp_potential_step_object(Hum.x,Hum.y,3,y)
}
}
First off, I'm assuming this is in the step event of the object.
The problem is in the line of code above, where you have the variable 'y' in the last position.
mp_potential_step_object(Hum.x,Hum.y,3,y)
The mp_potential_step_object uses (x,y,speed,obj) , so you are setting the object to avoid to whatever y position you are at, which will cause lots of problems and probably just make it ignore that entire line of code. Try doing
mp_potential_step_object(Hum.x,Hum.y,3,wall)or just
mp_potential_step(Hum.x,Hum.y,3,false)
-Naibla
Edited by naibla, 15 July 2011 - 10:47 PM.
#5
Posted 15 July 2011 - 10:58 PM
And it still does not work.
#6
Posted 15 July 2011 - 11:05 PM
#7
Posted 15 July 2011 - 11:08 PM
Is what is above your exact code?
Did you try what I suggested, but with the correction that @Alex@ said (which IS what is in my example, but just double checking)?
What's happening right now is that they treat all instance nearests as the same..
Isn't there only one instance nearest? I'm sorry if I'm not understanding you...
Edit: Bleh, ignore the above line... didn't read your last post right.
So, it almost works... somehow everyone has the same Hum. Try using a with statement maybe?
Edited by naibla, 15 July 2011 - 11:12 PM.
#8
Posted 15 July 2011 - 11:15 PM
if Sum>9 then
{
mp_potential_step_object(Cherry.x,Cherry.y,3,Carnivor)
}
else
if Sum<10
{if instance_exists(Bread) then
{
Hum = instance_nearest(x,y,Bread)
mp_potential_step_object(Hum.x,Hum.y,3,Carnivor)
}
}
Everything else works. Right now, it is only going towards instance Bread
#9
Posted 15 July 2011 - 11:57 PM
#10
Posted 16 July 2011 - 12:14 AM
Are you sure that Sum is increasing correctly?
Is Cherry an instance_nearest or just an object?
#11
Posted 16 July 2011 - 12:24 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











