Page 1 of 1
Executing a function - How to get a result
Posted: Sun Apr 05, 2015 10:32 pm
by Zryip TheSlug
The com.livecode.date library seems actually very limited.
For getting the list of the weekdayNames, I have tried:
Code: Select all
private handler getWeekDaysName() as List
variable tStringList as String
variable tDayNamesList as List
execute script "get the system weekdayNames"
put the result into tStringList
split tStringList by return into tDayNamesList
return tDayNamesList
end handler
But the engine is returning an error at the line:
put the result into tStringList
How can I get the result of a function when using "execute script"?
Re: Executing a function - How to get a result
Posted: Tue Apr 07, 2015 2:01 pm
by trevordevore
You need to return the value, not get it.
Code: Select all
execute script "return the system weekdayNames"
Re: Executing a function - How to get a result
Posted: Tue Apr 07, 2015 7:40 pm
by Zryip TheSlug
Trevor,
I should have thought to a simple "return". Thanks!
That's said I'm not sure the syntax for defining property options:
Code: Select all
metadata fontName.options is "execute:get the fontnames; sort it"
is not confusing. It confused me.

Re: Executing a function - How to get a result
Posted: Wed Apr 08, 2015 12:24 am
by Zryip TheSlug
trevordevore wrote:You need to return the value, not get it.
Code: Select all
execute script "return the system weekdayNames"
I gave this syntax a try:
Code: Select all
variable tStringList as String
execute script "return the system weekdayNames"
put the result into tStringList
and I got this error from the engine:
"Value is not of correct type for assignment to variable - expected type livecode.lang.string for assigning to variable tStringList".
We can assume, "the result" contains nothing or not the value we are expecting or
the engine is failing to type the result "object" in this case.
Or, on the other hand we can assume I do not know how to get a result.
Anyway, I can't figure out how the engine could give a type to "the result" as the type is totally hidden until the execute command has been interpreted by the engine.
For example, the result could contain:
Code: Select all
execute script "return true" -- a boolean
execute script "return 1" -- an integer
execute script "return test" -- a string
And the developer would expected to get a string in all the cases.
As we can't give a type to "the result" ourself, the syntax for the execute script command would be:
execute script "myScript" as [Type]
Re: Executing a function - How to get a result
Posted: Wed Apr 08, 2015 5:16 am
by trevordevore
Hmm, this is the code I tested in do-1 and it works for me.
Code: Select all
public handler OnOpen()
variable tStringList as String
variable tDayNamesList as List
execute script "return the system weekdayNames"
put the result into tStringList
split tStringList by "," into tDayNamesList
log "%@, %@" with [tStringList,tDayNamesList]
end handler
Are you sure your updated code is compiling? If you have installed the extension and you try to test new code from the extensionManager then the installed extension is run, not the updated code. You would need to uninstall it, restart, and then try testing again.
Re: Executing a function - How to get a result
Posted: Wed Apr 08, 2015 7:06 pm
by Zryip TheSlug
I found the problem.
You are in the OnOpen message.
The same code executed in the OnPaint or in the OnCreate message is returning the error.
The OnPaint message is probably not the best place for executing this kind of command, but I used it for testing. The OnCreate is more appropriated, though.
I will report this in the RQCC.
Re: Executing a function - How to get a result
Posted: Wed Apr 08, 2015 7:14 pm
by trevordevore
Actually, that probably isn't a bug. I remember reading that you can't execute code within certain handlers as it has the potential to create problems.
Re: Executing a function - How to get a result
Posted: Wed Apr 08, 2015 7:31 pm
by Zryip TheSlug
You're right. In the documentation itself. For the OnPaint and OnCreate messages we have a big note:
Note: Access to most script object operations is not allowed whilst an OnPaint handler is running.
I will just report a typo in the documentation about the note concerning the OnCreate message, which seen to be a copy paste of the OnPaint note.