|
|
Frusterated, guidance please.
#242668
12/25/08 02:10
12/25/08 02:10
|
Joined: Dec 2008
Posts: 12
Thordendal
OP
Newbie
|
OP
Newbie
Joined: Dec 2008
Posts: 12
|
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. 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? while (key_space) {
energy -= 1;
}I also believe I need to use while(1), am I right?
|
|
|
Re: Frusterated, guidance please.
[Re: Thordendal]
#242676
12/25/08 04:27
12/25/08 04:27
|
Joined: Aug 2008
Posts: 218 U.S.
GamerX
Member
|
Member
Joined: Aug 2008
Posts: 218
U.S.
|
Not totally sure what u want but i will give you a few examples.
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.
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.
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.
"You may never know what results come of your action, but if you do nothing there will be no result." -Mahatma Gandhi
|
|
|
Re: Frusterated, guidance please.
[Re: GamerX]
#242678
12/25/08 04:43
12/25/08 04:43
|
Joined: Dec 2008
Posts: 12
Thordendal
OP
Newbie
|
OP
Newbie
Joined: Dec 2008
Posts: 12
|
Just got it, what do you think?
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;
}
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|