scoring + Game takes 30+ seconds to end.

BlitzMax Forums/BlitzMax Programming/scoring + Game takes 30+ seconds to end.

WERDNA(Posted 2010) [#1]
Hey everyone.

I have a rather nasty problem with the game I'm working on right now.
I want to put in an awards system like in the super smash bro's games, where
if you meet certain prerequisites during a match you'll earn awards that net you
extra points for your high score :)

Well I have that working just fine, but as soon as I read the arrays that contain
the data, my game will slow down dramatically(No big deal since nothings going
on at the time other than the score display), and when you press a key the game
will 'seem' to run just fine. you can play matches, move around character select
etc. But as soon as you try to end by pressing ESC it takes from 20 to 60 seconds
to end OR just freezes up completely. This ONLY happens when I try to read
data from both arrays so I can display both the award name, and how many
points it's worth(I have two arrays. 1 that just holds the award names, and
the other which holds two values. True or False to see if you have met the
prerequisites, and the point value of the award).

Here's the code where I read from them.

Function ScoreDisplay()
Local Fonto = LoadImageFont:TimageFont(CurrentDir()+"/Fonts/Vera.ttf",36,SMOOTHFONT)
Local y = 172
Local AwardO$ = "A W A R D S"
SetImageFont Fonto

DrawText AwardO$,width/2-TextWidth(AwardO$)/2,100

(Here's the bit that checks the arrays V)
For scores = 1 To 51
If CheckArray[scores,0] = True
DrawText AwardsArray[scores]+" "+CheckArray[scores,1],width/2-200,y
y = y + 36
End If
Next

SetImageFont Fonto3
End Function

The above works fine if I edit out CheckArray[scores,1] after DrawText.
It also works fine on Windows XP. The problem seems to only be on Win7.

I tried redoing how I read the awards just a few moments ago, using two
different Types instead of two different arrays, and got it to display the text
just fine, but it still crashes or takes forever to end my program when I hit
ESC. I tried removing all of both types from their respective type lists before
typing END, but the program still ends itself weirdly. Occasionally it takes only
a few seconds to end, but usually it takes awhile or crashes.


Twould be nice if any one knows how to fix this :)
I'm using BlitzMax 1.34 by the way.


Jesse(Posted 2010) [#2]
what does the line look where you create the checkArray. you might be going out of bound.
arrays don't work the same as they do in blitzBasic.
if you create an array of 50 elements it will index between 0 to 49:
local a[50]
for b = 0 to 50-1
   a[b] = n
next

are you running in debug mode?
are you using strict or superstrict?


WERDNA(Posted 2010) [#3]
Global CheckArray[60,2]
For Checks = 1 To 51
CheckArray[Checks,0] = False
Next

I create more than I need so there's no way I'll go out of bounds ;)
A tad wasteful of resources, but whatever, lol.

I'm running in debug mode.
I am not using strict or superstrict.

As I mentioned, this does work just fine on WinXP. its just on Win7(And probably Vista)
that there is a problem.


Jesse(Posted 2010) [#4]
have you tried running your application with UAC OFF on windows 7?
I am thinking you are trying to write the files with out permission and are attempting to read files that don't exist in your hard drive.


Brucey(Posted 2010) [#5]
local a[50]
for b = 0 to 50-1
   a[b] = n
next


btw, using "Until" makes the code more readable :

local a[50]
for b = 0 Until 50
   a[b] = n
next


And as Jesse points out, arrays are zero indexed.


How often are you loading the same font file? 60 times a second?


jkrankie(Posted 2010) [#6]
I can''t see anything wrong with your function, so it's probably how you're calling it. are you calling it from in a loop or something?

Cheers
Charlie


Muttley(Posted 2010) [#7]
One thing that can help spot problems in advance is to always use SuperStrict. Seriously, every program you write, always have that as the first line, it will save you so many problems.

The fact that you're loading the imagefont every time ScoreDisplay() is also a bit suspect.


Czar Flavius(Posted 2010) [#8]
Make fonts and things like that global variables.


WERDNA(Posted 2010) [#9]
@Slaps self in the forehead.
Loading the font 60 times a second is definitely a bad idea, lol.

btw, using "Until" makes the code more readable :

Thanks for the tip! I'll try adding that from now on instead of to #.
And yeah, I now arrays are 0 indexed ;)

@jkrankie
I'm calling the function from the games main While loop. Nothings wrong with how
I'm calling it. It works just fine without any slow down as long as I edit out checkarray[scores,1]
after Drawtext.

I'll see about simply changing the font to a global, see if that alone fixes it, lol.


Thanks for the help, I'll see if any of the above fixes it.