help! (not sure if this is the right board?)

Previous topic - Next topic

mookmac

hey everyone, i'm trying to code a simple highscore board which currrently just consists of the 3 letter name entry common on most arcade machines. however when i try to complile my game i get this error:
Code (glbasic) Select
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2007.348 - 2D, WIN32
"Colorz.gbas"(63) warning : probably unassigned variable : level
"Colorz.gbas"(85) warning : probably unassigned variable : score
Wordcount:263 commands

compiling:
D:/DOCUME~1/ALEX~2.ALE/LOCALS~1/Temp/glbasic/gpc_temp0.cpp: In function `DGInt __GLBASIC__::highscore()':
D:/DOCUME~1/ALEX~2.ALE/LOCALS~1/Temp/glbasic/gpc_temp0.cpp:259: error: cannot convert `__GLBASIC__::CGStr' to `DGInt' in initialization
*** FATAL ERROR - Please post this output in the forum
the game was compiling and working fine until i tryed to add this sub, This sub is called from another sub which is the main game code. the sub which has appeared to broken the game is this (i've tryed commenting out pieces to fix the problem but to no avail so far):

Code (glbasic) Select
SUB highscore:

//the alphabet array
DIMDATA abet[], "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"


LET letter = 1
//letter 1
WHILE confirm = 0
PRINT abet[letter], 100, 100
SHOWSCREEN
IF KEY (200)
letter = letter - 1
IF letter = -1 THEN letter = 26
ELSEIF KEY (208)
letter = letter + 1
IF letter = 26 THEN letter = 1
ENDIF
IF KEY (45) THEN confirm = 1
WEND

a = abet [letter]
letter = 1

//letter 2
WHILE confirm = 1
PRINT a, 100, 100
PRINT abet[letter], 110, 100
SHOWSCREEN
IF KEY (200)
letter = letter - 1
IF letter = -1 THEN letter = 26
ELSEIF KEY (208)
letter = letter + 1
IF letter = 26 THEN letter = 1
ENDIF
IF KEY (45) THEN confirm = 2
WEND

b = abet [letter]
letter = 1

//letter 3
WHILE confirm = 2
PRINT a, 100, 100
PRINT b, 110, 100
PRINT abet[letter], 120, 100
SHOWSCREEN
IF KEY (200)
letter = letter - 1
IF letter = -1 THEN letter = 26
ELSEIF KEY (208)
letter = letter + 1
IF letter = 26 THEN letter = 1
ENDIF
IF KEY (45) THEN confirm = 3
WEND

c = abet [letter]
letter = 1

//LET name = a + b + c

PRINT "Highscores", 100, 50
PRINT a+""+b+""+c, 100, 70
SHOWSCREEN
//scores = "scores.bin"
//OPENFILE (0, scores, FALSE)
//WRITESTR 0, name
//CLOSEFILE 0

ENDSUB // HIGHSCORE
Thanks for your help, sorry if this is posted in the wrong place.

Neurox

Hello,
this is a simple error :-)

With an STRING VARIABLE use an $ simbol with name.
Replace abet name with abet$

Bye bye,
Neurox
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

mookmac

Thanks, that solved the main problem. However i've now run into a new issue. I'm using the same code (with the change from abet to abet$) but when I press the arrow keys (208 and 200) the game crashes and the log says:
QuoteError: Out of DIM array.
i'm not sure what im doing wrong cause I can't see any logical reason for it not too work unless i'm missunderstanding how the syntax for arrays works.

Ian Price

You are trying to access a part of the array that hasn't actually been defined - eg you are trying to access the 27th letter of the alphabet! The computer can't find the 27th letter and is telling you that it doesn't exist.

Skimming through your code I found this
Code (glbasic) Select
IF letter = -1 THEN letter = 26Your array only has 26 dimensions (0-25) trying to access 26 is causing the problem. Change that to "letter=25". That should help. :)
I came. I saw. I played.

mookmac

thanks that sorted it. Another question though; How can i slow the rate at which the program recives button inputs? e,g. when i hit up or down the game is moving through 7 or 8 array values becuase its reading my one button press as the same button press 7 or 8 times over.

Ian Price

I use something like this
Code (glbasic) Select
WHILE TRUE

IF KEY(??) AND press=0
 x=x+1
 press=10
ENDIF

IF press>0 THEN press=press-1

PRINT "X="+x,100,100

SHOWSCREEN

WEND
I came. I saw. I played.

Kitty Hello

...or wait until a button is released:
Code (glbasic) Select
// Main Game
LOCAL jump, shoot
   jump = OneButton(28)
   shoot = OneButton(128)
   ...


FUNCTION OneButton: k
STATIC ButtState[]
   IF LEN(ButtState[]) = 0 THEN DIM ButtState[256] // first time init

   IF ButtState[k]
      IF KEY(k) = 0 THEN ButtState[k] = FALSE
   ELSE
      IF KEY(k)
         ButtState[k] = TRUE
         RETURN TRUE
      ENDIF
   ENDIF
   RETURN FALSE
ENDFUNCTION