Page 1 of 1
Function Declaration / Prototyping
Posted: Mon Apr 18, 2011 8:03 pm
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.
Re: Function Declaration / Prototyping
Posted: Mon Apr 18, 2011 11:18 pm
by ArtBlink
Try this :
Code: Select all
Function p_DoSomething()
DebugPrint("hollywood rocks")
EndFunction
p_DoSomething
I think it's bug... no?
Re: Function Declaration / Prototyping
Posted: Mon Apr 18, 2011 11:37 pm
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.
Re: Function Declaration / Prototyping
Posted: Tue Apr 19, 2011 11:13 am
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()