Frusterated, guidance please.

Posted By: Thordendal

Frusterated, guidance please. - 12/25/08 02:10

I'm doing workshop 18 and the c_move is easy. I'm trying to make the key_space decrease the variable NOS.

I've tied them in, I just can't figure out a way to decrease the value of it when I hit the space button.

Code:
if ((key_space) && (nos >= 1))
c_move (my, vector(15 * time_step, 0, 0), nullvector, GLIDE);

I think I know what to do, but I can't figure out how to do it without crashing the client.

It's got to have something like this right?

Code:
while (key_space) {
energy -= 1;
}


I also believe I need to use while(1), am I right?
Posted By: GamerX

Re: Frusterated, guidance please. - 12/25/08 04:27

Not totally sure what u want but i will give you a few examples.

Code:
while(1)
{
if(key_space)
{
nos -= 1;
}
wait(1);
}


the above code will continue to subtract one from nos while you have the space key down if you want it to just subtract once every time you hit the space bar then you would do something like this.

Code:
var space_hold = 1;
while(1)
{
if(key_space && space_hold == 1)
{
nos -= 1;
space_hold = 0;
}
if(key_space != 1)
{
space_hold = 1;
}
wait(1);
}

That will take 1 from nos every time you hit the space bar even if you hold it down.

Code:
var space_hold = 1;
while(1)
{
if(key_space && space_hold == 1 && nos > 0)
{
nos -= 1;
space_hold = 0;
}
if(key_space != 1)
{
space_hold = 1;
}
wait(1);
}


That will subtract 1 from nos when you hit the space bar only if it is greater than 0.

If you were asking for something else let me know lol.
Or if you get an error because i am kinda half asleep right know just got out of the car.
Posted By: Thordendal

Re: Frusterated, guidance please. - 12/25/08 04:43

Just got it, what do you think?
Code:
if ((key_space) && (energy > 1)) // press and hold the "Space" key to move the car
			c_move (my, vector(15*time_step, 0, 0), nullvector, GLIDE);
		if(key_space)
			energy-= .12;
		if (energy < 0)
			energy = 0;
		if (energy < 100)
		energy += .02;	
		wait (1);
	}
}
PANEL* nos = {
	digits (50, 50, 3, *, 1,energy);
	flags = VISIBLE;
}

Posted By: GamerX

Re: Frusterated, guidance please. - 12/25/08 04:46

Looks good.
© 2023 lite-C Forums