News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Why does my code upset pb?

Started by Andreas, April 30, 2008, 11:42:14 PM

Previous topic - Next topic

Andreas

I have been mocking around in pb and this code crashes pb. And I have no idea why. Well ok I have some idea but a second opinion would be nice to learn. ;D



; PROJECT : Main
; AUTHOR  : Andy
; CREATED : 01.05.2008
; EDITED  : 01.05.2008
; ---------------------------------------------------------------------

Size=10
  CreateImage 1,Size,Size
  RenderPhongImage 1,Size/2,Size/2,$ffff8f,size*2.6,2.0
  openscreen 800,600,32,1


type tParticle

x#,y#

xSpeed#,ySpeed#

bullet
lifespan

image

endtype

dim part as tParticle list


ScreenVsync on





rem ---------------------------------------
rem                 MAIN LOOP
rem----------------------------------------
w=getscreenwidth()
h=getscreenheight()

setfps 60
repeat


cls 0


mx=mousex()
my=mousey()

if spacekey() and done=false
for lp=1 to 360 step 10
;mx=mousex()
;my=mousey()
mx=200 : my=300
createPart(mx,my,lp,rnd(3.0)+1,5000,1,false)
done=true
next
endif

xBase=400
yBase=500
dis=30

print getangle2d(xBase,yBase,mx,my)
ma=getangle2d(xBase,yBase,mx,my)
;line xBase,yBase,mx,my
if 1=mousebutton()
createPart(xBase,yBase,ma,rnd(3.0)+1,3000,1,true)
endif

for lp=0 to dis
dot xBase+cos(ma)*lp,yBase+sin(ma)*lp
next
updatePart()
sync



until esckey()

function explode(x#,y#)

for lp=1 to 360 step 10
;mx=mousex()
;my=mousey()
mx=200 : my=300
createPart(x,y,lp,rnd(3.0)+1,5000,1,false)
next

endfunction
function createPart(x#,y#,angle#,speed#,lifeSpan,image,bullet)

part= new tParticle

part.x# =x#
part.y# =y#

part.xspeed# =cos(angle#)*speed#
part.yspeed# =sin(angle#)*speed#

part.lifespan =timer()+lifeSpan
part.image =image

part.bullet =bullet

endfunction
Function updatePart()


currentTime=timer()

rem --ONE FOR ALL--
for each Part()

; --- Death Checks
if part.lifespan=<currentTime

if part.bullet=true
x#=part.x#
y#=part.y#
explode(x#,y#)
endif

part = null
continue
endif


part.x#=part.x#+part.xspeed#
part.y#=part.y#+part.yspeed#

drawimage part.image,Part.x#,part.y#,0



next

endfunction






Andreas
The best thing about making space shooters is that space, is easy to draw.

kevin

#1
   You've create an infinite loop.   In the update function you call the explode function, which creates bunch of new particles.  However your not preserving the particle list containers current pointer.  So after calling the Explode function and returning to the Update function, the list pointer will have been moved..  This process will lock the routine in a infinite loop until the VM runs out of memory.

PlayBASIC Code: [Select]
function explode(x#,y#)
OldPointer=GetListpos(Part())
for lp=1 to 360 step 10
createPart(x#,y#,lp,rnd(3.0)+1,5000,1,false)
next
SetListPos Part(),OldPOinter

endfunction



Andreas

I see.. Thanks. :) Going to play around some more with this.
The best thing about making space shooters is that space, is easy to draw.

Andreas

=GetListPos(ListHandle())
=GetListFirst(ListHandle())      
=GetListPrevious(ListHandle())       
=GetListNext(ListHandle())
=GetListSize(ListHandle())   

I can't get any of these to work in 1.71. They'r not recognized as commands.
The best thing about making space shooters is that space, is easy to draw.

kevin

#4
They're not in 1.71

Andreas

#5
Ok thanks.
Maybe my noob ass should have stuck with 1.63.. But the Dx3D sprites look so good :)

Let's see, I'll install both!  8)
andreas
The best thing about making space shooters is that space, is easy to draw.

kevin


Andreas

Now that I have fallen in love with  linked lists :-* is,
there any posibility that they will find there way in to 1.71-->?

andreas

(please say yes, please say yes)
The best thing about making space shooters is that space, is easy to draw.

kevin

#8
   Yep for sure! -  The bare bones list stuff is in 1.71 also, but unfortunately those exposed helper commands aren't.   The current focus is get the PlayMapper project to useful state (just about there) so I can get back to PlayBasic updates.

 The current WIP edition (from a few months back) is 1.72 however.  This has a number of new changes from even the 1.71 releases.   Mainly because it's stricter than previous editions of PB.

 
  Not sure how far away a version (any version) of 1.72 is however..