Functions ?


Mr_Munk

Member
Joined
Mar 9, 2005
Messages
226
Age
44
Location
Totnes, Devon, UK
Website
www.notofficial.co.uk
Yo,

I'm cleaning up my code at the moment and wondered if it's possible to emulate functions somehow, I read that you can do it in DIV by 'Sleeping' and 'Wakeup'ing processes, and passing parameters into the process.

However, when I try and pass parameters into a process Fenix throws a compiler error unless the parameters are pre-defined variables from the language...

Any ideas ?
 
Predefined?

You have to have a process called

process blabla(x,y,state);

for example, and then you can pass "parameters" into the process by calling it for example:

blabla(160,120,5);

which will give the predefined (I assume, you mean this by predefined) variables x and y the values 160 and 120 and the for this process private variable "state" the value 5.

Or you maybe mean

blabla_id=blabla();

so you can change every predefined variable with

blabla_id.x=160;
blabla_id.y=120;

for example, and every local variable for that process (you can`t change private variables this way afaik).

Hope this helps you.
 
I don't know where you got the sleeping and awaking from, but it sounds rather complicated for what you want to do. If you want to do some calculation and return a value, that can be done with a normal process:

Code:
Process addUp(value1,value2)

begin

return value1 + value2;

end

Of course, Fenix would be creating a whole new process for this single action, making it a pretty heavy addition for the cpu. I guess you could eliminate that by using one instance for it and sleeping that, waking it up for an addition when you need it, removing the creation and destruction. Hmm:

Code:
Program ice;

global
additionId;
additionResult;

begin
//create that single instance:
additionId = addUp();

//hey, I want some addition!

//Set the 'parameters', we add up 12 and 10
additionId.x = 10;
additionId.y = 12;

//Wake up the process, giving it focus
signal(additionId,s_wakeup);

//[1]

//After the process reached the sleepstate again, it returns focus
//And we can read out the result.
additionResult = additionId.z;

//additionResult should now have the value 22 in it.
end

process addUp()
begin
//Make the priority something awesomely high
priority = 100;


loop
  //Let it put itself to sleep
  signal(id,s_sleep);
  
  //When it is woken up, the parameters should be set, so it performs the action,
  //in this case the addition, and puts itself to sleep again.
  z = x + y;
end

end

I guess it would have to be something like this you mean then. I haven't tested it but I'd say it would work in DIV, in Fenix the signal() function works in mysterious ways so I'm not all that sure, maybe you'd have to wait a frame(insert where it says [1]) before you can read out the results(if Fenix decides to keep the focus on the main process).

If you can make something usefull out of this post fine, if not, at least I tried :) .
 
Quiest and Moogle, I can always count on you :D

You both helped indirectly...

I was trying to get at the first of the things Quiest mentioned (by pre-defined I meant reserved variable names) and from what you say (Quiest) it seems it isn't possible to make your own process and pass your own parameters in.

As Moogle pointed out that this would use more CPU, then it seems better not to try and adapt processes into custom functions anyway.

:rolleyes: I hope this makes sense I'm tired after a long and early shift.

Anyway, thanks guys. it's sorted.
 
Mr_Munk said:
...it seems it isn't possible to make your own process and pass your own parameters in.

o_O Now it seems we both meant something different... or I`m just thinking too stupid :D
 
Last edited by a moderator:
Back
Top