Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Return an value inside an function ?

Author
Message
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 28th Aug 2011 00: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 ?
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Aug 2011 00:24 Edited at: 28th Aug 2011 00:26
This works:


and so does this:



Maybe you need to declare NR? You might also need to declare My_new_value.

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 28th Aug 2011 01:11 Edited at: 28th Aug 2011 01:35
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?
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Aug 2011 01: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:

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.

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 28th Aug 2011 02: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?
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Aug 2011 02:34
Quote: "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:


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?

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 28th Aug 2011 02:35 Edited at: 28th Aug 2011 02:38
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








Quote: "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 ?
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Aug 2011 02:49
Quote: "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.

Quote: "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.

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 28th Aug 2011 03: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
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Aug 2011 03:40 Edited at: 28th Aug 2011 03:44
Ah-ha! From the documentation which we probably should have read in the first place
Quote: "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?

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 28th Aug 2011 03: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!
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Aug 2011 04:10
Quote: "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.

Quote: "Dont ask me ? Why it works"

Well we should accept miracles when they happen.

Login to post a reply

Server time is: 2024-03-28 09:51:03
Your offset time is: 2024-03-28 09:51:03