Jump to content


Photo

Do until for a period of time


  • Please log in to reply
10 replies to this topic

#1 Morrin

Morrin

    GMC Member

  • New Member
  • 23 posts

Posted 15 July 2011 - 07:41 PM

Hello,

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

#2 @Alex@

@Alex@

    Retired GMC Reviewer

  • Reviewer
  • 3076 posts
  • Version:Unknown

Posted 15 July 2011 - 07:48 PM

The do until structure is powerful and you've fallen into a trap here, where it takes so long to get to Me >= 9 it causes the game to crash.

replace the do...until structure with a if Me < 9 statement , this will achieve the desired result.
  • 0

#3 Morrin

Morrin

    GMC Member

  • New Member
  • 23 posts

Posted 15 July 2011 - 10:33 PM

It does not work- This is what I want to happen.
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
  • 0

#4 naibla

naibla

    GMC Member

  • New Member
  • 17 posts

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.

  • 0

#5 Morrin

Morrin

    GMC Member

  • New Member
  • 23 posts

Posted 15 July 2011 - 10:58 PM

Those aren't actual letters, they are just examples (as in algebra, x, y, z are all variables)

And it still does not work.
  • 0

#6 Morrin

Morrin

    GMC Member

  • New Member
  • 23 posts

Posted 15 July 2011 - 11:05 PM

What's happening right now is that they treat all instance nearests as the same..
  • 0

#7 naibla

naibla

    GMC Member

  • New Member
  • 17 posts

Posted 15 July 2011 - 11:08 PM

Is it in the step event?

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.

  • 0

#8 Morrin

Morrin

    GMC Member

  • New Member
  • 23 posts

Posted 15 July 2011 - 11:15 PM

This is the code I have

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

#9 Morrin

Morrin

    GMC Member

  • New Member
  • 23 posts

Posted 15 July 2011 - 11:57 PM

any ideas?
  • 0

#10 naibla

naibla

    GMC Member

  • New Member
  • 17 posts

Posted 16 July 2011 - 12:14 AM

Hmm... It looks good to me.
Are you sure that Sum is increasing correctly?

Is Cherry an instance_nearest or just an object?
  • 0

#11 Morrin

Morrin

    GMC Member

  • New Member
  • 23 posts

Posted 16 July 2011 - 12:24 AM

Just an object. And yes, it is being increased correctly. I've tested it alone.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users