Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / I need help about a speed jauger with joystick button hit

Author
Message
Starbuzzzz
13
Years of Service
User Offline
Joined: 5th Dec 2010
Location: France
Posted: 2nd Feb 2018 17:51 Edited at: 2nd Feb 2018 17:59
Hi all,
the title of my post is not very clear lol
I'm going to try to explain my problem.
Just for fun, I wanted to program a short program to calculate at what speed I can hit and release a button, as it was used in video games like Decathlon on hyper sports. The faster you hit the button, the faster the screen caracter runs. I think it was very easy to do it but.... erg.... No way :/
I've tried this :

boucle:
a=0:c=0
for i=1 to 50000
if joystick fire a() and a=0 then c=c+1:a=1
if joystick fire a()=0 and a=1 then c=c+1:a=0
NEXT
print c
goto boucle

c is the variable that is counting how many times I hit and release the button. ... But I only got 1 or 2 for c when I try this.
I don't want the program to count on a long period, but on short period to use it as it's used in an Hypers Sports program :/

I don't know if my explanation is clear but I will be happy if someone can help me about this. Thanx !
Buzzz
Starbuzzzz
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 2nd Feb 2018 21:50 Edited at: 2nd Feb 2018 21:59
A lot of the hardware input commands only update once per sync I think, sticking all this in a for loop doesn't give the system much ability to update.

Also putting multiple commands with : after then can be buggy, it won't always execute all of them

Try something like this:

http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Derek Darkly
12
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 2nd Feb 2018 23:40


Here u go my ninja.

Send your parents to noisy sprite demo hell... enter the D-Zone
zero32
7
Years of Service
User Offline
Joined: 28th Jul 2016
Location:
Posted: 5th Feb 2018 09:00
I like to do it with functions. And i recommend to use a the timer function for time based events. A for loop can be inaccurate on different computers.

may be cleaner if you use different buttons for different things
"It is only slightly easier than changing all sugar in a cake into stevia after it has already been baked" -Bisqwit
Starbuzzzz
13
Years of Service
User Offline
Joined: 5th Dec 2010
Location: France
Posted: 21st Feb 2018 11:49
Hi.
Thanx for your help guys, but your codes don't work better than mine I want that if I hit an release 10 times the button in one second I get the speed of 10 hits per second. Even whith your codes I just can get this result (I don't talk about the ability of being so fast with my finger but the ability of counting 10 hits in 1 second with dbpro.) Is it really impossible to count the real number of hit in a cycle ?
Starbuzzzz
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 21st Feb 2018 12:52 Edited at: 21st Feb 2018 12:58
Ortu wrote: "A lot of the hardware input commands only update once per sync I think, sticking all this in a for loop doesn't give the system much ability to update."

I can't check this now, but I would be inclined to agree. Also polling I/O is very time consuming compared to other things, so I can't see that happening continuously (between sync) as the program executes.

Rudolpho made a plugin called ZInput. I have not used this but planned to look into it. It is an alternative method for handling joystick/gamepad input. It might help here.
https://forum.thegamecreators.com/thread/217980
Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 21st Feb 2018 13:17 Edited at: 21st Feb 2018 13:18
Here's what I came up with, just start tapping the space bar really fast when he program starts, it will tell you how many time you hit in within a second. or hit it slow.

if I really hit the space bar fast, I can get 8 hits in 1 second.

I'm sure it can be optimized, sorry I was lazy with adding the goto to get the print command to print only once.

Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 21st Feb 2018 13:29
got rid of the goto

Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 21st Feb 2018 13:32
if I really slam the space bar, I've managed to get 9 hits in a second.

Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 21st Feb 2018 13:34 Edited at: 21st Feb 2018 13:47
Oh, and I don't have a joystick, but maybe you can modify the scancode commands to work with the joystick instead.

Login to post a reply

Server time is: 2024-03-28 11:41:53
Your offset time is: 2024-03-28 11:41:53