Pierre Hébert I’m working on a script that uses desktop position to change the background color of a shortcut.
Pierre Hébert I’m working on a script that uses desktop position to change the background color of a shortcut. The script works if I manually run the code from the Lightning menu or use the “Resumed” event. But I just can’t seem to make it run on the “Position Changed” event. Am I not using the event properly?
Here is the script if it helps:
var e = LL.getEvent();
var c = e.getContainer();
var wide = c.getWidth();
var xloc = c.getPositionX();
var scuthome= LL.getItemById(6750221).getProperties().edit();
if (xloc < 1080) {
scuthome.getBox(“i.box”).setColor(“c”,”ns”,0x1d000000);
scuthome.commit();
} else {
scuthome.getBox(“i.box”).setColor(“c”,”ns”,0x00000000);
scuthome.commit();
}
var scutcal= LL.getItemById(6750222).getProperties().edit();
if (1080 >= xloc && xloc << 2160) {
scutcal.getBox(“i.box”).setColor(“c”,”ns”,0x1d000000);
scutcal.commit();
} else {
scutcal.getBox(“i.box”).setColor(“c”,”ns”,0x00000000);
scutcal.commit();
}
]]>
< ![CDATA[
None that I am aware of, but that doesn’t mean there is no bug. If you add “alert(xloc);” just after the line “var xloc = c.getPositionX();”, does it display a correct value ?
]]>
< ![CDATA[
It displays the correct value.
it doesn’t seem to be running the script when I move around the desktop. Like I said, I can manually run the script and it performs just as expected.
]]>
< ![CDATA[
(This shouldn’t be the issue, but you wrote < < instead of <= )
]]>
< ![CDATA[
🙂 I just noticed that myself. Already made the change. Thanks
]]>
< ![CDATA[
Maybe this is a dumb question, but are you sure you configured the right event ?
I tried it right now and everything seems ok.
Just in case, try to set a very short script such as “alert(LL.getEvent().getContainer().getPositionX());” to see if this one liner works.
]]>
< ![CDATA[
That didn’t work on mine. I copied this line exactly and set it to run on Position Changed.
]]>
< ![CDATA[
And if you set any other action, such as “All apps” ? If it does not launch the app drawer, then I think that there is some mismatch of what you scroll and what you configure
]]>
< ![CDATA[
Other actions seem to work. I just tested the “Expand Notifications Tray” and it opened up as soon as I moved the desktop.
But if that action works, how come a script won’t run? Even the simple one-liner you had me test.
]]>
< ![CDATA[
I am puzzled 🙁 Except if scripts are disabled in the general settings, but in this case no script would run so I assume this is not the case. Would it be possible for you to export a backup of your setup and send it to me ?
]]>
< ![CDATA[
Absolutely. What is the best way to send it?
]]>
< ![CDATA[
by email at pierrox@pierrox.net(long tap on the archive in the backup/restore screen and you will get a “send” option)
]]>
< ![CDATA[
It should be on its way. My network signal is somewhat poor right now so I don’t know how long it will take. I’m also going to aplologize now in case I accidentally bombarded your inbox
]]>
< ![CDATA[
Thanks I got it. There’s a bug, but not where it was supposed to be. Surprisingly it has been there since a long time ago. Fortunately there is a workaround until the fix in the next update: when selecting the script ,hit back when you see the popup to enter script data instead of tapping on the ok button, and it will work.
]]>
< ![CDATA[
What was exactly the bug? If I could ask
]]>
< ![CDATA[
That did it. That was driving me crazy. You’re easily one of the most helpful developers on here. Thanks so much
]]>
< ![CDATA[
So that made it work and I found that that script was a little heavy and made moving between positions very laggy. So I have a new idea but have to pester Pierre Hébert and TrianguloY for one more question. Is there a way to call one script from another script?
]]>
< ![CDATA[
http://www.pierrox.net/android/applications/lightning_launcher/script/reference/net/pierrox/lightning_launcher/script/api/LL.html#runScript(java.lang.String,%20java.lang.String)
😉
]]>
< ![CDATA[
TrianguloY this is related with the issue you reported earlier: the data is set to an empty string instead of null and in this case the position change event was not expecting a data here.
Previously, scripts had no data and to maintain backward compatibility with existing setups the run script action encode everything in a string “id/script_data” or “id” if no script_data.
]]>
< ![CDATA[
I’m assuming its a little more complicated than LL.runScript(script name) because I’m getting a “Can’t find method” error.
]]>
< ![CDATA[
You need to pass data. You can simply use null if I remember correctly
LL.runScript(“name”,null);
]]>