Found an issue in SpiderBasic ? Please report it here !
User avatar
Paul
 
Posts: 79
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada

Wrong Type returned

by Paul Sat Feb 01, 2020 3:11 pm

Help File says...
MouseX() - Returns the actual mouse 'x' position (in pixels) on the current screen

The result is always #.5 (half a pixel more)
Even if I specify the Type as Integer, it still returns a float.
And how can it return Float if you've cast as Integer??

If I specifically tell it to return a float, it then returns an Integer ( # instead of #.5 )

Code: Select all
InitMouse()

Global targetx.i
;Global targetx.f

Procedure RenderEngine()
  ExamineMouse()
 
  targetx=MouseX()
  Debug "Result: "+Str(targetx)
 
  FlipBuffers()
EndProcedure


If OpenWindow(1,0,0,640,480,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(1),0,0,640,480)
  BindEvent(#PB_Event_RenderFrame, @RenderEngine())
  FlipBuffers()
EndIf
Andy
 
Posts: 17
Joined: Sat Feb 15, 2020 5:19 pm

Re: Wrong Type returned

by Andy Mon Feb 17, 2020 6:34 am

Hi, this works fine with SB 2.30 and chrome Version 80.0.3987.106 both with integer and float. If you want to display floats, don't forget to specify the amount of decimal places with StrF()

Code: Select all
StrF(targetx,2)
User avatar
Paul
 
Posts: 79
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada

Re: Wrong Type returned

by Paul Mon Feb 17, 2020 2:34 pm

I don't want to return a float... but MouseX and MouseY will randomly return floats even when you specifically tell it you want an Integer.
For some reason when I run the above example it no longer shows the problem :shock:

Try this example and see if you get a float returned:
Code: Select all
InitMouse()

Global targetx.i
;Global targetx.f

Procedure RenderEngine()
  ExamineMouse()
 
  targetx=MouseX()
  Debug "Result: "+Str(targetx)
 
  FlipBuffers()
EndProcedure


If OpenWindow(1,0,0,641,481,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(1),0,0,641,481)
  BindEvent(#PB_Event_RenderFrame, @RenderEngine())
  FlipBuffers()
EndIf


When I run this one it returns 10.5, 12.5, 14.5 etc even though I have specified targetx to be an integer using target.i
Then if I specify targetx to return a float using targetx.f it returns an integer.

Let me know what the results of the above code show you.
Andy
 
Posts: 17
Joined: Sat Feb 15, 2020 5:19 pm

Re: Wrong Type returned

by Andy Mon Mar 09, 2020 3:49 pm

It looks like a bug.

For now, use

Code: Select all
StrF(targetx,0)
Return to Bugs Reports

Who is online

Users browsing this forum: No registered users and 0 guests