Missing 'on' does not cause error...
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Missing 'on' does not cause error...
Greetings:
I'm wondering, does anyone agree that the following is a Livecode bug?...
I've just spent a day trying to figure why a button had stopped working. The end of the story is that I had accidentally deleted the 'on mouseUp' statement. It's at the head of a fairly long script, just after a 'global' statement, the code was still indented, and so it was not obvious the line had disappeared.
I'm really surprised that on closing the script, I didn't see any error. If I delete an 'end' statement, LC complains, because the there is no 'end' to match the 'on'. But the opposite check seems not to be done. LC is quite happy if you have an 'end' without a matching 'on'.
Thoughts?...
--paul
[LC6.6.1]
I'm wondering, does anyone agree that the following is a Livecode bug?...
I've just spent a day trying to figure why a button had stopped working. The end of the story is that I had accidentally deleted the 'on mouseUp' statement. It's at the head of a fairly long script, just after a 'global' statement, the code was still indented, and so it was not obvious the line had disappeared.
I'm really surprised that on closing the script, I didn't see any error. If I delete an 'end' statement, LC complains, because the there is no 'end' to match the 'on'. But the opposite check seems not to be done. LC is quite happy if you have an 'end' without a matching 'on'.
Thoughts?...
--paul
[LC6.6.1]
Re: Missing 'on' does not cause error...
Certainly if you lead LC on, in that you create a handler and do not close it, it will complain. But if you write a bunch of text that happens to finish with an "end whatever", then LC was never interested in what you wrote before that line.
I guess you might say that if you introduce what appears to be a formal handler, you better close it. But if you "close" a handler you never really "opened", no harm, no foul.
Craig Newman
I guess you might say that if you introduce what appears to be a formal handler, you better close it. But if you "close" a handler you never really "opened", no harm, no foul.
Craig Newman
Re: Missing 'on' does not cause error...
Okay Craig, I understand. But if it's not a bug, it still seems sloppy to me. I would at least expect to get a warning to tell me I was ending a handler I hadn't started.
--paul
--paul
Re: Missing 'on' does not cause error...
You are saying if you write a line in the script editor somewhere that begins with "end", then that editor ought to perk up and, what? Look upwards in the code and expect to find an "on"?
I suppose it could be implemented that way, but just wasn't. There is indeed a procedure that keeps an eye out for "on", and looks downward expecting to find an "end". But sloppy? I see it as just the way things are, though I fully understand why you were thrown a bit when you discovered the thing.
Craig
I suppose it could be implemented that way, but just wasn't. There is indeed a procedure that keeps an eye out for "on", and looks downward expecting to find an "end". But sloppy? I see it as just the way things are, though I fully understand why you were thrown a bit when you discovered the thing.
Craig
Re: Missing 'on' does not cause error...
Hi Craig,
that doesn't make sense to me.
In the LC 6.6.1 IDE, I can now use comments without having to use comment tags outside of a handler.
This script works and it shouldn't.
---------- start script ----------------------
clicking on this button sends "whatever" message ( uncommented comment )
on mouseUp
put "whatever"
end mouseUp
---------- end script ------------------------
If the uncommented string is inside a handler LC detects it and complains.
i.e LC finds the error in the next example:
---------- start script ----------------------
on mouseUp
clicking on this button sends "whatever" message ( uncommented comment )
put "whatever"
end mouseUp
---------- end script ------------------------
code that the IDE does not understand should be flagged; like it is in any other programming environment.
Paul
that doesn't make sense to me.
In the LC 6.6.1 IDE, I can now use comments without having to use comment tags outside of a handler.
This script works and it shouldn't.
---------- start script ----------------------
clicking on this button sends "whatever" message ( uncommented comment )
on mouseUp
put "whatever"
end mouseUp
---------- end script ------------------------
If the uncommented string is inside a handler LC detects it and complains.
i.e LC finds the error in the next example:
---------- start script ----------------------
on mouseUp
clicking on this button sends "whatever" message ( uncommented comment )
put "whatever"
end mouseUp
---------- end script ------------------------
code that the IDE does not understand should be flagged; like it is in any other programming environment.
Paul
Re: Missing 'on' does not cause error...
Trying to remember if HC allowed uncommented text outside of handlers. Not sure. Must test when I get to a computer that still has a crank on it. Oh yes, I have a dozen running at my office.
Loosey-goosey? I guess so. But that is part and parcel of the xTalk world. I would miss those homey attributes if they were banished. But again, I can see that this sort of thing would throw you if you were used to more formal languages.
Come to the dark side...
Craig
Loosey-goosey? I guess so. But that is part and parcel of the xTalk world. I would miss those homey attributes if they were banished. But again, I can see that this sort of thing would throw you if you were used to more formal languages.
Come to the dark side...
Craig
Re: Missing 'on' does not cause error...
For what it is worth. HC also allowed uncommented text to be sprinkled outside of handlers in object scripts.
Craig
Craig
Re: Missing 'on' does not cause error...
..........
Last edited by [-hh] on Wed Aug 13, 2014 2:35 pm, edited 1 time in total.
shiftLock happens
Re: Missing 'on' does not cause error...
It is so great to have Hermann back!!!
Re: Missing 'on' does not cause error...
Thanks a lot Craig and Hermann!
You gave me an idea which works perfectly
I've been missing the concept of HERE Documents in LC we can find in some other languages.
For instance, working with complex regex or applescript, the best solution so far was
to type the regex/applescript in a custom property or in a field which I didn't like that much as it splits
the whole code in two parts (hard to read and maintain)
So, here is my last hour testing a sort of HERE document with my applescript code:
First sample code is how I did it before,
second and third are 2 ways based on this strange Livecode feature
and below a screenshot of the same code in the AppleScript Editor!
So now, I can seriously write/debug any applescripts in the Applescript
Editor and when happy, copy/paste it in a Livecode script with almost no surprises.
At least, I can use this when coding and it will save me a lot of time
and still very easy to read!
Thierry
You gave me an idea which works perfectly

