Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,561 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Loop problem #329129
06/17/10 19:26
06/17/10 19:26
Joined: Jun 2007
Posts: 15
Norway
G
Gastara Offline OP
Newbie
Gastara  Offline OP
Newbie
G

Joined: Jun 2007
Posts: 15
Norway
Can someone help me with this please? I’m trying to make an endless loop for this while statement. At the moment, it moves the sprite forward, then back to start point and stop there. What do I need to do for making an endless loop for this?

Code:
while(1)
	{
		enemy_pan1.pos_x += speed_x;
		
		if (enemy_pan1.pos_x >= 500)
		{
			enemy_pan1.pos_x = 500;
			
			while(1)
			{
			enemy_pan1.pos_x -= speed_x;
			
			if (enemy_pan1.pos_x <= 300)
		   {
		   enemy_pan1.pos_x = 300;
			}
	      
	      wait(1);
			}
	
		}
			
		wait(1);
	}



Re: Loop problem [Re: Gastara] #329130
06/17/10 19:34
06/17/10 19:34
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
Code:
while(1)
{
   enemy_pan1.pos_x += speed_x;
   if (enemy_pan1.pos_x >= 500)
   {
      enemy_pan1.pos_x = 500;
      while(enemy_pan1.pos_x > 300)
      {
         enemy_pan1.pos_x -= speed_x;
         wait(1);
      }
      enemy_pan1.pos_x = 300;
   }
   wait(1);
}



(untested)

Your second whileloop never ends, so the panel stops moving at the way back...

Last edited by Widi; 06/17/10 19:37.
Re: Loop problem [Re: Widi] #329132
06/17/10 19:44
06/17/10 19:44
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Wouldn't it be easier to use a periodic function like sin? Then clamp the values between 300 and 500?

Re: Loop problem [Re: DJBMASTER] #329136
06/17/10 20:07
06/17/10 20:07
Joined: Jun 2007
Posts: 15
Norway
G
Gastara Offline OP
Newbie
Gastara  Offline OP
Newbie
G

Joined: Jun 2007
Posts: 15
Norway
Thank u very much Widi, it works fine now. I will also check out your solution DJBMASTER. Thanks!

Re: Loop problem [Re: DJBMASTER] #329137
06/17/10 20:14
06/17/10 20:14
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Code:
while(1)
{
	enemy_pan1.pos_x += speed_x;
	if((enemy_pan1.pos_x >= 500)||(enemy_pan1.pos_x <= 300))
	{	speed_x = -speed_x;	}
	wait(1);
}




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Loop problem [Re: EvilSOB] #329277
06/18/10 23:42
06/18/10 23:42
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
My go!
Code:
while(1)
{
   enemy_pan1.pos_x = minv(enemy_pan1.pos_x + speed_x, 500);
   while(enemy_pan1.pos_x != 300)
   {
      enemy_pan1.pos_x = maxv(enemy_pan1.pos_x - speed_x, 300);
      wait(1);
   }
   wait(1);
}

just to stop the extra movement below 300 and above 500 grin


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1