I'm trying to set up a scoring system for my game. I pieced something together that looks like it will work, but I'm having trouble actually displaying my score. I'm thinking it's something simple with how I'm attaching the variable.
text 0,0,"High Score: "+str$(highscore(1))
text 0,38,"Your Score: "+str$(score(1))
The error it gives says "cannot determine parameter type of [the string]." I've tried many combinations of symbols, and I also tried pointing not at an array, but at the variable itself.
The entire game code:
Set display mode 1024,768,32
Sync On
hide mouse
SW = screen width()
SH = screen height()
SN = 50
Q = 24
Randomize Timer()
F# = 1
E = 0
D = 0
score = 0
highscore = 0
set text font "arial"
set text size 32
Global LastMClick as Integer
Global MClick as Integer
Global Trigger as String
Global Score as Integer
load image "menumain1.jpg",5000,1
load image "menulose1.jpg",5001,1
load image "menuwin1.jpg",5002,1
load image "texcosmos.jpg",1000,1
load image "texcrosshair.tga",999,1
load image "texphishing.tga",1,1
load image "texpostcard.tga",2,1
load image "texdegrees.tga",3,1
load image "texmytob.tga",4,1
load image "texghost.tga",5,1
load image "texmydoom.tga",6,1
load image "texultimate.tga",7,1
load image "texspy.tga",8,1
load image "cityb1_64x118.tga",2001,1
load image "cityb2_64x130.tga",2002,1
load image "cityb3_78x205.tga",2003,1
load image "cityb4_43x235.tga",2004,1
load image "cityb5_139x249.tga",2005,1
load image "cityb6_97x137.tga",2006,1
load image "cityb7_47x275.tga",2007,1
load image "cityb8_169x169.tga",2008,1
load image "cityb9_71x226.tga",2009,1
load image "cityb10_44x198.tga",2010,1
load image "texmountains.tga",2011,1
get image 1002,0,0,1,1,1
load sound "soundsambient.wav",1
load sound "soundsvirus_impact.wav",2
load sound "soundskeyboard_beep.wav",3
load sound "soundsshield_impact.wav",4
loop sound 1
do
cls
gosub Setup
do
gosub OnClick
gosub CityHit
gosub RefScreen
gosub EndGame
sync
loop
loop
end
Rem *********************
Rem Procedures
Rem *********************
Setup:
REM **********
REM Create Sprites
REM **********
REM city display
REM random starts : Change ystarts to modify timing of descents
REM sprite designation
sprite 2011,0,SH-108,2011
sprite 2001,Q+12,SH-116,2001
sprite 2002,Q+85,SH-128,2002
sprite 2003,Q+148,SH-203,2003
sprite 2004,Q+232,SH-232,2004
sprite 2005,Q+280,SH-236,2005
sprite 2006,Q+467,SH-137,2006
sprite 2007,Q+582,SH-275,2007
sprite 2008,Q+647,SH-152,2008
sprite 2009,Q+824,SH-223,2009
sprite 2010,Q+913,SH-194,2010
Dim xstart(SN)
For P = 1 to SN
xstart(P)=(SW/10)*(rnd(8)+1)
Next P
dim ystartPH(SN)
For P = 1 to SN
ystartPH(P)=-rnd(360)-189*P
Next P
dim ystartPO(SN)
For P = 1 to SN
ystartPO(P)=-rnd(405)-657*P
Next P
dim ystartDE(SN)
For P = 1 to SN
ystartDE(P)=-rnd(389)-1223*P
Next P
dim ystartTB(SN)
For P = 1 to SN
ystartTB(P)=-rnd(487)-1673*P
Next P
dim ystartGH(SN)
For P = 1 to SN
ystartGH(P)=-rnd(579)-1361*P
Next P
dim ystartMY(SN)
For P = 1 to SN
ystartMY(P)=-rnd(709)-1879*P
Next P
dim ystartUL(SN)
For P = 1 to SN
ystartUL(P)=-rnd(749)-1925*P
Next P
dim ystartSP(SN)
For P = 1 to SN
ystartSP(P)=-rnd(411)-1482*P
Next P
For P = 1 to SN
Sprite P,xstart(P),ystartPH(P),1 : offset sprite P,90,90
Next P
For P = 1 to SN
Sprite P+SN,xstart(P),ystartPO(P),2 : offset sprite P+SN,90,90
Next P
For P = 1 to SN
Sprite P+(SN*2),xstart(P),ystartDE(P),3 : offset sprite P+SN*2,90,90
Next P
For P = 1 to SN
Sprite P+(SN*3),xstart(P),ystartTB(P),4 : offset sprite P+SN*3,90,90
Next P
For P = 1 to SN
Sprite P+(SN*4),xstart(P),ystartGH(P),5 : offset sprite P+SN*4,90,90 : set sprite alpha P+SN*4,128
Next P
For P = 1 to SN
Sprite P+(SN*5),xstart(P),ystartMY(P),6 : offset sprite P+SN*5,90,90 : set sprite alpha P+SN*5,128
Next P
For P = 1 to SN
Sprite P+(SN*6),xstart(P),ystartUL(P),7 : offset sprite P+SN*6,90,90
Next P
For P = 1 to SN
Sprite P+(SN*7),xstart(P),ystartSP(P),8 : offset sprite P+SN*7,90,90
Next P
REM score designations.
dim points(SN*8)
For P = 1 to SN*8
points(P)=10+2*(P/SN)
next P
GetHighscore()
dim score(1)
score(1)=score
dim highscore(1)
highscore(1)=highscore
return
Delay:
wait key
cls
return
OnClick:
UpdateMouse()
for P = 1 to (8*SN)
if SPRITE EXIST(P)
if Trigger="Shoot"
s=sprite collision(1002,P)
if s <> 0 then INC F#,.025: INC E,1 : score = score + points(P) : delete SPRITE P : play sound 2
endif
endif
next P
if Trigger="Shoot" then Sprite 999,mousex(),mousey(),999 : offset sprite 999,55,55 : set sprite alpha 999,128 : show sprite 999 : play sound 3
if Trigger="Held" then Sprite 999,mousex(),mousey(),999 : offset sprite 999,55,55 : set sprite alpha 999,128 : show sprite 999
if Trigger="NotPulled" then Sprite 999,mousex(),mousey(),999 : offset sprite 999,55,55 : set sprite alpha 999,128 : show sprite 999
if Trigger="Lifted" then Sprite 999,mousex(),mousey(),999 : offset sprite 999,55,55 : set sprite alpha 999,128 : show sprite 999
return
CityHit:
for P = 1 to (8*SN)
if sprite exist(P)
k=sprite collision(2011,P)
if k = 1 then delete sprite P : INC D,1 : score = score - (points(P)/2) : play sound 4
endif
next P
return
RefScreen:
` the sprite display. include the movement and display subroutines
paste image 1000,0,0
sprite 1002,mousex(),mousey(),1002 : hide sprite 1002
For P = 1 to (8*SN)
if sprite exist(P) then move Sprite P,-.45*(F#+1)
Next P
if score(1) > highscore(1) then highscore = score
text 0,0,"High Score: "+str$(highscore(1))
text 0,38,"Your Score: "+str$(score(1))
return
EndGame:
if E = 140 then gosub EndGameGood
if D = 30 then gosub EndGameBad
return
EndGameBad:
hide all sprites
cls
paste image 5001,0,0
text 0,0,"High Score: "+str$(highscore(1))
text 0,38,"Your Score: "+str$(score(1))
sync
if score(1) = highscore(1) then SaveHighscore(score)
gosub delay
end
return
EndGameGood:
hide all sprites
cls
paste image 5002,0,0
text 0,0,"High Score: "str$(highscore(1))
text 0,38,"Your Score: "str$(score(1))
sync
if score(1) = highscore(1) then SaveHighscore(score)
gosub delay
end
return
Function UpdateMouse()
LastMClick=MClick
MClick=MouseClick()
`Mouse is not held Down
if MClick=0 and LastMClick=0 then Trigger="NotPulled"
`LeftMouse is held Down
if MClick=1 and LastMClick=0 then Trigger="Shoot"
`LeftMouse has just Been Pressed
if MClick=1 and LastMClick=1 then Trigger="Held"
`LeftMouse has just been Lifted
if MClick=0 and LastMClick=1 then Trigger="Lifted"
Endfunction
function GetHighscore()
if file exist("datahiscore.dat")
open to read 1, "datahiscore.dat" : ` Open the hiscore file
read file 1, value : ` read in the hiscore
close file 1 : ` close the hiscore file
else
value=0 : ` when the file does not exist, pass back a zero
endif
endfunction
function SaveHighscore(score)
if file exist("datahiscore.dat") then delete file "datahiscore.dat" : ` remove the hiscore file
open to write 1, "datahiscore.dat" : ` create a new one
write file 1, score : ` write the score to the file
close file 1 : ` close the hiscore file
endfunction
[EDIT] Nevermind, I have it working... ugh...