I've been missing the concept of HERE Documents in LC we can find in some other languages.
For instance, working with complex regex or applescript, the best solution so far was
to type the regex/applescript in a custom property or in a field which I didn't like that much as it splits
the whole code in two parts (hard to read and maintain)
So, here is my last hour testing a sort of HERE document with my applescript code:
First sample code is how I did it before,
second and third are 2 ways based on this strange Livecode feature

Code: Select all
private function doBBLivecode aFile, aTitle
do format("tell application \"BBLivecode\" to edit script \"%s\" infos \"%s\" type %s autosave true", \
aFile,aTitle, "Stack") as applescript
return the result
end doBBLivecode
on mouseUp
local scripFile
put "/Users/x/Desktop/xyz.lcscript" into scripFile
put the script of me into url ("file:" & scripFile)
put "button sunnyLCBBproperties" into BBEtitle
put doBBLivecode( scripFile, BBEtitle)
end mouseUp
Code: Select all
tell application "BBLivecode"
edit script "%s" infos "%s" type %s autosave %s
end tell
#
local AScript
on mouseUp
local scriptFile, BBEtitle
put "/Users/x/Desktop/xyz.lcscript" into scriptFile
put the script of me into url ("file:" & scriptFile)
put "button sunnyLCBBproperties" into BBEtitle
do format( AScript, scriptFile, BBEtitle, "Stack", true ) as applescript
end mouseUp
on mouseDown
set itemDelimiter to "#"
put item 1 of the script of me into AScript
end mouseDown
Code: Select all
tell application "BBLivecode"
edit script "_scriptAlias_" infos "_BBEtitle_" type _type_ autosave "_autoSave_"
end tell
#
local AScript
on mouseUp
local scriptFile, BBEtitle
put "/Users/x/Desktop/xyz.lcscript" into scriptFile
put the script of me into url ("file:" & scriptFile)
put "button sunnyLCBBproperties" into BBEtitle
replace "_scriptAlias_" with scriptFile in AScript
replace "_BBEtitle_" with BBEtitle in AScript
replace "_type_" with "Stack" in AScript
replace "_autoSave_" with true in AScript
do AScript as applescript
end mouseUp
on mouseDown
set itemDelimiter to "#"
put item 1 of the script of me into AScript
end mouseDown
So now, I can seriously write/debug any applescripts in the Applescript
Editor and when happy, copy/paste it in a Livecode script with almost no surprises.
At least, I can use this when coding and it will save me a lot of time
and still very easy to read!
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
Re: Missing 'on' does not cause error...
..........
Last edited by [-hh] on Wed Aug 13, 2014 2:34 pm, edited 1 time in total.
shiftLock happens
Re: Missing 'on' does not cause error...
I think we have to call him Sheriff Hermann now...dunbarx wrote:It is so great to have Hermann back!!!
Look at that shiny new badge!
Simon

I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Missing 'on' does not cause error...
..........
Last edited by [-hh] on Wed Aug 13, 2014 2:36 pm, edited 1 time in total.
shiftLock happens
Re: Missing 'on' does not cause error...
Hey I'm there as well!!!(at least I'm engraved in the LOB-forever-startup-splash)
Wow didn't know that

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Missing 'on' does not cause error...
Hermann,Simon,[-hh] wrote: TWO.
At BOTTOM of a script I do things as Thierry describes now (and then use item -1 instead of item 1 and so on). It's better to do this at bottom, if you have, as I do, also other not recommended things in scripts, see next remark.
And never ever do (at work) what I described in remark three ...
Sorry to disturb your bagde conversation

This morning I push a bit more the idea of storing some data connected to a script in the script!
Re-reading my yesterday's code, I feel today that it's a bit dangerous and even if it works well today,
we never know which LC version will break the game (as it's not an official feature).
So, that said, I've slightly changed the code above and did comment my data,
e.g a whole button script:
Code: Select all
local AScript, CP
/*** CP=tdzAScript
tell application "BBLivecode"
edit script "_scriptAlias_" infos "_BBEtitle_" type _type_ autosave "_autoSave_"
end tell
*/
on mouseUp
local scriptFile, BBEtitle
if AScript is empty then put the tdzAScript of me into AScript
put "/Users/x/Desktop/xyz.lcscript" into scriptFile
put the script of me into url ("file:" & scriptFile)
put "button sunnyLCBBproperties" into BBEtitle
replace "_scriptAlias_" with scriptFile in AScript
replace "_BBEtitle_" with BBEtitle in AScript
replace "_type_" with "Stack" in AScript
replace "_autoSave_" with true in AScript
do AScript as applescript
end mouseUp
on mouseDown
if the environment is "development" then
if matchText( the script of me, \
"(?msi)^\s*/\*+\s+CP=([^\n]+)\n(.+?)\n\s*\*/", \
CP, AScript) then set the CP of me to AScript
end if
end mouseDown
split it in a custom property name and in a var containing the data (my applescript in this case)
and set the property which will be called in a standalone application only.
Still some room to improve things but the idea is there,
and I believe it's quite solid by now,
and it's a real pleasure to read an applescript/regex/whatever without any extra backslash or quotes..
Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!