Daid
Member
I found it impossible to google into this. And so far no tutorial I've found covers it.
It's something I've used in UnrealScript (Unreal's own scripting language) alot. A class type variable.
I'll show an example: (Note that this code is pure example, real UnrealScript needs some more work/slightly diffrent syntax)
As baseclass for a weapon.
This allows for all basic firing code to remain in the weapon class, and only the variable needs to be modified if you want to fire a diffrent projectile. The projectile could even be modified by a pickup
(Ok, in this example a function "CreateProjectile" that only makes the projectile would also solve it, but read on)
Another use is a random pickup spawner for example, it has an array of class types. And selects a pickup to spawn from that.
Now I'm looking for a way to do this in C++, but I cannot find any. Does it exists at all?
It would clean up this code:
Into this:
(Also example code, the real code will include weight factors and stuff, just need to get this sorted first)
(PS, I could be totaly nuts for wanting something like this :blink: )
It's something I've used in UnrealScript (Unreal's own scripting language) alot. A class type variable.
I'll show an example: (Note that this code is pure example, real UnrealScript needs some more work/slightly diffrent syntax)
Code:
class Weapon extents Inventory
class<Projectile> MyProjectile;
function Fire(vector FireLocation, rotator FireDirection)
{
new MyProjectile(FireLocation, FireDirection);
}
Code:
class Shockrifle extents Weapon
function Init()
{
MyProjectile = class'Shockball';
}
(Ok, in this example a function "CreateProjectile" that only makes the projectile would also solve it, but read on)
Another use is a random pickup spawner for example, it has an array of class types. And selects a pickup to spawn from that.
Now I'm looking for a way to do this in C++, but I cannot find any. Does it exists at all?
It would clean up this code:
Code:
void CreateRandomItemAt(TVector Location)
{
switch(rand() % 3)
{
case 0: new TPotion(Location); break;
case 1: new TSword(Location); break;
case 2: new TShield(Location); break;
}
}
Code:
'class' RandomItems[MAX_ITEMS];
void CreateRandomItemAt(TVector Location)
{
new RandomItems[rand() % MAX_ITEMS](Location);
}
(PS, I could be totaly nuts for wanting something like this :blink: )