News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Playbasic crashing when compiling

Started by darkx, May 24, 2010, 04:55:53 PM

Previous topic - Next topic

darkx

I am currently making a function that will create sprites for me however when I run the code it seems to crash while compiling. This also seems to happen even if I just press check syntax.

PlayBASIC Code: [Select]
`create dynamic object
psub createdynamicobject(ty,fr,fpos,x,y,gx,gy,gh,gra,maxhp,curhp,speedm,orgspeed,curspeed,mag,maxmag,player,sidesol,topsol,bottomsol,atton1,attst1,attend1,atton2,attst2,attend2,atton3,attst3,attend3,atton4,attst4,attend4,atton5,attst5,attend5,walkon,walkst,walkend,jumpon,jumpst,jumpend,damon,damst,damend,stunon,stunst,stunend,deathon,deathst,deathend,idleon,idlest,idleend,lookupon,lookupst,lookupend,lookdownon,lookdownst,lookdownend)

`find a free dynamic object id to use
for i=0 to dynamicobjectlimit
if dynamicobject(i).used=0
dynamicobject(i).used=1
e=i
exitfor
endif
next i

`create the sprite
dynamicobject(e).framesheetid=ty
dynamicobject(e).framerate=fr
dynamicobject(e).animid=newanim(dynamicobject(e).framesheetid,fr)
dynamicobject(e).animpos=fpos
dynamicobject(e).spriteid=newsprite(getscreenwidth()+9999,getscreenheight()+9999,getanimimage(dynamicobject(e).animpos))
dynamicobject(e).imageid=getanimimage(dynamicobject(e).animpos)



dynamicobject(e).x=x
dynamicobject(e).y=y
dynamicobject(e).gravityx=gx
dynamicobject(e).gravityy=gy
dynamicobject(e).ghost=gh
dynamicobject(e).gravity=gra
dynamicobject(e).maxhp=maxhp
dynamicobject(e).currenthp=curhp
dynamicobject(e).speedmax=speedm
dynamicobject(e).orginalspeed=orgspeed
dynamicobject(e).currentspeed=curspeed
dynamicobject(e).magic=mag
dynamicobject(e).maxmagic=maxmag
dynamicobject(e).player=player
dynamicobject(e).sidesolid=sidesol
dynamicobject(e).topsolid=topsol
dynamicobject(e).bottomsolid=bottomsol


`animation
`attack anim 1
dynamicobject(e).attackanimon1=atton1
dynamicobject(e).attackstart1=attst1
dynamicobject(e).attackend1=attend1
`attack anim 2
dynamicobject(e).attackanimon2=atton2
dynamicobject(e).attackstart2=attst2
dynamicobject(e).attackend2=attend2
`attack anim 3
dynamicobject(e).attackanimon3=atton3
dynamicobject(e).attackstart3=attst3
dynamicobject(e).attackend3=attend3
`attack anim 4
dynamicobject(e).attackanimon4=atton4
dynamicobject(e).attackstart4=attst4
dynamicobject(e).attackend4=attend4
`attack anim 5
dynamicobject(e).attackanimon5=atton5
dynamicobject(e).attackstart5=attst5
dynamicobject(e).attackend5=attend5
`walk anim
dynamicobject(e).walkanimon=walkon
dynamicobject(e).walkstart=walkst
dynamicobject(e).walkend=walkend
`jumpanim
dynamicobject(e).jumpanimon=jumpon
dynamicobject(e).jumpstart=jumpst
dynamicobject(e).jumpend=jumpend
`damagedanim
dynamicobject(e).damageanimon=damon
dynamicobject(e).damagestart=damst
dynamicobject(e).damageend=damend
`stunanim
dynamicobject(e).stunanimon=stunon
dynamicobject(e).stunstart=stunst
dynamicobject(e).stunend=stunend
`deathanim
dynamicobject(e).deathanimon=deathon
dynamicobject(e).deathstart=deathst
dynamicobject(e).deathend=deathend
`idle anim
dynamicobject(e).idleanimon=idleon
dynamicobject(e).idlestart=idlest
dynamicobject(e).idleend=idleend
`lookupanim
dynamicobject(e).lookupanimon=lookupon
dynamicobject(e).lookupstart=lookupst
dynamicobject(e).lookupend=lookupend
`lookdownanim
dynamicobject(e).lookdownanimon=lookdownon
dynamicobject(e).lookdownstart=lookdownst
dynamicobject(e).lookdownend=lookdownend




endpsub dynamicobject(e).objectid



As you can see I am passing a lot of variable through the psub function, so I'm wondering if I did anything wrong to cause this crash or if it has something to do with psub and function.

Note I have also tried function although the results are the same.



[Edit]

It seems there is a limit to the number of variables passable through a function and psub because after removing these 4 variables ty,fr,fpos, the compiler does not crash. Is there any possible way to extend the limit?

kevin


darkx

I see, Thank you for the response Kevin.

kevin


darkx ,

   Can you explain what you're trying to do.  Seems like your trying wrap up an generic interface.    If you want to pass lots of stuff into a functions, this is generally done by using structures (types).    So we fill in the stucture, then pass it to the function to work upon.   The trouble with passing too much data (individually) , is the function quickly losses it's usefulness as generic 'problem' solver.  So rather than have mega functions, a better idea is to break these down into smaller, more focused  chunks.

    In the example above, you could break the big function into several parts.  But here i've just cut, the section that initializies the animations from the core properties.   These could be cut down further. But anway..





`create dynamic object
psub createdynamicobject(ty,fr,fpos,x,y,gx,gy,gh,gra,maxhp,curhp,speedm,orgspeed,curspeed,mag,maxmag,player,sidesol,topsol,bottomsol)

`find a free dynamic object id to use
e=GetFreeCell(dynamicobject())

`create the sprite
dynamicobject(e).framesheetid=ty
dynamicobject(e).framerate =fr
dynamicobject(e).animid =newanim(dynamicobject(e).framesheetid,fr)
dynamicobject(e).animpos =fpos
dynamicobject(e).spriteid =newsprite(getscreenwidth()+9999,getscreenheight()+9999,getanimimage(dynamicobject(e).animpos))
dynamicobject(e).imageid =getanimimage(dynamicobject(e).animpos)

dynamicobject(e).x=x
dynamicobject(e).y=y
dynamicobject(e).gravityx=gx
dynamicobject(e).gravityy=gy
dynamicobject(e).ghost=gh
dynamicobject(e).gravity=gra
dynamicobject(e).maxhp=maxhp
dynamicobject(e).currenthp=curhp
dynamicobject(e).speedmax=speedm
dynamicobject(e).orginalspeed=orgspeed
dynamicobject(e).currentspeed=curspeed
dynamicobject(e).magic=mag
dynamicobject(e).maxmagic=maxmag
dynamicobject(e).player=player
dynamicobject(e).sidesolid=sidesol
dynamicobject(e).topsolid=topsol
dynamicobject(e).bottomsolid=bottomsol
endpsub e


