Posted: 28th Aug 2011 0:06
Iam a bit stuck and belive its extremely simple ?
But i cant get the app kit to return an value from inside the function.

function do_particles()
NR = create particle()
endfunction NR

And to get the value should i well only do this?

My_new_value = do_particles()

As its the same as My_new_value = NR ?
Posted: 28th Aug 2011 0:24
This works:
+ Code Snippet
rem Portrait App
SetDisplayAspect( 0.66 )

rem A Wizard Did It!
do
 Print(distance(5.0,1.0,4.0,1.0))
 Sync()
loop

function distance( x1 as float, x2 as float, y1 as float, y2 as float)
    dist as float

    dist = ((x1 - x2)^2 + (y1 - y2)^2)^(0.5)

endfunction dist


and so does this:
+ Code Snippet
rem Portrait App
SetDisplayAspect( 0.66 )

a as float
a = distance(5.0,1.0,4.0,1.0)
rem A Wizard Did It!
do
 Print(a)
 Sync()
loop

function distance( x1 as float, x2 as float, y1 as float, y2 as float)
    dist as float

    dist = ((x1 - x2)^2 + (y1 - y2)^2)^(0.5)

endfunction dist



Maybe you need to declare NR? You might also need to declare My_new_value.
Posted: 28th Aug 2011 1:11
Its the weird part as it dosent work here ???

// Particles_Setup (IMG , xDir , yDir , Life , Size , Ang , Rate , X , Y )
Player.Engine = Particles_Setup ( Player.Engine , img_Particle , -50 , 0 , 0.3 , 16 , 80 , 60 , GetSpriteX ( Player.ID ) , GetSpriteY ( Player.ID )+ (GetSpriteHeight( Player.ID )/2) )

And inside my particle function...

function Particles_Setup ( id as integer , IMG as integer , xDir as integer , yDir as integer , Life as float, Size as integer , Ang as integer , Rate as integer , X as float , Y as float)

// If particles exist destroy them before creating new ones
if GetParticlesExists ( id ) = 1
DeleteParticles ( id )
endif

id = CreateParticles ( X , Y )

SetParticlesImage ( id , IMG )
SetParticlesStartZone ( id , 0, 0, 0, 0 )
SetParticlesDirection ( id , xDir , yDir )
SetParticlesLife ( id , Life )
SetParticlesSize ( id , Size )
SetParticlesAngle ( id , Ang )
SetParticlesFrequency ( id , Rate )

endfunction id

Iam a bit confused?

_______________________________________________________________________
I think i found an bug?

As this one work!

Particle.ID = Player.Engine

Player.Engine = Particles_Setup ( img_Particle , -50 , 0 , 0.3 , 16 , 80 , 60 , GetSpriteX ( Player.ID ) , GetSpriteY ( Player.ID )+ (GetSpriteHeight( Player.ID )/2) )

function Particles_Setup ( IMG as integer , xDir as integer , yDir as integer , Life as float, Size as integer , Ang as integer , Rate as integer , X as float , Y as float)

// If particles exist destroy them before creating new ones
if GetParticlesExists ( Particle.ID ) = 1
DeleteParticles ( Particle.ID )
endif

Particle.ID = CreateParticles ( X , Y )

SetParticlesImage ( Particle.ID , IMG )
SetParticlesStartZone ( Particle.ID , 0, 0, 0, 0 )
SetParticlesDirection ( Particle.ID , xDir , yDir )
SetParticlesLife ( Particle.ID , Life )
SetParticlesSize ( Particle.ID , Size )
SetParticlesAngle ( Particle.ID , Ang )
SetParticlesFrequency ( Particle.ID , Rate )

endfunction Particle.ID

But if i pass any variabel to the global type Particle.ID
inside the function so does it get screwed up?
Posted: 28th Aug 2011 1:36
As far as I can tell that should be ok but what you could try is splitting up the particle_setup function.

You could make this bit a separate function:
+ Code Snippet
// If particles exist destroy them before creating new ones
if GetParticlesExists ( id ) = 1
DeleteParticles ( id )
endif

id = CreateParticles ( X , Y )

and then pass the id received from that into the "rest" of your particle_setup function. I might not change anything but may help to isolate the problem.
Posted: 28th Aug 2011 2:16
I also noticed that if you pass more then 9 variabels in to an function so will it also get screwed up ?

Extremely weird?
Posted: 28th Aug 2011 2:34
I also noticed that if you pass more then 9 variabels in to an function so will it also get screwed up ?

Well this works:
+ Code Snippet
SetDisplayAspect( 0.66 )
SetRandomSeed( Timer())

a as integer
a = func1()
rem A Wizard Did It!
do
 Print(a)
 Sync()
loop

function func1()
    b as integer
    b = getrandom(1,2,3,4,5,6,7,8,9,0)

