Stupid Question: Public vs Private vs Unmarked variables/properties?

I’ve got a viewData object I put together (not a class, because I only need one) and has properties set by some methods in my interaction handler, and the properties get used by a bunch of different drawing methods for my UI. However, as I set it up, I was finding that I couldn’t access the properties as expected. They’d turn red and return ‘unresolved reference’ errors.

https://preview.redd.it/l3qjvn2u2hp71.jpg?width=458&format=pjpg&auto=webp&s=5546aa01d05e561a3528236d060f570c6f612cc8

After some trial and error, I put ‘private’ in front of my viewData declaration: private var viewData = object { and suddenly everything worked as expected. I know that private and public have something to do with how stuff is stored in memory, but it seems counterintuitive to me that the private declaration made properties accessible from elsewhere while public didn’t. Also have no idea how those two differ from just declaring with var.

https://preview.redd.it/v15v23aeshp71.jpg?width=447&format=pjpg&auto=webp&s=174468b293f6b4ce0bf57c138795da535b862896

I should add that I’m just using the object to contain the variables because it seems like it will help with organization. There’s clearly some ‘programming best practices’ on how to put stuff together, but unfortunately I have neither the time nor attention span for a ground-up education on it. I only seem to learn and absorb by building and breaking stuff then ducking back to foundational references as needed. Unfortunately this type of stuff seems like it’s so foundational that it’s either not documented, or glossed over because I should have learned it in a 101 class.

submitted by /u/dealingwitholddata
[link] [comments]