Page 1 of 1

Hello World

Posted: Tue Mar 10, 2015 11:11 pm
by netdzynr
So I saw one example (somewhere) that showed executing a script and launching the LiveCode dialog. When I try to run the following, I get "Hello" in a dialog followed by an error.

Code: Select all

public handler OnPaint()
	execute script "answer" && "Hello World"
end handler
Error: errorDialog "857,0,0,runtime

What am I doing wrong?

BTW, is there some another handler besides onPaint that can be used to execute widget code, or is that the basic "run" command?

Re: Hello World

Posted: Tue Mar 10, 2015 11:15 pm
by trevordevore
Try this Scott:

Code: Select all

execute script ("answer" && "\qhi there\q")
OnPaint() is just where you draw the control. OnCreate() is where you can initialize variables, start timers, etc. Then you respond to events using handlers like OnMouseUp(), OnMouseDown(), etc.

Re: Hello World

Posted: Wed Mar 11, 2015 5:56 pm
by trevordevore
Scott - I just came across the OnOpen() handler as well. That is probably a better place to start timers. I'm using it to calculate the width of text in a widget so I can access the width in a preOpenStack handler. Previously I was just calculating the width in OnPaint.

OnCreate - initialize script local variables with default values.
OnLoad - load up saved data
OnOpen - Schedule timers, determine bounds of controls, etc. For example, if you want to get the equivalent of the formattedWidth of a widget you would need to compute that in OnOpen if you wanted to access it in a preOpenStack handler.
OnPaint - draw to screen.

Re: Hello World

Posted: Wed Mar 11, 2015 6:12 pm
by netdzynr
Thanks Trevor. So looking at these messages, it seems like:

"onCreate" is the equivalent "new control"

"onOpen" is the equivalent of "openControl" (or preOpenControl)

How does "onLoad" differ with regard to the above?

Re: Hello World

Posted: Wed Mar 11, 2015 6:16 pm
by LCfraser
"OnLoad" is called when the stack containing the widget is loaded. It is responsible for setting all the widget properties back to the values they were at save time, using an array that the widget's OnSave handler created when the stack was saved.

One other thing worth noting is that we've added a restriction to the "execute script" call - it is only usable in a small number of event handlers as, for example, using it in OnPaint will cause problems due to re-entrancy if the script causes any changes to the outside world.