Page 1 of 1
					
				werid problem
				Posted: Fri Sep 05, 2003 10:26 pm
				by Dreglor
				Hello, i'am new to purebasic and to the fourms and i been playing around with pb and i found that some lines of code don't work in some places
inparticular, lines that return to a varibal
i have to find one because i found a work around to them
but it just annoying becuase it will return one number like it was a constant it can only set once and then never change but it does not give any errors what so ever
if any one has found this problem before please tell me if this is a bug or something i doing wrong
			 
			
					
				
				Posted: Fri Sep 05, 2003 10:42 pm
				by Karbon
				Lets see some code! 

 
			
					
				
				Posted: Thu Sep 11, 2003 6:02 am
				by Dreglor
				sorry it took so long but i found it
i had forgoten what i got it from
i try it again it it does it work
but if i use a diffrent  (but identical resulting) line of code it works perfectly
i have tested this in a diffrent lang and it works just fine...
heres the code:
Code: Select all
If InitSprite()=0
  MessageRequester("Fatal Error!","Could not initalize directX",0)
  End
EndIf
#screen_width.w=1024
#screen_height.w=768
If OpenScreen(#screen_width,#screen_height,16,"")=0
  MessageRequester("Fatal Error!","Could not initalize the screen",0)
  End
EndIf
If InitKeyboard()=0
  MessageRequester("Fatal Error!","Could not initalize the keyboard",0)
  End
EndIf
SetFrameRate(60) ;i put this in to keep the frame rate constant
xmax.w=10000
ymax.w=10000
zmax.w=2000
sspeed.w=-10
zmin.w=10
num.l=5000 ;get slow around 55000-60000 and i have 2.66 cpu ( by slow i mean if it gets below 60 fps, the set frame rate)
centerx.w=#screen_width/2
centery.w=#screen_height/2
zoom.w=60
shade.w=0
fnum.w=0
fps.s="0"
Dim sx(num)
Dim sy(num)
Dim sz(num)
For i=0 To num
    sx(i)=Random(xmax)-xmax/2
    sy(i)=Random(ymax)-ymax/2
    sz(i)=Random(zmax)
Next i
Repeat
  StartDrawing(ScreenOutput())
  start=Date()
  For i=0 To num
    sz(i)=sz(i)+sspeed
    If sz(i)<=zmin
      sz(i)=zmax
      sx(i)=Random(xmax)-xmax/2
      sy(i)=Random(ymax)-ymax/2
    EndIf
    screenx.w=(sx(i)*zoom)/sz(i)+centerx
    screeny.w=(-sy(i)*zoom)/sz(i)+centery
    shade=255-(sz(i)/zmax*255) ;does'nt work always returns 255 i don't know why
    ;shade=Int(255/zmax* -sz(i)) ;does work
    If screenx < #screen_width
      If screeny < #screen_height
        If screenx > 0
          If screeny > 0
           Plot(screenx,screeny,RGB(shade,shade,shade))
          EndIf
        EndIf
      EndIf
    EndIf
  Next i
  DrawText("FPS: "+fps)
  StopDrawing()
  FlipBuffers()
  ClearScreen(0,0,0)
  ExamineKeyboard()
  If Date() > start
    fps=Str(fnum)
    fnum=0
    start=Date()
  Else
    fnum=fnum+1
  EndIf
Until KeyboardReleased(#PB_Key_Escape)
CloseScreen()
End
the one that doesn't work only out puts 255
and can any one verify that my fps counter work properly?
so if any one spot why this isn't working i would love to know why it happing and if it should do that
 
			
					
				
				Posted: Thu Sep 11, 2003 5:10 pm
				by MikeB
				In the line that does not work you are taking a number sz(i) which is up to 
2000 and dividing by 2000 so that the result is always 0. something.
PB is then interpreting this as an integer and so the result is always 0.
0 * anything is still 0
so you get 255-0  =  255 every time!
simple really
MikeB
			 
			
					
				
				Posted: Thu Sep 11, 2003 6:11 pm
				by GedB
				To summarise, all you have to do to fix the original line is change line 25 to 
Alternatively you can wrap the bad line in an Int(), just like the good line.
Interestingly, if you remove the Int() from the good line, it now fails but this time the result is always 0, so you see nothing unless you change the background colour.
If you are assigning to a variable then that target seems to be used for storing interim results.  This probably saves having to allocate new memory locations so it could be a deliberate optimisation.
When the expression is destined for a function call, then that calls paramater is the target paramater.
Here's a demonstration:
Code: Select all
Procedure.l lParam(p.l)
  ProcedureReturn p * 100
EndProcedure
Procedure.f fParam(p.f)
  ProcedureReturn p * 100
EndProcedure
l.l = (10/3) * 100
f.f = (10/3) * 100
Debug l
Debug f
Debug lParam(10/3)
Debug fParam(10/3)
returns
 
			
					
				
				Posted: Thu Sep 11, 2003 11:35 pm
				by Dreglor
				hmm
i think the problems comes as a result of data types because the bad line it has 2 diffrent data types (word and long) so maybe purebsic does not have any datatype converting yet? or is it just buggy?
from what i can see wrapping int() around the line thanks GedB
			 
			
					
				
				Posted: Fri Sep 12, 2003 12:09 am
				by Kale
				so maybe purebsic does not have any datatype converting yet?
You mean like Javascript? No no no... thats just lazy!  

  PureBasic is a 'Statically Typed' language, like all professional languages are. You must define a type for each variable and stick to it (meaning: the variable can not change type during run time).
 
			
					
				
				Posted: Fri Sep 12, 2003 10:08 am
				by GedB
				Yes, Purebasic is optimised for Speed.
Other languages trade processor time for the programmers convenience.