LCB variable assignment and evaluation confusion

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
SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

LCB variable assignment and evaluation confusion

Post by SparkOut » Mon Apr 02, 2018 1:56 pm

I have been trying to get a chance to look into LCB again and thought I'd have a go at examining the clock widget to get used to manipulating the canvas and paths.
I have just had a hard disk problem so a new Windows 10 setup of LC 9-rc1 is being used, no older editions clogging things up.
Several things are making it hard to get to grips with again, I thought I had made great steps with the previous task of interfacing with foreign dll handlers for the Velleman experiment board, but so much of the basics is tripping me up here.
Firstly when testing, making any changes is not necessarily being reflected in the test, for instance, if I set

Code: Select all

metadata preferredSize is "300,300"
instead of 200 x 200 then mostly the test widget doesn't change size. Occasionally there is something that happens and the size follows the new preference, but then if I make a change again, it sticks to the 300 x 300 size until another seemingly random thing happens to obey the setting. I know it's not just a cache thing because some of the other programmatical changes to the widget ARE taking effect.

Mainly though my thoughts are concerned with how to evaluate variables right now.

In the clock .lcb the updateGeometry() handler contains

Code: Select all

put [my width / 2, my height / 2] into mCentre
If I try to copy that mCentre value to another variable, by various means, they all fail.

Code: Select all

put [my width / 2, my height / 2] into mCentre
put [(my width / 2) + 30, (my height / 2) + 30] into mNewVar -- fails
put [my width / 2, my height / 2] into mNewVar -- fails, even though a literal cut and paste of the valid line but with mCentre edited to mNewVar
put mCentre into mNewVar -- fails (sure beats me why)
/* this fails
variable tX as Number
variable tY as Number
put mCentre[1] into tX
put mCentre[2] into tY
add 90 to tX
add 90 to tY
put the empty list into mNewVar
push tY onto mNewVar
push tX onto mNewVar
*/
/* this fails
put the empty list into mNewVar
push mCentre[2] onto mNewVar
push mCentre[1] onto mNewVar
*/
put [90,90] into mNewVar -- works to put the hard coded values into the variable
When I mention "fails" above, I mean that no error is generated, but the script silently ignores the values supposedly put into the mNewVar list. What gives? How can I understand these evaluations and assignments?

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 192
Joined: Thu Apr 18, 2013 2:48 pm

Re: LCB variable assignment and evaluation confusion

Post by livecodeali » Mon Apr 02, 2018 2:22 pm

Regarding preferredSize, this is not actually hooked up with the test button in the extension builder, which is arguably a bug - although the behavior currently used is to recreate the widget and containing stack with the same rect it had before, which is quite useful. I suppose if a preferredSize is set it should use this all the time, rather than the previously chosen size. When the widget is installed, and dragged out from the tools palette, preferredSize is used.

What are you doing with the new variables that shows the failure? It's impossible to try and diagnose the problem you're having without seeing the whole context. Have you changed the identifier of the clock widgets? Otherwise it might be having problems because a widget with that identifier is already loaded.

Post Reply

Return to “LiveCode Builder”