iconjunky

Hi,

I`m storing info in a list which I`ve written:

List<float> mapList = new List<float>();

I`m storing mapList[x] = `ModelName`, mapList[x +1] = `ModelpositionX`, mapList[x +2] = `ModelpositionZ` amongst others.

..and would like to.

DrawModel(mapList[x], Matrix.CreateTranslation(mapList[x +1], 0, mapList[x +2]);

Which gives the error: Error 2 Cannot convert type 'float' to 'Microsoft.Xna.Framework.Graphics.Model' : for mapList[x] above.

Is there anyway I can convert mapList[x] so its accepted
I`ve only just starting with lists and arrays, which one would be better for the type of thing I`m doing above

Any information on any of the above would be great. I`m off to read up some more. Thanks in advance.

-Daz.



Re: XNA Game Studio Express Loading a Model from a List<> problem?

Rick Mogstad

Assuming you have the properties for ModelName, ModelPosition, etc. in your Model class, you could change your list to be a List<Model> (or whichever type you use). Since DrawModel wants a model object, and you are passing in a float, you get the error. Also, how is the ModelName a float






Re: XNA Game Studio Express Loading a Model from a List<> problem?

iconjunky

Ah, thanks very much. I take it I`ll need two types of lists One for List<Models> and one List<Floats> Or is there a way to put all the different info into a List<string> then convert it into the type I`d want later

I was just using a float value for the Model name then using a workaround to draw it.

Thanks again, seems silly now but that was baffling me all last night.







Re: XNA Game Studio Express Loading a Model from a List<> problem?

George Clingerman

When you're working with descriptors of the same object like the name of the Model, it's PositionX and it's PositionY, what you want to do is not have seperate Lists for each of those.

You want to create a class describing all the properties of your object. So, you're going to want to make a ModelClass or something similar. In that class, have a string for storing the name, a float, integer, vector2, whatever for storing your positions and more properties for whatever other related data you have about your model objects.

Then you'll make a List of that class. So if you called your class, myModels, your list is going to be List<myModels>. Then you'll have those objects stored in your dictionary object and each object will have it's own properties for it's name and postion.

That way you're not making a ton of dictionary objects for each property of your models and having them be so loosely disconnected.

I hope that helps explain it a little for you.





Re: XNA Game Studio Express Loading a Model from a List<> problem?

Rick Mogstad

Can you provide code as to how you were populating the original list Does your model object provide all of the info that was in the <float> list



Another way is to create a class that has all of the info you want, including the actual model object....


    class MyModel
    {


        Model mModel;
        public MyModel(Model model)
        {
            mModel = model;
        }

        public Model Model
        {
            get { return mModel; }
        }

        String mModelName;
        public String ModelName
        {
            get{return mModelName;}
            set {mModelName = value;}
        }

        float mPositionX;
        public float PositionX
        {
            get { return mPositionX; }
            set { mPositionX = value; }
        }

        float mPositionY;
        public float PositionY
        {
            get { return mPositionY; }
            set { mPositionY = value; }
        }


    }


And then create a list of those...

List<MyModel> myList;

Then you could access all the info you needed in one list, as well as the model itself.

Hope that helps some.







Re: XNA Game Studio Express Loading a Model from a List<> problem?

iconjunky

I`ve managed to do it using a seperate Model list with all the names of the models in. I populated the model list using `.Add`. I needed the name of one Model and the coords of another, then some other info from floats to populate the list with.

There are only 4 Models and I tried to populate the list on creation, (towards the top of the class ) with no success. I thought I could just do.

List<Model> mModelsList = new List<Model> (mModela, mModelb, mModelc, mModeld);

But I`m clearly writing it wrong.

The `class list` route seems very interesting, unfortunately a little over my head atm.

Thanks again, very helpfull.
-Daz.





Re: XNA Game Studio Express Loading a Model from a List<> problem?

Rick Mogstad

iconjunky wrote:

The `class list` route seems very interesting, unfortunately a little over my head atm.



Don't take this the wrong way, since we were all where you were at one time, but if you don't understand that concept, you are going to run into a lot of roadblocks. Its a pretty standard coding concept to use classes (further backed up by the fact that George suggested the same exact thing....)

Honestly, the best thing I could recommend is that you get some of the coding/C# fundamentals under your belt before you get too far into XNA, so that you don't end up burning yourself out trying to do things a rather difficult way.

Hope your project goes well.

-Rick