`create dynamic object
psub SetdynamicobjectAnimations(e,atton1,attst1,attend1,atton2,attst2,attend2,atton3,attst3,attend3,atton4,attst4,attend4,atton5,attst5,attend5,walkon,walkst,walkend,jumpon,jumpst,jumpend,damon,damst,damend,stunon,stunst,stunend,deathon,deathst,deathend,idleon,idlest,idleend,lookupon,lookupst,lookupend,lookdownon,lookdownst,lookdownend)


`animation
`attack anim 1
dynamicobject(e).attackanimon1=atton1
dynamicobject(e).attackstart1=attst1
dynamicobject(e).attackend1=attend1

`attack anim 2
dynamicobject(e).attackanimon2=atton2
dynamicobject(e).attackstart2=attst2
dynamicobject(e).attackend2=attend2
`attack anim 3
dynamicobject(e).attackanimon3=atton3
dynamicobject(e).attackstart3=attst3
dynamicobject(e).attackend3=attend3
`attack anim 4
dynamicobject(e).attackanimon4=atton4
dynamicobject(e).attackstart4=attst4
dynamicobject(e).attackend4=attend4
`attack anim 5
dynamicobject(e).attackanimon5=atton5
dynamicobject(e).attackstart5=attst5
dynamicobject(e).attackend5=attend5
`walk anim
dynamicobject(e).walkanimon=walkon
dynamicobject(e).walkstart=walkst
dynamicobject(e).walkend=walkend
`jumpanim
dynamicobject(e).jumpanimon=jumpon
dynamicobject(e).jumpstart=jumpst
dynamicobject(e).jumpend=jumpend
`damagedanim
dynamicobject(e).damageanimon=damon
dynamicobject(e).damagestart=damst
dynamicobject(e).damageend=damend
`stunanim
dynamicobject(e).stunanimon=stunon
dynamicobject(e).stunstart=stunst
dynamicobject(e).stunend=stunend
`deathanim
dynamicobject(e).deathanimon=deathon
dynamicobject(e).deathstart=deathst
dynamicobject(e).deathend=deathend
`idle anim
dynamicobject(e).idleanimon=idleon
dynamicobject(e).idlestart=idlest
dynamicobject(e).idleend=idleend
`lookupanim
dynamicobject(e).lookupanimon=lookupon
dynamicobject(e).lookupstart=lookupst
dynamicobject(e).lookupend=lookupend
`lookdownanim
dynamicobject(e).lookdownanimon=lookdownon
dynamicobject(e).lookdownstart=lookdownst
dynamicobject(e).lookdownend=lookdownend

endpsub e






kevin


  Here's a bit of example as something to chew on.     Here's i've a similiar strutcure do what darkx's got, except i've broken the fields up into common groups, focusing upon the animations.    While i'm not totally sure what dakrs using the various properties for, i've just added my own dummies purely as an example.     Anyway, so what we're doing is creating a small type to hold all the properties about an indidual characters animations state.    Then we're binding all the different animations into a second type, which will hold all of the various attacks as well as running,walking and death.   Then this is included in the main type (nested). 

   This is useful in PlayBASIC for two reasons,  we can get a  pointer to any nested type within a another and we can pass pointers into functions.

   So on the surface it appears that we've just simplify our initialized code a bit.   But what we've really done, is conceptually break down the big generic blobs of code into smaller more focues chunks.    In this particular example the 'SetAnim" function can be used on data of type tCharacterAnimStates.    Secondly, if we use this function as our method for altering the properties within a tCharacterAnimStates type, we're far less likely to be impacted by any changes to the structures. 

 
   



; Properties of this animation
Type tCharacterAnimStates
State as integer
index as integer
EndType


; Animations Groups into a single structure
Type tCharacterAnim
Attack1 as tCharacterAnimStates
Attack2 as tCharacterAnimStates
Attack3 as tCharacterAnimStates
Attack4 as tCharacterAnimStates
Attack5 as tCharacterAnimStates

Walking as tCharacterAnimStates
Running as tCharacterAnimStates
Death as tCharacterAnimStates
EndType

       ; Characters type
Type MyCharacter
; some properties this Character has
X,Y
Sprite
Score

; the Animation sub trpe
Anim as tCharacterAnim

EndType



Dim Objs(0) as MyCharacter


index=NewCharacter(100,200)

print Index

Sync
waitkey


Psub NewCharacter(x,y)
Index=getFreeCell(Objs())
Objs(index)= New MyCharacter
Objs(index).x=x
Objs(index).y=y

; init the States of Attack Anims  to some made values for this demo
SetAnim(Objs(index).Anim.Attack1,  on,10)  ;
SetAnim(Objs(index).Anim.Attack2,  on,20)  ;
SetAnim(Objs(index).Anim.Attack3,  on,30)  ;
SetAnim(Objs(index).Anim.Attack4,  on,40)  ;
SetAnim(Objs(index).Anim.Attack5,  on,50)  ;

SetAnim(Objs(index).Anim.Walking,  on,50)  ;
SetAnim(Objs(index).Anim.Running,  on,50)  ;
SetAnim(Objs(index).Anim.Death,  on,50)  ;

EndPsub Index


Psub SetAnim(me as tCharacterAnimStates pointer, State,Index)
me.State=State
me.index=index
EndPsub