473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can't input to a global object array

5
Hi,

So I'm making my final project for my CS class. I'm making a pokemon game.
So right now I'm trying to input information(The pokemon the player has) into my array of objects(The list of pokemon the player has). I have the array in a global class so every form can access it. I have it declared as;

Expand|Select|Wrap|Line Numbers
  1. public class GlobalVariables
  2.     {
  3.             public static PlayerPokemon[] PlayerPokemonList = new PlayerPokemon[5];
  4.     }
but when I try to input something to that array with;

GlobalVariables.PlayerPokemonList[0].Name = "BULBASAUR";

It says the object is null. I've tried to declare the array under the initilizer in the form but it doesn't work, I tried it like this;

Expand|Select|Wrap|Line Numbers
  1.  public IntroForm()
  2.         {
  3.             InitializeComponent();
  4.             GlobalVariables.PlayerPokemonList[] PlayerList = new GlobalVariables.PlayerPokemonList[];
  5.         }
I have also tried to put it under Public Partial Class, but it doesnt work

Any help would be greatly appreciated
Jan 9 '10 #1
6 2047
alexis4
113 100+
try this:
Expand|Select|Wrap|Line Numbers
  1. public static PlayerPokemon[] PlayerPokemonList = 
  2.    new PlayerPokemon[5];
  3.  
  4. for (byte i = 0; i < 5; i++)
  5.   PlayerPokemonList[i] = new PlayerPokemon();
Jan 9 '10 #2
tlhintoq
3,525 Expert 2GB
Bytes has a policy regarding assisting students with their homework.

The short version is that the volunteers here can't help you with schoolwork.
A) We don't know what material you have and have not learned in class.
B) We don't know the guidelines you must follow.
C) In the long run giving you the answers actually short changes your education.
Jan 10 '10 #3
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Jan 10 '10 #4
tlhintoq
3,525 Expert 2GB
Please forgive me but...
So I'm making my final project for my CS class.
So you've gone through the entire class and they never taught you that you have initialize the objects before you can use them? Ask for your money back and put it toward an assortment of self-teaching books from the book store. The "Sams" line is quite good. "Sam's Teach yourself C# in 21 days" for example.

Please understand that I'm not insulting you - I am expressing my deep distain for whatever school stole your money and gave you little for it.
Jan 10 '10 #5
Barda4
5
My class is only a grade 12 class, so I don't pay for it. And it's not that I don't know how to initilze objects, it's just I'm trying to initilize a global object array, but whatever I've tried, doesnt work.
Jan 10 '10 #6
tlhintoq
3,525 Expert 2GB
it's just I'm trying to initilize a global object array
As Alexis4 pointed out, you have to initialize each object in the array.
Making the array allocates a variable and memory space, but it doesn't cause each object *in* the array to be created.
So you make the array, then make a new object for element of the array.
Jan 11 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: lawrence | last post by:
How dangerous or stupid is it for an object to have a reference to the object which contains it? If I have a class called $controllerForAll which has an arrray of all the objects that exist, what...
1
by: Phil Powell | last post by:
Consider this: class ActionHandler { ...
8
by: john townsley | last post by:
whats the best way to declare Global objects (holding say 10 member variables and functions) of an unknown size in c++, memory efficient as possible thanks
15
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
6
by: Mike | last post by:
I have a form that contains 240 "products". Each Product has a TR. Each TR contains a Yes and No radio button and a Product-Qty text input. A situation exists where I have to go through all the...
1
by: pbd22 | last post by:
hi. i have been posting this here and elsewhere a lot and can't seem to get resolution on this problem. i have been trying to upload files using a hidden iframe to a asp.net/vb.net form. the...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.