Page 1 of 2
Ruby Issue: Draw and Init
Posted: Wed Oct 22, 2014 11:39 pm
by tulamide
If a view is connected to the Ruby editor, when starting the schematic (and probably any exports also) the 'draw' method is called before the init method. A simple test will convince you, see attachment.
In my spline class example 2, I can resolve the issue by calling init from within the draw method, which should convince everyone who wasn't from the attached test.
This renders 'init' pretty much useless. Luckily, you can also initialize by just placing the initializing code at the very beginning of the Ruby editor, without defining an init method. No need to call init from the draw method then.
Thought you should be aware of it!
Re: Ruby Issue: Draw and Init
Posted: Thu Oct 23, 2014 5:45 am
by Exo
Thanks for pointing this out and giving a solution.
I have noticed that too, it is rather odd and doesn't make much sense!
Re: Ruby Issue: Draw and Init? not true
Posted: Thu Oct 23, 2014 6:50 am
by Tronic
Your test is not very correct, look at this:
The problem that you have with your class Spline is that you must always load the modules that contain the classes, before any other modules, otherwise your class when the module invokes it, does not yet exist in memory.
Re: Ruby Issue: Draw and Init? not true
Posted: Thu Oct 23, 2014 7:36 am
by tulamide
Tronic wrote:Your test is not very correct, look at this:
The attachment order_issue_not_true_issue.fsm is no longer available
The problem that you have with your class Spline is that you must always load the modules that contain the classes, before any other modules, otherwise your class when the module invokes it, does not yet exist in memory.
I'm sorry, but you're not true. See, the watch method only gets triggered when the method it's in is also triggered. That's why you get the impression of a regular order, since after the first draw, the order is correct (draw, init, draw). The spline class is an expansion of the ruby edit class, any access to the class forces ruby to build it if not yet existant. That's why you have no issues at all when initializing at the very beginning of the editor, without creating an 'init' method.
My schematic on the other hand raises an error whenever one of the methods gets called, whatever is the first. No Spline Class involved at all!
See the attached schematic without your 'afterload' prim. (draw gets called 3x, init 1x)
Re: Ruby Issue: Draw and Init
Posted: Thu Oct 23, 2014 7:58 am
by Tronic
Unfortunately I can not agree to your idea,
because if the method "Init" was not the first to be triggered,
would not be initialized the variable with which you observe the results,
you're considering the number of trig happened, but the method "draw" shows a longer time,
compared to that reported by the method "init",
so for me the order of execution is correct.
Re: Ruby Issue: Draw and Init
Posted: Thu Oct 23, 2014 8:10 am
by tulamide
Tronic wrote:...so for me the order of execution is correct.
That's exactly what I said in my last post. You get the impression, because after the first 'draw' call, the order indeed is correct. There's just the issue that draw gets called
a first time before 'init'Here's another schematic, and if this one doesn't convince you, I don't know what else.

Make sure Flowstone is not running, then open it with the schematic. After load, just click on the trigger button and be surprised

Re: Ruby Issue: Draw and Init
Posted: Thu Oct 23, 2014 8:18 am
by Tronic
Sorry, but not...
trig order still
Method:
1) init
2) event
3) draw
try to switch OFF the module and retrig....
surprise....
Re: Ruby Issue: Draw and Init
Posted: Thu Oct 23, 2014 8:27 am
by tulamide
Tronic wrote:Sorry, but not...
trig order still
Method:
1) init
2) event
3) draw
try to switch OFF the module and retrig....
surprise....
Tronic, I see you misunderstand the whole issue. We talk past each other. Of course, it works after retrig. That's what I am saying the whole time! You don't even need to switch it off, just enter something in the editor, for example a space anywhere and retrigger. But the issue is not that it works
afterwards, the issue is that, as you can clearly see in the last schematic I posted, 'init' doesn't get called, while 'draw' is called -
at the very first time.
I don't know how I could explain it in another way so that it might get clearer.
Re: Ruby Issue: Draw and Init
Posted: Thu Oct 23, 2014 8:31 am
by Tronic
your preview test is not correct, it every time reset the variable when you trig the module,
because method init is called only the first time, so the variable @a_init is lost(is reset) in your case.
Re: Ruby Issue: Draw and Init
Posted: Thu Oct 23, 2014 8:35 am
by tulamide
Tronic wrote:your preview test is not correct, it every time reset the variable when you trig the module,
because method init is called only the first time, so the variable @a_init is lost(is reset) in your case.
Wrong again, I don't trig the module, I trig the event method. Also, your thought would also reset @a_draw
But I'll leave it as it is. I've done my best.
