I have a page with controls on it, when a user clicks on the option to change the control, I would like it to switch to a small box with a cursor so that they can type in the new setting. I try to use OpenScreen(800,600,16,"change controls") but it dies on FlipBuffers() right after you click on the item.
Also, I tried putting a sprite in place of the screen change, but that goes away when you release the mouse button...
And finally, if you click and hold, then move the mouse it dumps you from the program all together.
My code IS listed below, but I've also included it in the zip located at:
http://www.kennethcraft.com/designs/pb/hunter.zip
Its rather long, and I may be doing something wrong, but here's the code I'm using:
Code: Select all
; -----------------------------------------------
; The Options Menu Screen
; -----------------------------------------------
;------------------------------------------------
;Attempt To open the screen at 800x600x16 And init the mouse
InitSprite()
InitKeyboard()
InitMouse()
If OpenScreen(800,600, 16, "Options Screen") = 0
MessageRequester("Error", "Impossible to open a 800*600 16 bit screen",0)
End
EndIf
; Goto Subs and run extra commands
Gosub GetUserControls
Gosub LoadUserControls
;------------------------------------------------
; Set and define Variables
x = 100
y = 100
;------------------------------------------------
; Load the background image for the main menu
LoadSprite(0,"bmp\controls.bmp",0)
LoadSprite(1,"bmp\arrow.bmp",0)
LoadSprite(2,"bmp\ctrlchange.bmp",0)
InitSound()
LoadSound(0,"snd\ssg24.wav")
;PlaySound(0,1)
MouseLocate(400, 300)
TransparentSpriteColor(1, 0, 0, 0)
Repeat
FlipBuffers()
ExamineKeyboard()
ExamineMouse()
x = MouseX() ; Returns actual x pos of our mouse
y = MouseY() ; Returns actual y pos of our mouse
If MouseButton(3)
End
EndIf
DisplaySprite(0,0,0)
;-----------------
StartDrawing(ScreenOutput()) ; screenoutput writes to buffer
DrawingMode(1)
FrontColor(255,255,255)
Locate(323,195)
DrawText("UP") ; up foward
Locate(323,220)
DrawText("DOWN") ; down backward
Locate(323,245)
DrawText("LEFT") ; left move left
Locate(323,270)
DrawText("RIGHT") ; right move right
Locate(323,294)
DrawText("C") ; C crouch
Locate(323,320)
DrawText("RSHFT") ; rshift run
Locate(323,345)
DrawText("M-1") ; mouse 1 shoot
Locate(323,370)
DrawText("/") ; / zoom in
Locate(323,393)
DrawText("\") ; \ zoom out
Locate(323,419)
DrawText("R") ; R reload
Locate(523,195)
DrawText("1") ; 1 choose first item
Locate(523,220)
DrawText("2") ; 2 choose second item
Locate(523,245)
DrawText("3") ; 3 choose third item
Locate(523,270)
DrawText("4") ; 4 choose forth item
Locate(523,294)
DrawText("5") ; 5 choose fifth item
Locate(523,320)
DrawText("6") ; 6 choose sixth item
Locate(523,345)
DrawText("7") ; 7 choose seventh item
Locate(523,370)
DrawText("8") ; 8 choose eighth item
Locate(523,393)
DrawText("9") ; 9 choose ninth item
Locate(523,419)
DrawText("PGUP") ; page up next item
Locate(523,444)
DrawText("PGDN") ; page down previous item
StopDrawing()
DisplayTransparentSprite(1, x-SpriteWidth(1)/2, y-SpriteHeight(1)/2)
Gosub CheckMouseLocations
ForEver
End
GetUserControls:
;-------------------------------------------------
; Openning the Default key map and creating a copy
; for the users custom settings.
NewList KeyMap.s()
ClearList(KeyMap())
; Open Default keys for Read Only Access
If FileSize("dta\controls.htr") = -1
If ReadFile(0,"dta\controls.htr") = 0
;MessageRequest("Error!", "File controls.htr cannot be opened",0)
End
Else
; Put File data into array KeyMap()
a = 0
For a = 0 To Lof()
AddElement(KeyMap())
KeyMap() = ReadString()
Next a
b = CountList(KeyMap())
; Create User file
CreateFile(1, "dta\usermap.htr")
For a = 0 To b
SelectElement(KeyMap(), a)
WriteStringN(KeyMap())
Next a
CloseFile(0)
EndIf
EndIf
Return
LoadUserControls:
;--------------------------------------------------
; Open the usermap.htr file to display in controls
ClearList(KeyMap())
If ReadFile(1,"dta\usermap.htr") = 0
End
Else
a = 0
For a = 0 To Lof()
AddElement(KeyMap())
KeyMap() = ReadString()
Next a
EndIf
CloseFile(1)
Return
CheckMouseLocations:
mx = MouseX()
my = MouseY()
;--------------------------------------------------
; Check the left column
If mx>320 And mx<370
If my>202 And my<222 ;Forward
If MouseButton(1)
DisplaySprite(2, 400, 300)
EndIf
ElseIf my>227 And my<247 ;Backward
If MouseButton(1)
OpenScreen(800,600,16,"Change Controls")
EndIf
ElseIf my>252 And my<272 ;Left
If MouseButton(1)
End
EndIf
ElseIf my>277 And my<297 ;Right
If MouseButton(1)
End
EndIf
ElseIf my>302 And my<322 ;Crounch
If MouseButton(1)
End
EndIf
ElseIf my>327 And my<347 ;Run
If MouseButton(1)
End
EndIf
ElseIf my>352 And my<372 ;Fire
If MouseButton(1)
End
EndIf
ElseIf my>377 And my<397 ;Zoom In
If MouseButton(1)
End
EndIf
ElseIf my>402 And my<422 ;Zoom Out
If MouseButton(1)
End
EndIf
ElseIf my>427 And my<447 ;Reload
If MouseButton(1)
End
EndIf
ElseIf my>452 And my<472 ;Blank Spot
If MouseButton(1)
EndIf
EndIf
EndIf
Return
one more question: how can I determine if an array already exists in ram? Walking through the code it looks like if I go into the page 2 times I'm going to error out when it hits NewList KeyMap.s() on the second run?
thanks