endfunction b

function getrandom( f as integer, g as integer, h as integer, i as integer, j as integer, k as integer, l as integer, m as integer, n as integer, o as integer )
    c = f + g + h + i + j + k + l + m + n + o
endfunction c


But yes, this is weird. What actually happens when you try to return the variable, do you get an error? or does nothing happen at all?
Posted: 28th Aug 2011 2:35
Its some weird bug in the main code for functions!
As this one work as long as i dont use or pass more then 9 variabels inside an function




+ Code Snippet
/////////////////////////////////////////
// Particle functions //////////////////
///////////////////////////////////////
function Particles_Initiate ( ID as integer ,IMG as integer , sz1 as integer , sz2 as integer , sz3 as integer , sz4 as integer, X as float , Y as float)

	// If particles exist destroy them before creating new ones
	if GetParticlesExists ( ID ) = 1
        DeleteParticles ( ID )
    endif

    ID = CreateParticles ( X , Y  )

    SetParticlesImage         ( ID , IMG )
    SetParticlesStartZone     ( ID , sz1, sz2, sz3, sz4 )

endfunction ID

function Particles_Setup (ID as integer , xDir as integer , yDir as integer , Life as float, Size as integer , Ang as integer , Rate as integer )


    SetParticlesDirection     ( ID , xDir , yDir )
    SetParticlesLife          ( ID , Life )
    SetParticlesSize          ( ID , Size )
    SetParticlesAngle         ( ID , Ang )
    SetParticlesFrequency     ( ID , Rate )

endfunction


+ Code Snippet
// Generate some engine particles

    Player.Engine = Particles_Initiate (Player.Engine, img_Particle , 0 , 0 , 0 , 0, GetSpriteX ( Player.ID ) , GetSpriteY ( Player.ID )+ (GetSpriteHeight( Player.ID )/2))

    Particles_Setup ( Player.Engine, -50 , 0 , 0.3 , 16 , 80 , 60  )


But yes, this is weird. What actually happens when you try to return the variable, do you get an error? or does nothing happen at all?

It simply freezes when i try to run the code.

The compiler dosent say anything?

Could it be that i mix floats and integers?
Some kind of limitation of memory usage?

floats use more memory then integers well ?
Posted: 28th Aug 2011 2:49
Could it be that i mix floats and integers?

I don't think so but anything is possible. I mix floats and integers all the time.

Some kind of limitation of memory usage?

Again it's possible but I'd say very unlikely, unless you have some massive array in there somewhere.

Well, the main thing is that you have something that works.
Posted: 28th Aug 2011 3:02
Will probably have to split my functions more in the app kit

I tested some more and this works !!

function Particles_Setup (ID as integer , xDir as integer , yDir as integer , Life as float, Size as integer , Ang as integer , Rate as integer , VR1 as float , VR2 as float , FC1 as float)


SetParticlesDirection ( ID , xDir , yDir )
SetParticlesLife ( ID , Life )
SetParticlesSize ( ID , Size )
SetParticlesAngle ( ID , Ang )
SetParticlesFrequency ( ID , Rate )
SetParticlesVelocityRange ( ID , VR1 , Vr2 )
AddParticlesForce ( ID , FC1, 0.4, -1500.0, -1550.0 )
endfunction


But not this one ???

function Particles_Setup (ID as integer , xDir as integer , yDir as integer , Life as float, Size as integer , Ang as integer , Rate as integer , VR1 as float , VR2 as float , FC1 as float ,FC2 as float)


SetParticlesDirection ( ID , xDir , yDir )
SetParticlesLife ( ID , Life )
SetParticlesSize ( ID , Size )
SetParticlesAngle ( ID , Ang )
SetParticlesFrequency ( ID , Rate )
SetParticlesVelocityRange ( ID , VR1 , Vr2 )
AddParticlesForce ( ID , FC1, FC2, -1500.0, -1550.0 )
endfunction
Posted: 28th Aug 2011 3:40
Ah-ha! From the documentation which we probably should have read in the first place
You can pass up to nine parameters into your function, and have the option of returning a value when the function returns.


But this brings up another question, why does my function with 10 parameters work?

Edit: Actually it doesn't, if you replace the last parameter "0" with 10 you will get some random number which would cause an error.

So how does your function with 10 parameters work?
Posted: 28th Aug 2011 3:56
Dont ask me ? Why it works

But why limit it to 9 ?

I think the documentation is a bit of a mess to find the stuff in right now ?

But this is the first release!
Posted: 28th Aug 2011 4:10
But why limit it to 9

I think maybe because AppGameKit BASIC handles all of the memory for you and because the devices you develop for don't have a lot of RAM they want to limit it to 9. If you need more then you should probably look into tier 2.

Dont ask me ? Why it works

Well we should accept miracles when they happen.