Starting A Process Inside A Function Not Working.


TrevorBradley

Active Member
Joined
Nov 6, 2007
Messages
732
OK, another puzzler.

The following code does not work:

CODE

Program ProcessTest;
Begin
set_fps(60,0);
set_mode(320,240);

timer_function();

let_me_alone();
exit();
End;

Function timer_function()
Begin
timer();

Repeat
frame;
Until (key(_esc));
End;

Process timer()
Private
int mytext;
Begin
Loop
mytext=write(0,160,120,4,timer[0]);
frame;
delete_text(mytext);
End;
End;



If I move the timer() call to the main program (above timer_function()) it works fine.

Is it not possible to start processes from within functions?
Do you have to start all processes from the main function?
 
Hello. I'm not that familiar with using functions in fenix as I tend to just use processes so I don't know about their nuances, that said I had a quick look at your code and it is working but you need to remove the let_me_alone() and exit() from the main program.
 
ruckage said:
Hello. I'm not that familiar with using functions in fenix as I tend to just use processes so I don't know about their nuances, that said I had a quick look at your code and it is working but you need to remove the let_me_alone() and exit() from the main program.
I'm using functions as subroutines, to try to keep my code neat and tidy.

I don't see the difference between my previous code and this one, for instance:

CODE

Program ProcessTest;
Begin
set_fps(60,0);
set_mode(320,240);

timer();

Repeat
frame;
Until (key(_esc));

let_me_alone();
exit();
End;

Process timer()
Private
int mytext;
Begin
Loop
mytext=write(0,160,120,4,timer[0]);
frame;
delete_text(mytext);
End;
End;




If the call to a process is put inside a function, then the function returns instantly without blocking. It's as if a function that calls a process itself becomes a process (instead of a function subroutine) and unblocks.

Annoying, but good to know if you're coding.
 
Last edited by a moderator:
Every function and every process that calls to frame runs in parallel. In your first example, you launch three parallel processes (processes and functions are nearly the same thing in Fenix): the main code, timer() and timer_function(). But the only thing that the main code does is exit(), so you exit :)

In the first example you have to wait for timer_function to finish(). Something like this in your main code:

CODE

Program ProcessTest;
Begin
set_fps(60,0);
set_mode(320,240);

timer_function();
repeat
frame;
while exists(type timer_function);

let_me_alone();
exit();
End;



At least, that was how Div worked. Check the grammar because I haven't developed for fenix in years!
 
QUOTE
Every function and every process that calls to frame runs in parallel.


This is incorrect for Fenix.

From FenixWiki:

http://www.fenixdocs.com/index.php/Function

The difference between a function and a process is that the calling process or function waits until the function is completed. When a process or function calls a process, it doesn't wait. This means that, even when the called function contains frame statements, the calling function or process still waits for the function to finish.

I've been using dozens of function calls and they behave exactly like this. If I don't include the call to the process within the function, the function behaves exactly like this, blocking the main loop until completion. But when a process call is inserted into the function instead of the main body, it's as if the word "Function" was crossed out and replaced with "Process", and the program quickly hits exit();
 
The wiki is correct and the code works for me (BGDC 0.93 and FXI 0.93).
What FXI version are you using?

[EDIT]
Is it not possible to start processes from within functions?
Sure it's possible.

Do you have to start all processes from the main function?
Nah, you can even kill all processes except one and call the main() function again (handy for a restart()).
 
Sandman said:
The wiki is correct and the code works for me (BGDC 0.93 and FXI 0.93).
What FXI version are you using?

[EDIT]
Is it not possible to start processes from within functions?
Sure it's possible.

Do you have to start all processes from the main function?
Nah, you can even kill all processes except one and call the main() function again (handy for a restart()).



My FXI is v0.84, from March 2004. It's the one that comes with the Flamebird devkit on archive.gp2x.de.

A bunch of websites seemed down when I started downloading, so it's possible many of my versions are out of date... :)

*Looks around for new software*

The fenix main site is still broken, and I can't download. I have Flamebird MX now, but it doesn't come with Fenix...

Which version of the windows Fenix interpreter and Puck2099's Fenix interpreter for GP2X (Beta 6?) should I have?
 
Last edited by a moderator:
I missed your link in your post.

I've tried downloading 0.92a from sourceforge, except fxi and fxc appear to be broken. Same occurs for bdgc 0.93. Run from the command line they drop right back without any output. Am I missing something?
 
Trevor Bradley said:
The fenix main site is still broken, and I can't download. I have Flamebird MX now, but it doesn't come with Fenix...
I personally use ConTEXT because I think FlameBird MX still needs a lot of work. I haven't tried beyond version FBMX 0.55 though, but it's too messy to my liking.

Trevor Bradley said:
Run from the command line they drop right back without any output. Am I missing something?
Yes, they don't output to the console anymore. They output everything to stdout.txt. This is why the earlier FlameBird MX crashes with the later Fenix versions.

Trevor Bradley said:
Verified this works just fine in 0.92a.
Aye. I recommend 0.93 though, it has bugfixes. Although if you program for the GP2X or any other exotic platform, you'll want to use an official release so 0.92a is good (source code etc). Or wait a bit for the next Bennu release.
 
Last edited by a moderator:
Back
Top