I wanted a counter that I can change by clicking on it (just a simple +1/-1) and I found
https://steamcommunity.com/sharedfiles/filedetails/?id=1552081476
.. which works very well, but it's a little crowded. I got rid of all the buttons I didn't need/want to get something that just does the +1/-1 on left/right-click. No problems so far, the script still works fine.
However, moving the counter without clicking the button is a little hard, so I decided to also show its value on the other side, with a XML UI Text element and included
self.UI.setAttribute("FrontVal","text",val)
to add_subtract, the buttons click_function, so keep it updated. This also works fine.
However, a problem arises whenever the object is loaded, copied, pulled from a bag, etc. Then, the XML UI Text element isn't updated. It shows the original XML UI Text's value ("front") instead. So I think: alright, I just need to update the XML whenever the object loads as well, so I add:
self.UI.setAttribute("FrontVal","text",val)
to the onload function. This results in an error: "object reference not set to an instance of an object". AFAICT that means that the object doesn't exist, causing the "self." reference to return nil. I'm puzzled about this, because the script, before that, executes several self.createButton() functions with no problem at all.
So, WTF and how do I get around this?