thanks to the help on my previous question, i was able to get my array of instances for the ship class working, however I found out that the new objects that I created were only available in the class that they were created. As I needed them to be available to several classes, this is a problem. I thought it might be a simple matter of changing the initial declaration from "private" to "public", but this didnt seem to yield any results. I also consulted my microsoft visual c# step by step book ( i didnt want to clutter up the forums without trying to solve it on my own first), but they didnt go into this topic in depth.
Heres my creation code
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Microsoft.Samples.DirectX.UtilityToolkit;
namespace IDOE
{
class galaxSetup
{
//new game goes here first
private globfleetdata globalFDat = null;
private Ship[] ship = null;
private Vector3 test;
private int currentFreeNum = 0; //the number used to give a unique tag to each instance of ship.cs
public galaxSetup()
{
}
public void newgame()
{
globalFDat=new globfleetdata(); //creates new instance of globfleetdata
ship = new Ship[4]; //creates new ship class array with 4 members
globalFDat.newgame(); //calls the newgame method of the globalFDat instance of the globfleetdata class
createShip(3); //creates 3 new instances of the ship class
}
public void createShip(int numNewtoAdd)
{
for (int counter = 0; counter < numNewtoAdd; counter++)
{
currentFreeNum++;
ship[currentFreeNum] = new Ship();
assignVari(currentFreeNum);
}
}
public void assignVari(int whichShip)
{
test = ship[1].Position;
}
}
}
thanks

instances part 2
Brian Hartman - MSFT
cool. I'll give it a try when i get home today.
Suddenly its all starting to make more sense. I think i might be getting the hang of this stuff finally.
I'll let ya know if more problems come up, but i think ive got it under control now.
thanks much
elfenland
in order for other classes to see it, you need to make it from private to public as you had said. Now, since the class (this class code you have posted) has the reference/object of the Ship objects, in order for the other class to see it you need to either:
The last is a better option. The reason being is because one class should not really need to know about the other, and you are exposing your entire class (all public members/methods) to which other classes can access - bad design.
To pass the objects around to other classes, take a look at this. you may need to adjust it accordingly:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=729974&SiteID=1
I hope this helps in some way
pkv
Daniel UJ
public Ship[] ship
{
get { return ship; }
set { ship = value; }
}
so that if Im in another class and call g.Ship[3].position I will get the position method of the ship[3] object (where "g" is an instance of the class that created ship[3])
that seems a little screwy. Am I on the right track, or did I miss the boat
perhaps what i really want is
public Ship[] ship(shipNum)
{
get { return ship[shipNum]; }
set { ship[shipNum] = value; }
}
hmm well that doesnt seem quite right either
thanks