Why Is My Program Stuttering Instead of Playing Smoothly?

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

Moderators: Shine, Insert_witty_name

Post Reply
wicked.fable
Posts: 1
Joined: Thu Jun 12, 2008 11:51 am

Why Is My Program Stuttering Instead of Playing Smoothly?

Post by wicked.fable »

I am creating a program for timing speedsolves (solving Rubik's Cubes or other such puzzles fast) that, as of now, can save your times and lets you switch between different categories of solving such as One-Handed, Speed, or Blindfolded while allowing you to save an inddividual time for each category. The program was running very smoothly until, it seems, I added the feature to switch categories. Now, for example, when the timer runs it stutters instead of progressing smoothly. I have searched but I really do not have any real idea as to what I should search to find out why this is happening. Could someone help me out? The code is below.

Thanks,
dChan

Code: Select all

System.usbDiskModeActivate ()

white = Color.new (255,255,255)
black = Color.new (0,0,0)
red = Color.new (255,0,0)
lime = Color.new (128,255,0)

fontcherl = Font.load ("cherl.ttf")
fontcherl:setPixelSizes (72,72)

fontcherl2 = Font.load ("cherl.ttf")
fontcherl2:setPixelSizes (28,28)

fontcheri = Font.load ("CHERI.ttf")
fontcheri:setPixelSizes (36,36)

fonttrashco = Font.load ("trashco.ttf")
fonttrashco:setPixelSizes (48,48)

category =  {}
category[1] = {c = "One-Handed Solve"}
category[2] = {c = "Speed Solve"}
category[3] = {c = "Blindfolded Solve"}
categorynumber = 2

categoryrecord = "ss"

counter = Timer.new ()
counter:stop ()

background = Image.createEmpty (480,272)
background:clear (white)

function timerControls ()
if categorynumber == 1 then
categoryrecord = "oh"
end

if categorynumber == 2 then
categoryrecord = "ss"
end

if categorynumber == 3 then
categoryrecord = "bld"
end

if counter:time () > 600000 then
counter:reset (0)
end

if pad:cross () then
counter:stop ()
end

if pad:square () then
counter:stop ()
counter:reset (0)
end

if pad:triangle () then
file = io.open ("record"..categoryrecord..".txt","w")
file:write (currentTime)
file:close ()
end

if pad&#58;r &#40;&#41; and categorynumber < 3 then
categorynumber = categorynumber + 1
end

if pad&#58;l &#40;&#41; and categorynumber > 1 then
categorynumber = categorynumber - 1
end

if pad&#58;r &#40;&#41; and pad&#58;l &#40;&#41; and counter&#58;stop &#40;&#41; then
counter&#58;reset &#40;0&#41;
counter&#58;start &#40;&#41;
end
end

while true do 
screen&#58;clear &#40;&#41;

screen&#58;blit &#40;0,0,background&#41; 

currentTime = counter&#58;time &#40;&#41; / 1000

file = io.open &#40;"record"..categoryrecord..".txt","r"&#41;
record = file&#58;read &#40;"*n"&#41;
file&#58;close &#40;&#41;

screen&#58;fontPrint &#40;fonttrashco,140,50,"cWatch",lime&#41;
screen&#58;fontPrint &#40;fontcherl2,140,80,category&#91;categorynumber&#93;.c,black&#41;
screen&#58;fontPrint &#40;fontcherl,140,136,currentTime,black&#41;
screen&#58;fontPrint &#40;fontcherl2,60,200,"Personal Record&#58;",black&#41;
screen&#58;fontPrint &#40;fontcheri,300,200,record,black&#41;

pad = Controls.read &#40;&#41;

timerControls &#40;&#41;

screen.waitVblankStart &#40;&#41;
screen.flip &#40;&#41;

if pad&#58;start &#40;&#41; then
break
end
end 
EDIT: The activation of the USB connection is just to help me revise the code faster. It has no use in the actual program. The program also does not recognize when I press a button right away. Sometimes it takes several tries before it realizes I am pressing a button.
Post Reply