This one is most probably ‘a bug’.
This one is most probably ‘a bug’.
I have below Script to be run on resumed event for a text item to make it as a countdown bar.
It runs fine most of the time when I press Back to exit current app/activity and go to home screen. However, if I press the home button, an error is occurred.
var npt = LL.getVariables().getInteger(‘varNextPrayerTime’);
var mnpt = LL.getVariables().getFloat(‘varMintoNPT’);
var mtp = Math.round((((npt – Math.floor(Date.now() / 1000)) / 60) / mnpt) * 710);
if (mtp >= 0) {
var e=LL.getEvent();
var c=e.getContainer();
var item = c.getItemByName(‘barPrayer’);
item.setSize(mtp,17);
Android.makeNewToast(mtp, true).show();
}
]]>« How do I make the background of the sidebar transparent? (Previous Post)
< ![CDATA[
This also happened if my phone is locked. Also happening whenever I interact with other items.
]]>
< ![CDATA[
Where is the script set? In the resumed event of the item or of the container?
]]>
< ![CDATA[
seems LL.getEvent().getContainer() returns null
]]>
< ![CDATA[
TrianguloY of the item.
]]>
< ![CDATA[
I recommend then to simply use LL.getEvent().getItem()
Or set it in the resumed event of the container with the item.
When a script is run in the resumed event of an item, LL.getEvent().getContainer() normally returns null, other times an undefined container.
]]>
< ![CDATA[
TrianguloY I did this, still getting error. I will put the resumed on container
var npt = LL.getVariables().getInteger(‘varNextPrayerTime’);
var mnpt = LL.getVariables().getFloat(‘varMintoNPT’);
var mtp = Math.round((((npt – Math.floor(Date.now() / 1000)) / 60) / mnpt) * 665);
if (mtp < 0) {var mtp = 0;}
var e=LL.getEvent().getItem();
var item = e.getItemByName(‘barPrayer’);
item.setSize(mtp,17);
]]>
< ![CDATA[
No no.
LL.getEvent().getItem() returns the item where the script is run, so simply
var item=LL.getEvent().getItem()
]]>
< ![CDATA[
You mean the code should be this way? It is not working and gives new error. Cannot find function setSize in object function getItem()
var npt = LL.getVariables().getInteger(‘varNextPrayerTime’);
var mnpt = LL.getVariables().getFloat(‘varMintoNPT’);
var mtp = Math.round((((npt – Math.floor(Date.now() / 1000)) / 60) / mnpt) * 665);
if (mtp < 0) {var mtp = 0;}
var item=LL.getEvent().getItem;
item.setSize(mtp,17);
]]>
< ![CDATA[
You forgot the () in the getItem
]]>
< ![CDATA[
Grrrrrrrr. Thanks TrianguloY
The good part of this discussion that I learnt new thing of getItem() function. That it will always gets the item which is running the script.
Love LL
]]>