|
Hold down a key to charge
#392384
01/22/12 02:29
01/22/12 02:29
|
Joined: Aug 2009
Posts: 13
WoYoSensei
OP
Newbie
|
OP
Newbie
Joined: Aug 2009
Posts: 13
|
Hi, I have a very noob question. I`m trying to do something like charging skill, but first I would like to learn on something easy. Let`s say I have a variable shift_press = 0 and when I`m holding a key (left shift for example) this variable is growing +1 for every 0.5 second (max 60 fps, so for every 30 fps). When I`m not holding Left Shift anymore, var shift_press is going back to 0. And here is my question. I know how it should work, but Lite-C is just completely not logical in this way  Could you assist me with this? How the code should look to work just as I want to?
|
|
|
Re: Hold down a key to charge
[Re: WoYoSensei]
#392385
01/22/12 02:55
01/22/12 02:55
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
if(!key_shift) charge = 0; else charge = minv(charge+0.5*time_step, charge_maximum); What's so illogical about this? 
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Hold down a key to charge
[Re: WoYoSensei]
#392468
01/23/12 00:35
01/23/12 00:35
|
Joined: Aug 2009
Posts: 13
WoYoSensei
OP
Newbie
|
OP
Newbie
Joined: Aug 2009
Posts: 13
|
OK, so here is my code
#include <acknex.h>
#include <default.c>
var press_shift = 0;
var charge_maximum = 100;
function shift_press()
{
if(!key_shift) press_shift = 0;
else press_shift = minv(press_shift+0.5*time_step, charge_maximum);
}
PANEL* shift_pan = {
digits (30,10, 4, *, 1, press_shift);
flags = SHOW;
}
function main()
{
screen_size.x = 800;
screen_size.y = 600;
video_switch(0,0,2);
screen_color.blue = 150; // dark blue
shift_press();
}
and it`s not working... I was trying, but probably Lite-C doesn`t like me so much as I like Lite-C  What this code should do? Well, nothing important. I`m trying to move this charging to variable. When I`m pressing Left Shift, var should growing, but it doesn`t happen. I was working witch many other languages before, with Lite-C as well, but that was centuries ago and I think I lost my talent  Could you help me with this? Thank you for any help.
|
|
|
Re: Hold down a key to charge
[Re: WoYoSensei]
#392470
01/23/12 00:47
01/23/12 00:47
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
The problem is that the function is only executed once, you have to add a loop to shift_press:
function shift_press()
{
while(1)
{
if(!key_shift) press_shift = 0;
else press_shift = minv(press_shift+0.5*time_step, charge_maximum);
wait(1);
}
}
I suggest you have a look at the tutorial: http://tutorial.3dgamestudio.net/
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|