Can anyone help me with “runScript” and “getData”? There seems to be a problem with passing the parameter…
Can anyone help me with “runScript” and “getData”? There seems to be a problem with passing the parameter…
script1:
LL.runScript(“script2″,”myPanel”);
script2:
var d = LL.getCurrentDesktop();
var e = LL.getEvent();
var p = e.getData();
alert(p);
var i = d.getItemByLabel(p);
I have a panel labeled “myPanel” on the desktop.
I run script1 from a shortcut.
Alert shows ‘myPanel’.
getItemByLabel returns NULL.
BUT: if I directly use d.getItemByLabel(“myPanel”), the panel is found.
Is this a bug?
]]>
< ![CDATA[
alert(d.getItemByLabel(“myPanel”).getLabel()) shows myPanel without the single quotes BTW.
Do I need to use JSON to pass a single string?
]]>
< ![CDATA[
The quotes are a part of the result getdata(). Wether it”s bug or a feature i dont”t know.
]]>
< ![CDATA[
Yes, definitely a bug. alert (“-” + p + “-“) shows “-‘myPanel’-“. Quotation mark are part of the string. Tried replace(“‘”,””), removes only first mark.
Great, my first try with scripting, failing at once 🙁
]]>
< ![CDATA[
Pierre Hébert Or am I doing something wrong? Is JSON-encoding required? Documentation states otherwise, JSON as option.
]]>
< ![CDATA[
Lutz Linke to be honest: I think it it’s really a bug. (Didn’t try myself, just from your comments)
]]>
< ![CDATA[
I don’t remember why but the data is explicitly quoted and escaped. Testing without these extra quotes didn’t reveal any problem. Does anybody remember whether there was a need for this at time of introduction of this runScript function ?
]]>
< ![CDATA[
Pierre Hébert Searched the community, did not find anything. My bet would be JSON requires this quoting. Quick search showed samples like:
var json = ‘{“result”:true,”count”:1}’,
var obj = JSON.parse(json);
Seems JSON requires double quotation marks inside a string in single quotation marks. I think you tried to ensure somehow a JSON string would be transfered correctly from calling to receiving function.
]]>
< ![CDATA[
But tag also lets you store json…and it don’t add the quotes :/
]]>
< ![CDATA[
TrianguloY Thanks. Tag however does not seen appropriate to post data.
Anyway… I tested my theory, tried JSON stringify and parse, but even JSON complains “unexpected token ‘ ” (not sure I used JSON properly, new to me). So the single quotes do not make sense.
Or, Pierre Hébert , did you find a reason why the escaping was added?
]]>
< ![CDATA[
Lutz Linke The single quotes in your example are just ‘second double quotes’
I mean:
‘This a string that have a “string” inside’
So, if you want to make a string with ‘strings’ inside you can use (and you need to use in other languages)
“This a string that have a \”string\” inside”
But, in JavaScript, quotes are more or less the same, so you can use the others.
In theory (but I didn’t test) you can also write
var json = “{‘result’:true,’count’:1}”,
var obj = JSON.parse(json);
]]>
< ![CDATA[
To sum up
Pierre: remove the extra quotes
]]>
< ![CDATA[
TrianguloY Yes, I knew that with JS one can use both single or double quotes. Tried to figure out a possible use.
Second your opinion: extra quotes (and escaping if any) must be removed. Data must not be altered. It’s just a string anyway.
]]>
< ![CDATA[
I finally found the reason for this escaping. It was required with the older script engine, but I forgot about this at time the second engine replaced the first one.
]]>