SOLVED: Determine players y and display Label text

Started by barefoot, Mon 15/08/2011 11:53:59

Previous topic - Next topic

barefoot

Hi

EDIT: I guess I'm trying to determine if player y is between int and int then show this TEXT on labels.

IE (y from top) 200/170  Display this, 170/140 Display this, 140/100 Display this, 100/70 Display this,


It's if player between y ints that the problem.

Hope you understand.

-----------------------------

I'm trying to make a global so that whatever the players y is will determine Labels text
IE Lheight: 400 feet / Lspeed: 300 mph.

I would like the screen split up into say 4 horizontal lines, each will display Lheight and Lspeed Labels with appropriate text depending on y.

I am using regions to do this but fails when with an eBlock.

So far I have this but need help beacause it's not quite enough.

In Global:
Code: ags

function repeatedly_execute_always() 

{
  
	  if (cfighter1a.y >  99) 
{
  Lheight.Text="0 feet";
	Lspeed.Text="0 mph";
	
	{
		
		
	 if (cfighter1a.y <=  219) 
{
  Lheight.Text="500 feet";
	Lspeed.Text="300 mph";
}
		
		
	  if (cfighter1a.y < 209) 
{
  Lheight.Text="300 feet";
		Lspeed.Text="200 mph";

	
	}
		
		
	  if (cfighter1a.y <=  99) 
{
  Lheight.Text="0 feet";
		Lspeed.Text="0 mph";

}
 
}
	
}}


Also trying to STOP firing missile continuously when key is pressed.
Tried Game.DoOnceOnly but this does not stop the firing. If key is pressed action happens only once until released and pressed again.

Can you help please

barefoot

I May Not Be Perfect but I Have A Big Heart ..

arj0n

#1
Quote from: barefoot on Mon 15/08/2011 11:53:59
Also trying to STOP firing missile continuously when key is pressed.
Tried Game.DoOnceOnly but this does not stop the firing. If key is pressed action happens only once until released and pressed again.

Why not something like:
Code: ags

function on_key_press(eKeyCode keycode)
{
  if (((keycode == <your key>) && (IsKeyPressed(<your key>) == 0) && (<your possibly extra if-statement>))){
  .....; \\your missile-firing code
}
else {
.....; \\other possible not-missile-firing code
}}



Not tested - not sure if the 'else' part is needed...

EDIT:
For your y-position-label, do you mean you need a 'between' thing? Like:
Code: ags

if ((cfighter1a.y >  99) && (cfighter1a.y <  219)){
Lheight.Text="0 feet";
Lspeed.Text="0 mph";
}

I guess not because you would have thought of it yourself.... ;)

Khris

I have cleaned up the indentations. You need to do this yourself, especially when you want help with your code.

Code: ags
function repeatedly_execute_always() 
{  
  if (cfighter1a.y >  99) 
  {
    Lheight.Text="0 feet";
    Lspeed.Text="0 mph";
	
    {
      if (cfighter1a.y <=  219) 
      {
        Lheight.Text="500 feet";
        Lspeed.Text="300 mph";
      }
		
      if (cfighter1a.y < 209) 
      {
        Lheight.Text="300 feet";
        Lspeed.Text="200 mph";
      }

      if (cfighter1a.y <=  99) 
      {
        Lheight.Text="0 feet";
        Lspeed.Text="0 mph";
      }
    }	
  }
}

There weren't any missing or wrong brackets though.

Just look at this code, it should be obvious why it doesn't work.
For instance the inner three if conditions are all true for a value of 99 or smaller. This doesn't mean it doesn't work but it's not exactly a good way of doing things.
Also, the last one is never going to be true since y can't be greater than 99 and at the same time smaller than or equal to 99.

Code: ags
function repeatedly_execute_always() 
{
  int height, speed, y = cfighter1a.y;
  
  if (y <= 99)
  {
    speed = 0;
    height = 0;
  }
  else if (y <= 209)   // y: 100-209
  {   
    speed = 200;
    height = 300;
  }
  else                    // y > 209
  {                    
    speed = 300;
    height = 500;
  }

  Lspeed.Text = String.Format("%d mph", speed);
  Lheight.Text = String.Format("%d feet", height);
}


Not sure if this really is what you want, I'd find it kinda weird if the height (of my jet I suppose) jumped around like that instead of having a linear relation to the position of what I'm moving up and down on the screen.
Why not something like height = player.y * 2; or similar?

barefoot

#3
Thank you Khris

Edit: seems to work ok. Needs small tweeking. Will report back.

Looking at: height = player.y * 2;

---------------------------------------------

Sorry about code...  and again, thanks for your reply.

As far as it goes it does relate to the position of the main player (plane) which can only move up and down. As player moves up or down so the height and speed labels change.

I will try what you have put. Thanks also to Arj0n.

cheers  :=

barefoot




I May Not Be Perfect but I Have A Big Heart ..

barefoot

Tweeked and works well...


:=

Code: ags


function repeatedly_execute_always() 

{
	
	int height, speed, y = cfighter1a.y;
  
  if (y <= 99)
  {
    speed = 400;
    height = 700;
		
		}
  else if (y <= 150)
  {
    speed = 300;
    height = 500;
  }
  else if (y <= 209)   
  {   
    speed = 200;
    height = 300;
		
		
		 }
  else if (y <= 220)   
  {   
    speed = 100;
    height = 200;
		
		
  }
  else                    
  {                    
    speed = 0;
    height = 0;
  }

  Lspeed.Text = String.Format("Speed: %d mph", speed);
  Lheight.Text = String.Format("%d feet", height);
	
  
	 }


Cheers for your assistance again Khris

barefoot


I May Not Be Perfect but I Have A Big Heart ..

SMF spam blocked by CleanTalk