Hello World

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
netdzynr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 62
Joined: Sat Apr 08, 2006 6:04 am
Contact:

Hello World

Post by netdzynr » Tue Mar 10, 2015 11:11 pm

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?

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Hello World

Post by trevordevore » Tue Mar 10, 2015 11:15 pm

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.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Hello World

Post by trevordevore » Wed Mar 11, 2015 5:56 pm

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.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

netdzynr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 62
Joined: Sat Apr 08, 2006 6:04 am
Contact:

Re: Hello World

Post by netdzynr » Wed Mar 11, 2015 6:12 pm

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?

LCfraser
Livecode Staff Member
Livecode Staff Member
Posts: 71
Joined: Thu Nov 28, 2013 11:18 am
Contact:

Re: Hello World

Post by LCfraser » Wed Mar 11, 2015 6:16 pm

"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.

Post Reply

Return to “LiveCode Builder”