How to keep a boolean variable defined as true or false

In ETA’s itemPicker.js file, I have a variable that is assigned a variable from another .js file: ruler.js. The variable in question is boolean, and, as far as I can tell, has no reason to be undefined at any point.

To illustrate, here is my console log. When clicking on the ruler button upon startup, I get the following false/true log reports. After clicking on a tile, instead of defining a point for the ruler, as I have tried writing the script to do, it simply highlights the tile as if the ruler button had never been selected to begin with.
I then click the ruler button again, and see the problem: rulerActive somehow became undefined because I clicked on the tile.
image

image

If someone has any idea as to why this might be happening, or can even push me in the right direction, I would be very grateful. In fact, if at all possible, I will be more than happy to share my newfound knowledge with other confused game designers.

The short version is that you have made rulerActive a global variable and not part of the Ruler object.

Therefore rulerButton.script.ruler.ruleActive is ALWAYS undefined because the property doesn’t exist on the ruler object.

You don’t show the whole script, so that makes it kinda tough - especially for a newb like me. But I notice that your .findByName statement is on line 86 and not in the initialize portion of the script. Is it possible that your “undefined” results is coming from a portion of the script before we get to the .findByName statement on line 86.

Ahhh … so the problem is that he’s not saying

“this.rulerActive = rulerButton.script.ruler.rulerActive” ?

So you’re saying that rulerActive should be an attribute of Ruler, the same way that passiveAsset and activeAsset are?

Doesn’t need to be an attribute but should be a property.

Thank you both very much for your help. I’m now just trying to figure out how to replace the “Sample Text” with the number generated by line 148 on itemPicker.js.