Class Warfare

Created with Sketch.

Class Warfare

My continued education into the basic format of C# continues. Once past the, let’s call it “culture shock,” the language isn’t altogether too dissimilar, save for the one thing I’ll get to in a second.
“Ifs” and “Whiles” work just like they should, and the “++” notation is a cute shorthand.
There is a “do” command, which I hate the syntax of though. Basically, it’s a “while” statement. More basically for those of you at home without programming experience, a “while” statement tells the computer to keep on doing something while something is true. The Game engine for example is more or less:

While (exit = false)
Run Engine
Wend (end of while loop)

So as long as the “exit” variable = false then keep running the game. “Do” works sort of like that, but guarantees that the code runs at least once. I’m sure I can find a use for that, but hate how I do it:

Code Goes Here}
While(something = something else)

With that, the condition goes at the end. Right ^ there it’s not a big deal, but add a hundred lines in between and it’s easy to forget why something is doing something.

Other stuff works like it should too. Arrays (tables of data – see my rambling about combat animations in the diary for an idea of how those work) can be arrayed and inputs do exactly that.
I’m still at a slight loss about how Functions work, but other than being needing to say “void” to not return a variable directly they seem to be the same animal.

Except for one thing – Classes. I’m not there yet. They seem to be the hidden Qi that powers the language and mastery thereof will allow me to see the green rain code of the Matrix. I get that, at a basic level, they are a structural component. They keep the code pieces all separate, which somehow facilitates communication of some kind. Then individual “instances” of the classes can be summoned up from the spaces in-between and those code bits, or chunks of variables or functions can be used for other things.
The two things that are getting me, I mean really getting me coming from Basic are:
1) How the hell do I summon an “instance” of code? Doesn’t it have to be compiled? Or is it just pointing at other code like a convoluted function call? Why do my examples have pointers inside a class that that appear to be local variables inside the same bloody class? Like a goddamn digital ourobouros. How do you reference something from inside itself? That doesn’t make any fuggin sense I tells ya.
2) How do these classes even talk to each other? They don’t share variables, they pass around the same local variables and once they start I don’t seem to have a way to make them actually do anything. I could probably get away with coding the way I normally do and then just put everything inside a single class and then never mention it again, but then I’m not really using the power of the language. Plus, the stuff that makes things run on XNA are all written with a SARS riddled cornucopia of classes and local functions, so that doesn’t really help me.

It’s okay though, I have faith that I can figure it out. I mean after only a week I can read C#, which is more than I could previously. I’ll think I’ll be ready to make some code soon.

– I mentioned “++” in the words above. It seemed like so long ago. Anyway, what it is, is a counter trick. Basically, if you do – variable++, it’s the same as – variable = variable + 1. It’s shorter and faster. There are also “–” versions which decrease by one and other flavours that I find both exotic and nauseating, like those pepper lollipops from Mexico..

– I’ve gotten Namespaces buttoned down. They’re a way to code like a retard by yourself, or have your group written code usable. I think that what it is, is a collection of variable and function names, almost like a folder that you can make. So you can have a variable in Namespace Ernie called Rubber_Ducky and then also have a Namespace Bert and a variable called Rubber_Ducky. Even though they have the same specific name, they are different because they come from different places. It’s like how you can have different documents in your computer called the same stuff in different places.
It makes sense in a group, since then you can all have your own little sandbox and not worry about using variables the wrong way. In my own code, if someone went in a thought that iX (the player’s X coordinate) might be a nice thing to use for a counter, it would lay waste to the game engine.
But like I said, if you’re coding by yourself, I can’t think of a decent reason to do this. Granted you can call variables from other Namespaces like this : Bert.Rubber_Ducky, but really, why would you do that instead of simply making it have its own specific name? I may be missing something here. I’ll throw some IQ at it and see what sticks.

Yay! Technical post! Hopefully I’ll be able to leverage some of this new voodoo into something useful. Hopefully soon. I feel like I’m writing an essay test for a programming class sometimes. Only with more swearing.