Page 1 of 2
Clock Widget Errors on Windows
Posted: Sat Mar 14, 2015 6:20 pm
by n.allan
The clock widget is throwing error when I drag it onto a new stack.
Code: Select all
executing at 5:15:31 PM
LCB Error Variables must be defined before being used - variable mIsDay in community.livecode.livecode.clock.
Object widget id 1003
LCB File clock.lcb
LCB Line 231
Code: Select all
executing at 5:15:31 PM
LCB Error Variables must be defined before being used - variable mIsDay in community.livecode.livecode.clock.
Object widget id 1003
LCB File clock.lcb
LCB Line 231
Now, the only reason I ask is that my own widget is throwing the same errors. Does the widget work OK on Mac?
Re: Clock Widget Errors on Windows
Posted: Sat Mar 14, 2015 6:54 pm
by paul_gr
Same here.
"Variables must be defined before being used" is quite explicit, and variable "mIsDay" is being defined on line 72 as boolean....
Now the script editor is freezing... I'll reinstall LC 8 and try again.
Sometimes I wonder if Livecode ever tests their products on Windows before release
Paul
Re: Clock Widget Errors on Windows
Posted: Sat Mar 14, 2015 7:28 pm
by n.allan
It's often the case. I was so mad I almost went to the shop to buy a mac! Heaven forbid!
We reeeeally need a debugger for this tho.
Like you say, all the variables seem to be defined.
Re: Clock Widget Errors on Windows
Posted: Sat Mar 14, 2015 8:04 pm
by paul_gr
Dragged mac out of cupboard to try LC 8.0 on OSX Mavericks.
Clock widget works great...
Paul
Re: Clock Widget Errors on Windows
Posted: Sat Mar 14, 2015 8:15 pm
by LCMark
The clock definitely does work on Mac - I just double-checked with a fresh install of DP1.
I think this might be an intermittent bug in the Windows engine - we will need to investigate (I've filed this here:
http://quality.runrev.com/show_bug.cgi?id=14954)
In regards to being 'defined' then that error message is perhaps a little misleading (it should be 'variables must be initialized before being used') - it means whether a value has been put into the variable yet or not; rather than whether its been declared. You cannot fetch the value from a variable unless you have explicitly put something into it in DP1. This is actually a semantic we will be relaxing slightly in DP2 - some types will have a 'default' value, and if you type a variable then it will be initialized with it automatically.
A debugger for LCB is on our TODO list - due to the nature of how the widget architecture works, it won't be 'in the IDE'; instead it will be a separate app that will run and be able to 'attach' to the IDE process (a bit more like debuggers for traditional languages). Obviously we also intend to integrate it into the IDE in such a way that this particular detail isn't directly apparent

Re: Clock Widget Errors on Windows
Posted: Sat Mar 14, 2015 8:26 pm
by n.allan
OK. With regard to my own widget in patricular. How would one go about initialising a variable of type image, with the absense of a "the empty image" function?
My image variable is used in my onpaint () method but does not necessarily have any data until the "fileName" property of my widget is set.
Re: Clock Widget Errors on Windows
Posted: Sat Mar 14, 2015 8:57 pm
by LCMark
@n.allan: There's one option you can use now, one which will become available when we've finished off 'private resources', and one when we add default initialization to other types.
The current option is to use an 'optional' type. Optionally typed variables get initialized with 'undefined' automatically. So you can test whether you have an image or not.
Code: Select all
variable mMyImage as optional Image
handler OnPaint()
if mMyImage is defined then
... paint the image ...
else
... do other behavior ...
end if
end handler
A future option will be to include a default image as a private resource for your widget. This will then allow you to initialize your image in OnCreate with the default:
Code: Select all
variable mMyImage as Image
handler OnCreate()
put image from resource file "default.png" into mMyImage
end handler
The second future option will mean you won't have to do anything (well depending on what you want to render if there is no filename yet!) - an image will be default initialized to the empty one (i.e. one of size 0 x 0).
Edit: I got the syntax wrong in the above 'is' should have been 'as' in the type annotations.
Re: Clock Widget Errors on Windows
Posted: Sun Mar 15, 2015 4:19 am
by n.allan
OK here is my code, this widget has 2 properties:
fileName -- set this to a valid image file
processParamters -- ignore this, (works as well as can be expected at this point)
If you set the fileName of this widget to a valid "*.png" file the error stops (obviously because the variable is full of valid data)
in the code I have commented my attempts to initialise the variable mProcessedImage. The compiler throws error with:
Code: Select all
variable mProcessedImage is optional Image
no matter where I put it.
A call to my own setter with an emtpy string
has no effect.
the code looks lousy but hey ho
Code: Select all
widget community.livecode.nmallan.imageProcess
use com.livecode.canvas
use com.livecode.widget
metadata title is "Image Process"
metadata author is "Neil Allan"
metadata version is "1.0.0"
property fileName get mImageFile set setImageFile
property processParameters get getProcessParameters set setProcessParameters
private variable mImageFile as String -- image file name
private variable mProcessParameters as List -- process parameters
private variable mOriginalImage as Image -- used to process data
private variable mProcessedImage as Image -- this will be drawn to canvas
private variable mImageData as Data -- the raw bytes ARGB or RGBA to process
--variable mProcessedImage is optional Image -- ***attempt to stop error***
public handler OnLoad()
--variable mProcessedImage is optional Image -- ***attempt to stop error***
--setImageFile(the empty string) -- ***attempt to stop error****
end handler
public handler OnCreate()
-- variable mProcessedImage is optional Image -- *** attempt to stop error ***
-- setImageFile(the empty string) -- ***attempt to stop error***
end handler
public handler OnPaint()
-- variable mProcessedImage is optional Image -- ***attempt to stop error***
if mProcessedImage is defined then
draw mProcessedImage into rectangle [0,0,my width,my height] of this canvas
end if
end handler
private handler setImageFile(in pImageFile as String) as undefined
-- set image file and reset process parameters
get setProcessParameters("0,0,0,0,0,0,0,0,0")
put pImageFile into mImageFile
put image from file mImageFile into mOriginalImage
put mOriginalImage into mProcessedImage
put the pixels of mOriginalImage into mImageData -- ARGB/RGBA data to process
redraw all
end handler
private handler setProcessParameters(in pParameters as String) as undefined
split pParameters by ","
put the result into mProcessParameters
-- the mojo will go here
end handler
private handler getProcessParameters() as String
combine mProcessParameters with ","
return the result
end handler
end widget
Re: Clock Widget Errors on Windows
Posted: Sun Mar 15, 2015 11:55 am
by LCMark
@n.allan: Argh - sorry it should 'as optional ...' - type annotations of variables use 'as' not 'is'. We're still working on making syntax errors a bit easier to understand.
Re: Clock Widget Errors on Windows
Posted: Sun Mar 15, 2015 2:28 pm
by n.allan
That has fixed it.
So the "optional" keyword initializes a variable too. That's good to know.
Re: Clock Widget Errors on Windows
Posted: Mon Mar 16, 2015 10:12 am
by peter-b
n.allan wrote:So the "optional" keyword initializes a variable too. That's good to know.
That's not quite accurate: the "optional" keyword says that it's okay for the variable to be uninitialized. A subtle but important distinction!

Re: Clock Widget Errors on Windows
Posted: Mon Mar 16, 2015 10:54 am
by n.allan
OK. I think I get it. There is nothing in the variable but that is OK with the compiler.
In my situation, where I have an undefined (empty) "mProcessedImage" Image type variable, being drawn to the canvas during the OnPaint() method. The program does not complain about the variable being empty due to the fact it is declared optional I guess. I wonder if that will be the same for all variable types?
for example, if I declare an optional Integer variable and try to perform arithmetic on it, will the operator assume that 0 is in the variable like in LCS? Will it fail elegantly?
I guess I could go and try it, but without a basic understanding It is difficult to interpret some the errors from the compiler. I'll go and try it now I suppose.
Re: Clock Widget Errors on Windows
Posted: Mon Mar 16, 2015 11:22 am
by n.allan
OK I just tested it and It looks like if you do not assign a value to a variable, mathematical operators will simply return empty. BUT it won't complain either. This might be a source of frustration for some. IE it will not assume a default integer value of 0 like in LCS (or some other languages)
I'll put this here in case some people are as thick as me.
To Sum Up: Variables in LCB should always be defined before being operated on to avoid confusion.
Code: Select all
library community.livecode.nmallan.maths
public handler Tested() as Integer
variable tIntA as optional Integer -- my simple test of "optional" properties
variable tIntB as Integer
variable tIntC as Integer
put 1 into tIntA -- if tIntA is not defined then operator will return empty
put 1 into tIntB
put tIntA + tIntB into tIntC
return tIntC
end handler
end library
Re: Clock Widget Errors on Windows
Posted: Mon Mar 16, 2015 11:26 am
by LCMark
@n.allan: LCB is strict - so you should get an error if you try and use an undefined variable in an operator. We'll check this out - you should be getting an error thrown if you don't have the 'put 1 into tIntA' line.
Re: Clock Widget Errors on Windows
Posted: Mon Mar 16, 2015 11:53 am
by n.allan
I just treble checked, If I comment out "put 1 into tIntA" I get no errors, it simply returns empty in the message box.