call a function in the Function Editor

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
manuel
Posts: 9
Joined: Monday 28 October, 2013 - 10:47

call a function in the Function Editor

Post by manuel »

Hi,

I´m trying to call a function in a Function Editor with another function in the same Function Editor. It works properly, but if I save my model and open it again there is an error saying the function is not a valid expression. If I open the functions again and press OK the error is gone and i can continue my work. I got many of this functions and everytime my model is crashing I need several minutes to fix this problem. Has anyone a idea how to fix it?

Thanks a lot.
Manuel
marlies
Posts: 301
Joined: Monday 17 January, 2011 - 09:28

Re: call a function in the Function Editor

Post by marlies »

Hi Manual,

That is because of the sequence of registration. This is the sequence in which they are shown in the function editor. What you could do to solve this:

- Use the command PreregisterFunction(p1,p2,p3) in the oninit event handler of an atom that is higher in rank than the function editor to preregister the function.
- Add another function editor to your model, which you use to registrate the functions that make use of functions in the first editor.
- Or make sure that the sequence in the 1st function editor is according to the required registration sequence.

Regards, Marlies
manuel
Posts: 9
Joined: Monday 28 October, 2013 - 10:47

Re: call a function in the Function Editor

Post by manuel »

thanks, it works now :-)

Another question: is there any possibility to end an infinite loop?
In Plant Simulation the infinite loop is stopped if you press three buttons on the keyboard.
Is there any similar option in ED?
marlies
Posts: 301
Joined: Monday 17 January, 2011 - 09:28

Re: call a function in the Function Editor

Post by marlies »

Hi Manuel,

I am afraid that once you're in the infinite loop the only solution is ctrl+alt+delete.

To check why your code is getting into this infinite loop, I would suggest to add the command enterdebugger(1) in your code and step through the code to find out what's going wrong.

Besides that it's always good to limit your loops. The command loopuntil for example has a parameter that defines the maximum number to execute, the loop will stop even when the criterium isn't reached.

Regards, Marlies
schepers
Posts: 14
Joined: Thursday 19 January, 2012 - 12:08

Re: call a function in the Function Editor

Post by schepers »

Hello,
is there any solution for recursion? When I try to implement a recursion, only fault is unreg. function.
Thx,
Schepers
marlies
Posts: 301
Joined: Monday 17 January, 2011 - 09:28

Re: call a function in the Function Editor

Post by marlies »

Hello Schepers,

It should be no problem to implement a recursion as long as you make sure that your code is not triggering infinite loops.

What do you mean by: only fault is unreg. function? Do you get an error message? And if so, what did you implement and when do you get the error message?

Regards, Marlies
Post Reply