Function Declaration / Prototyping

Discuss any general programming issues here
Post Reply
djrikki
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Function Declaration / Prototyping

Post by djrikki »

Hi,

At the moment if I want to call and use a function it must have previously been defined. Naturally I want to be able to organise or group my functions together how I want them,

Code: Select all

p_DoSomething

function p_DoSomething()
     debugprint("hollywood rocks")
endfunction
This piece of code would fail because the function has yet to be defined.
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
ArtBlink
Posts: 484
Joined: Mon Nov 01, 2010 10:37 am
Location: Albert - France
Contact:

Re: Function Declaration / Prototyping

Post by ArtBlink »

Try this :

Code: Select all

Function p_DoSomething()
     DebugPrint("hollywood rocks")
EndFunction

p_DoSomething
I think it's bug... no?
djrikki
Posts: 682
Joined: Wed Apr 06, 2011 12:26 am

Re: Function Declaration / Prototyping

Post by djrikki »

No not a bug. If there is no way to declare the function prototype at the top of the code then that would be a limitation. Andreas will know for sure.
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Function Declaration / Prototyping

Post by airsoftsoftwair »

Functions in Hollywood are just variables that contain a function instead of a static value. Thus, they have to be initialized prior to use. Writing

Code: Select all

Function p_Add(a, b)
    Return(a+b)
EndFunction
is the same as

Code: Select all

p_Add = Function(a, b) Return(a+b) EndFunction
A workaround for your problem is to encapsulate everything into functions. Then the problem won't arise. I.e.:

Code: Select all

Function p_Main()
  p_DoSomething()
EndFunction

Function p_DoSomething()
...
EndFunction

p_Main()
Post Reply