View Full Version : Is a Timer loop in redraw callback possible?

12-11-2012, 07:53 AM
I often get distracted from the work at hand to try and pretty up my LScripts and make them sexier/more interactive. So I just was trying to draw a series of glyphs as if it were an animated gif in the redraw function. I couldn't find any timer function except time() which returns ticks as the 4th argument which are seconds since 1-1-1900 (not the 1970 epoch like in other languages?).

Anyway, I can't see why this isn't working. Assume the glyphs are loaded and a button's callback toggles the flag to draw it and does a requpdate() on the viewport control after flipping the flag. For some reason, all I get is the first frame of the animation. However, when I toggle the button on and off I get the subseqent frames. This tells me that the requpdate needs to be called to animate it, but docs say it has no effect in the redraw function so I'm not sure how to loop a timer to keep updating the viewport while I'm animating. Any suggestions? Here is the pertinent code:

// GLOBALS outside main/generic

var preLoaderGlyphs;
// assume preLoaderGlyphs are loaded before requester is up
var currentLoaderFrame = 1;
var preLoaderFlag = false;
var lastFrameAt = 0;

// button callback toggles preLoaderFlag and calls requpdate
// ...

vpt_Canvas_redraw: ctl
var currentTime = time();
if (currentTime[4]>lastFrameAt+1)
lastFrameAt = currentTime[4];
drawglyph(preLoaderGlyphs[currentLoaderFrame], 480,170);
if (currentLoaderFrame>8)
currentLoaderFrame = 1;

12-14-2012, 09:35 AM
Any thoughts on this? Or am I pushing it expecting this sort of thing from Lscript? Thx!

12-14-2012, 03:30 PM
LW is not very multithreaded. And to my knowledge it will typically call plugin callbacks in fixed order, not run them in separate and disjoint threads, even if that would be sensible and/or theoretically possible. And lscript does not provide anything (one exception) to create and manage your own threads (you can't perform LW operations inside LW SDK threads either, they are just for calculation etc; again, the way LW operates is very fixed and linear), so trying to make it execute in anything but a linear fashion will fail. Drawing happens when it needs to happen and at fixed points. You can however force the panel to refresh at regular intervals using reqpost("myUDF", milliseconds) (the exception referred to). It should work for your purposes. Might cause other issues, but worth a try.

12-14-2012, 04:41 PM
Thanks evenflcw! for the reqpost argument in ms, I must have missed that in the docs, I'll try it out. I understand it wouldn't be very multithreaded, but I assumed perhaps there would be a timer command like if JavaScript...