Forge War - Arrays of All Dimensions
July 26, 2013
So coding has been moving along. I've moved into the quest phase of the game and working in C# has provided one continued annoyance for me.
All right, in AS3, when I want to grab a variable dynamically (as in do I want to grab "Player1Quest" or "Player2Quest" depending on if some other variable "i" is 1 or 2), then that is totally easy. I set up a construction: this, and I can grab the variable by constructing the string of its name. If I'm grabbing a movie clip object or something it gets a little more complicated, but there's still a simple way to do it.
No so in C# my friends! Well, there may be a way, but I have yet to find it, and I've done some looking. So instead of doing something like:
this=25;I have 2 options - the smart way and the stupid way. Of course, up until this point, I've been using the stupid way. The stupid way being a series of "if" statements that add a much of needless lines to your code:
if(i==1){Player1Quest=25;}if(i==2){Player2Quest=25;}etc.This is dumb.
The other way is to not have a different variables for all this player quest business and instead just have an array called "PlayerQuest." Oh, holy crap, I'm a genius. Or at least not a moron. Then you can just be, like:
PlayerQuest=25;So much better! And I was doing this for some things, but I think I got hung up if the variable was already an array and for some reason I was apprehensive about making a 2D array. Or if it was a 2D array and I had to make a 3D array. Because I'm afraid of brackets I guess?
I don't know, but I decided I needed to go back and condense all my variables into arrays before the stupidity got too much out of hand, so that was exciting, and now I can get on with my life.
Leave a comment
Comments will be approved before showing up.