-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lua: Source - sharing variables and init call sequence #4411
Comments
.. can you rule out that another script in the init handler also contains a “print(”Init called:”, counter )” statement ? all init handlers are executed during boot, so another statement could explain your observation on startup |
Yes, ruled out. When I comment this print() out this output is no more. |
Your variable counter belongs to the script, not to the source. So it is common to all models using the same source! |
Understood. Is it possible then to fix the init call sequence so the init of the source is called only once when the model is loaded? Thanks |
|
I am starting to think about splitting |
That would be great, or any other option that would allow me to initialise source per model. I understand there are likely other priorities but TBH I'm somewhat stuck with this. Really appreciate if you find time to improve this.... |
Thanks! |
I have just introduced a new function |
Thanks! |
I'm experiencing a "strange" behavior in how Ethos is handling lua source - maybe this is as designed but does cause underised effects.
My source shell (simplified to illustrate the problem) looks like
1st, when I start Ethos (sim or debug), the output is:
Init called 0
Read called: 0 -- or error on the new model, expected
Init called 0 -- second time?
So init is called two times. This is not a big deal on its own however with multiple model using the same source there is a problem.
I need counter to have default value of 0 for every new model. I create 1st model, run the source logic or use configure() to set the counter to say 10. All works as expected, 10 get saved to the model.bin file and retrieved on next model start.
Now I create the 2nd model (via wizard, not cloning). The source is disabled by default. So I go to the model settings/Lua and enable it. What I have as an output is:
Init called 10
As you may see the counter value was inherited from the previous model. My next step was to set it to default 0 in init() but then I bump into the issue that init is called 2 times, 2nd one after read so this overrides the stored value. I could also initialize counter with default on read (before storage.read) but than as read is not called when I'm enabling the source, so my default value is back to 10, while I need 0.
Is there workaround I am missing or perhaps the init should not be called 2 times?
Many thanks
The text was updated successfully, but these errors were encountered: