Lokai
Knight
How to create Items based on a Type
OK, this one is hard even to describe, so I will post some pseudo code to illustrate.
Now, what I want to do is based on this next bit of code, so its the most important part. Lets pretend that I have many classes that are all Shapes. Some of them are Derived from Square, some from Circle, and some from Triangle. The one below is Derived from Square. I have named it DerivedSquare1 for simplicity. It has 2 variables, both Types, because they can be any type of Shape, one based on Circle, and the other based on Triangle. But I do not know which during Scripting, because there are many, like DerivedTriangle1, DerivedTriangle2, etc. SO HERE IS THE QUESTION: How do I create the items based on a Type? I don't just want to create BaseTriangle and BaseCircle, because they don't have all the code I need, it has to be specific Types which are derived from the base types.
Am I missing something easy?
[/code]
OK, this one is hard even to describe, so I will post some pseudo code to illustrate.
Code:
using System;
namespace MyWorld
{
public class BaseShape : Item
{
//code here
}
}
Code:
using System;
namespace MyWorld
{
public class BaseSquare : BaseShape
{
//code here
}
}
Code:
using System;
namespace MyWorld
{
public class BaseCircle : BaseShape
{
//code here
}
}
Code:
using System;
namespace MyWorld
{
public class BaseTriangle : BaseShape
{
//code here
}
}
Now, what I want to do is based on this next bit of code, so its the most important part. Lets pretend that I have many classes that are all Shapes. Some of them are Derived from Square, some from Circle, and some from Triangle. The one below is Derived from Square. I have named it DerivedSquare1 for simplicity. It has 2 variables, both Types, because they can be any type of Shape, one based on Circle, and the other based on Triangle. But I do not know which during Scripting, because there are many, like DerivedTriangle1, DerivedTriangle2, etc. SO HERE IS THE QUESTION: How do I create the items based on a Type? I don't just want to create BaseTriangle and BaseCircle, because they don't have all the code I need, it has to be specific Types which are derived from the base types.
Am I missing something easy?
[/code]
Code:
using System;
namespace MyWorld
{
public class DerivedSquare : BaseSquare
{
public Type TriangleType;
public Type CircleType;
// HERE IS WHERE I WANT TO CREATE SOME ITEMS
Item i = new Item; //not what I want.... I want somehow to call typeof(TriangleType) or something...??
Item j = new Item;
}
}