calculating too fast

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

calculating too fast

Post by wekilledbambi03 »

im making a drag racing game. i spent like an hour or 2 working out the equations for the gear ratios and what not. i based it off of data collected from gt4(playing the game is why it took me about 2 hours). anyway, i got it all worked out and it should go really good. in fact it pretty much does each gear works fairly good. problem is the game is too good at checking #s. i have my shifting set up as...

Code: Select all

function shiftup()
gear = gear+1
end

function shiftdn()
gear = gear-1
end

....
if pad:r() then
shiftup() end
if pad:l() then
shiftdn() end
i also have a gear max and min setup but thats not important. the thing is as soon as i tap r itll keep going. one tap may shift to 2 or 6. is their any way to make some functions or just slow it down? i tried making a seperate function for every gear but that did the same thing.
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

Code: Select all

upCount = 0
downCount = 0

function checkPad()
	local pad = Controls.read()
	
	if pad:up() then
		upCount = upCount + 1
		if upCount == 1 then
			shiftUp()
		end
	else
		upCount = 0
	end
 
	if pad:down() then
		downCount = downCount + 1
		if downCount == 1 then
			shiftDown()
		end
	else
		downCount = 0
	end
end
modify your code to only trigger once per button push.. like above.
Last edited by chaos on Thu Oct 20, 2005 10:38 pm, edited 1 time in total.
Chaosmachine Studios: High Quality Homebrew.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

outch!
added the clean solution (by shine)
to the wiki here

greets
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

Post by wekilledbambi03 »

Code: Select all

if upCount = 1 then 
that part (and the downcount one) give me an error. it says then expected near =. i change it to

Code: Select all

if upCount > 1 then  
that got rid of the error but it went back to what it was doing before.
thank you though.
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

Post by wekilledbambi03 »

nevermind...i changed it to

Code: Select all

if upCount == 1 then 
but i must have changed something in other parts of the code cause it doesnt work right.
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

ya, that was a fairly quick hack in notepad, not tested at all.. just a general idea. it should have been ==
Chaosmachine Studios: High Quality Homebrew.
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

LuMo wrote:outch!
added the clean solution (by shine)
to the wiki here

greets
there are some problems with that method.. every time any control changes, it will re-read all controls being held, as if you pressed them a second time.. also, you have no way to know how long each individual control has been held, which is useful in a lot of different situations.
Chaosmachine Studios: High Quality Homebrew.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

removed due: posted 2 secs after the post above ;)
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

Post by wekilledbambi03 »

thanks guys i got the shifting working now. now i gotta jsut work on making a timer and a bunch of other stuff.
Post Reply