Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 09 Jan 2013
Offline Last Active Jan 08 2014 11:24 AM

Topics I've Started

Having trouble accessing an objects properties.

25 December 2013 - 07:48 AM

            Character[] PlayerOne = new Character[5];

            PlayerOne[1] = new BladeWarrior();
            PlayerOne[2] = new FistWarrior();
            PlayerOne[3] = new Archer();
            PlayerOne[4] = new RedMage();
            PlayerOne[5] = new BlueMage();          

I know through polymorphism, a BladeWarrior can be a Character but it cant be the other way around. My problem is that when I try to access an element of an array. Player[1] for example, I cant access functions and variables from the BladeWarrior class. It's only letting me access variables and functions from the Character class which the BladeWarrior class inherits from.


I'm going to need to be able to access Bladewarrior functions/variables if Im going to want 2 characters to fight.

I was thinking I could use the "as" function to set PlayerOne[1] as the specific object . Not exactly like this:

string s = objArray[i] as string;
 The line of code above is just to get an idea of which "as" Im talking about.

What is a solution to this problem? Your time and effort is much appreciated. Thank you in advanced.

Accessing a text file from resource folder in MS visual studio.

13 February 2013 - 05:23 AM

Ive got this text file Im trying to read from. Its located in my resources folder in microsoft visual studio. Im trying to access that text file so I can parse the text from that file to an integer and store it in my integer array called Armor[,] .The contents of the text file is a 12x11 chart of numbers which I would like to parse to an integer and store into the 2D Armor[,] array. Here are the contents of the text file:




When I run the program I get an error saying:

Value cannot be null.
Parameter name: path


The error that microsoft visual studio's throwing is because of the line:



StreamReader armorStream = new StreamReader(Resources.Armor);


//namespace used do directly access Resource.FileName
using TurfBattles.Properties;
public void LoadArmor()


//Create a variable for storing the armor defense values

int[,] Armor = new int[12, 11];
//Create a string variable for storing the stream readers input
string myString = new string();

int Row = 0;

//Create a stream reader for reading the Armor.txt file

StreamReader armorStream = new StreamReader(Resources.Armor);

//While the stream reader is able to read the next line

//do this:

while ((myString = armorStream.ReadLine()) != null)


//Loop through each value of the myStringSplit array

for (int Column = 0; Column < 11; Column++)


//This splits the text up and stores it into an array of strings

//It also stores the white spaces into a character array

string[] myStringSplit = myString.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);

//Store the current value of myStringSplit into the Armor Array

Armor[Row, Column] = int.Parse(myStringSplit[Column]);








Why can't I acess a process?

03 February 2013 - 07:36 PM

As you can see in my code I included System.Diagnostics. The purpose of this program is to get the current process and output it to the console. I am trying to access Process.GetCurrentProcess    on line 14  .  Also, as you can see, I can only access Process.Program   . Why is it that I can't use:


Process.GetCurrentProcess(); and all of the other functions of the Process Class.





What is the difference in these 2 variables?

02 February 2013 - 09:05 PM

When declaring a variable why should I use this:


int a = new int();


rather than:


int a;



I apologize if it is syntactically incorrect, but if you get the drift of what I am trying to ask, please let me know. Is it because of the way the variable or the value in the variable is stored in the memory? Maybe it makes it more efficient?

I found this really funny.

31 January 2013 - 11:11 PM

I was working on my code for a bit, and decided to take a little break. I came across this. I thought it was funny, just wanted to share it for the others who are about to bang their head on their keyboards from debugging etc smile.png