Well, hard to tell why it's not working from just the small snippets you provided. I created a small working example for myself and everything works fine. It stops/starts the starfield and finally exits when position=4. Maybe saving the result of Ptk_GetPosition in a global variable (i.e. position=Ptk_GetPosition() ) will already do the trick in your case... Anyway, here's my example. ZIP con exe attached. (Assumes you have the userlib installed already for everyone else!)
Pad.
MAX_STAR=500
STAR_SPEED=6
Global Dim star_x.l(MAX_STAR)
Global Dim star_y.l(MAX_STAR)
Global Dim star_z.l(MAX_STAR)
Global speed=4
InitSprite() : InitKeyboard()
OpenWindow(1, 0, 0, 800, 600, "Ptk_GetPosition() Example", #PB_Window_ScreenCentered )
OpenWindowedScreen(WindowID(1), 0, 0, 800, 600, 0, 0, 0)
Ptk_InitDriver(GetForegroundWindow_(),20)
Ptk_InitModule(?tune,0)
Ptk_Play()
Procedure rnd(min.w,max.w)
a = max - Random (max-min)
ProcedureReturn a
EndProcedure
Procedure setup_stars()
For c.w=0 To 500
star_x(c)= Rnd(-600/2,800/2) << 6
star_y(c)= Rnd(-600/2,800/2) << 6
star_z(c)=Rnd(2,255)
Next
EndProcedure
Procedure UpdateStar()
For c=0 To 500
star_z(c)=star_z(c)-speed
If star_z(c)<=2
star_z(c)=255
EndIf
s_x=(star_x(c)/star_z(c))+(800/2)
s_y=(star_y(c)/star_z(c))+(600/2)
col=255-star_z(c)
FrontColor (RGB(col,col,col))
Box (s_x,s_y,3,3)
Next
EndProcedure
setup_stars()
Repeat
ClearScreen(RGB(0,0,0))
WaitWindowEvent(1)
StartDrawing(ScreenOutput())
position=Ptk_GetPosition()
If position=1 : speed=0 : EndIf
If position=2 : speed=4 : EndIf
If position=3 : speed=0 : EndIf
updatestar()
StopDrawing()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape) Or position=4
Ptk_Stop()
Ptk_ReleaseDriver()
End
DataSection
tune:
IncludeBinary "Comic Bakery Remix.ptp"
EndDataSection