Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

It's gonna take me a while to digest all this, but this is super, super useful.  Especially this part: "The dot operation for objects and dictionaries is simply an alias for the square bracket operation with a string key."  (Is this the case in Visual Basic, I wonder?  If it is, either I never got taught it explicitly, or I've forgotten it in the intervening years.)

I appreciate you taking the time to show me the incremental steps to get down to the most efficient version, so that I can more easily conceptualize what's going on and why.  As a self-taught programmer with what is likely ADHD, I find it all too easy to gloss over bits that seem surface-level "duh" or "I can look this up whenever", but explanations that are succinct enough to focus on but also detailed enough to help me grasp the underlying principles (instead of just the surface-level appearance) are exceedingly useful yet difficult to find.

P.S. I presume the debug mode would be a better way of handling the troubleshooting process than pulling out bits of code like I've been doing... so I just gotta get past the inertia/resistance of "but I don't want to figure out the New Thing, I'm working on this thing, and the irritation of doing this poorly is less of a problem than the effort it takes to do things better" brain mode.  Same reason it took me like five years to get to the point of modding Skyrim, and now I can't imagine playing without mods.  Brain inertia is fun (sigh).

(1 edit)

I haven't used Visual Basic in at least a decade so I don't remember, but in most languages I know the dot operator is only used to access member functions of the class or member variables of the object.

In GDScript, objects and dictionaries use C++ compiled functions in similar-ish ways to compiled languages, but it includes more steps as the data is evaluated and handled in realtime due to the lack of strict data typing. If the string after the dot operator doesn't correspond to any compiled preset then it is processed as a key for a lookup.

In compiled languages member variables of an object are accessed by converting the name into a memory offset from the starting memory address of the object. In GDScript, member variables are string keys used to access values in an internal dictionary, so the relative offsets of variables in memory are not constant. Compiled languages don't use complex lookups like dictionaries as a core part of their design, so I would only expect such a feature to exist in an interpreted scripting languages where convenience is more important than efficiency.

Edit: It might be time to start a new chain of posts as this one is getting quite deep and less convenient to find.