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
2 registered members (TipmyPip, 1 invisible), 18,731 guests, and 7 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
Hold down a key to charge #392384
01/22/12 02:29
01/22/12 02:29
Joined: Aug 2009
Posts: 13
W
WoYoSensei Offline OP
Newbie
WoYoSensei  Offline OP
Newbie
W

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 tongue
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 Offline
Senior Expert
Superku  Offline
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? wink


"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
W
WoYoSensei Offline OP
Newbie
WoYoSensei  Offline OP
Newbie
W

Joined: Aug 2009
Posts: 13
OK, so here is my code

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 tongue

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 tongue
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 Offline
Senior Expert
Superku  Offline
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:

Code:
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
Re: Hold down a key to charge [Re: Superku] #392483
01/23/12 10:41
01/23/12 10:41
Joined: Aug 2009
Posts: 13
W
WoYoSensei Offline OP
Newbie
WoYoSensei  Offline OP
Newbie
W

Joined: Aug 2009
Posts: 13
Ehhh, yes, now it`s working like a dream. Thank you.


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