Like a Rosetta Stone

Created with Sketch.

Like a Rosetta Stone

In the late hours, I mean really late almost encroaching on early hours, I had a breakthrough. I was reading things like Method and Class and not understanding what that was exactly. My issue, once again, was one of vocabulary. The lightning bolt that hit, was that “method” is just the way C# refers to a “function.” Methods I’ve never worked with before, but functions? Oh man, we go way back.
So I’m staring at code and trying to put things together and writing just a giant pant load of comments to keep the logic flowing like boxed wine, and I’m finding that functions/methods live inside a Class, which resides on Namespace Street. Or can. It seems that such a hierarchy is slightly disingenuine, since I can create a new Class inside a method and summon a Namespace whenever I feel like it, but I think that at this stage thinking is those kind of global terms is helpful. It avoids an overabundance of riches.
Anyway, once a function/method is called we can make it so that it only works inside the Class where is lives, or available anywhere. We can also call it “Static,” which opens up whole new worlds of possibility.

You see, the other way to create a function/method is to not call it Static, then it can be called as an “Instance.” To do that, I summon up the function/method and stick it to a variable. Kind of like this, but with correct syntax:

New Function Version1 = WhateverClass.Function(Stuff)

Then you would put information (or arguments) into the little brackets there. It creates a new (like the first command) version, or “instance” of the function/method that uses the variables that you’ve given it. Afterwards, you can call back that specific version of the function.
To put it another way with something I’ve done before. The collision rectangle code in The Thief’s Tale is built around 12 rectangles. Each of those rectangles has an X and Y position and a height and width. Each of those attributes is saved in the computer as a single variable, like Rect1X and Rect1Y.
However, instead they could be built using an instanced function/method. Like this:
New CollisionRectangle Rect1 = WhateverClass.CollisionRectangle(Position,H,W)

Afterwards, whenever I need to check something for collision against that rectangle I could simply call back that particular instance (Rect1). It’ll bring all of the information I’d given it previously and then run the code that resides inside using it.
The real cute trick, is that I can create those from nothing as they are needed since all of the variables are local, but saved. In Blitz only Global variables are consistent, and they have to be declared in advance. Instancing allows me to create whole new things on the fly. So hypothetically, I could recreate the ThiefEngine and build screens with thousands of rectangles.

– I ran across a slightly odd thing in my explorations, something called “Vector.” I was in the process of drawing sprites on the screen (in this case, The Knight enemy since I have lots of assets for it) and the stupid little window kept telling me that 200,200 is an integer and not wanted. To which I said, very likely aloud, “No shit, I’m aware that 200 is a bloody number.” It turns out, it wanted something different, a Vector. Basically, it’s like a tiny box that holds other variables, in this case, X,Y and if you want, Z. So before you can use it you have to fill the box, like this : Vector2 WhateverPosition(200,200)
I think the syntax is right, but it’s just as likely not. In any event, afterwards, I just refer to WhateverPosition when I want to put Whatever where it needs to go. This seems kind of silly in 2D, but I suppose that doing it in 3D and a couple of hundred times per cycle it probably helps quite a bit.