QuakeC class in FTEQCC

Discuss programming in the QuakeC language.
Post Reply
Max_Salivan
Posts: 96
Joined: Thu Dec 15, 2011 1:00 pm

QuakeC class in FTEQCC

Post by Max_Salivan »

Hi,forum. i am learning how to use classes in qc by myself. Compiling is good,but i got crash in game...what i am doing wrong?

Code: Select all

class CKnife
{
	.void() PrimaryAttack;
	.void(float iDamage,float iDistance) Attack;
};
CKnife knife;
void CKnife::PrimaryAttack()
{
		self.knife.Attack(20,48);
}
void CKnife::Attack(float iDamage,float iDistance)
{
	local vector org, end;
	makevectors(self.v_angle);
	org = self.origin + self.view_ofs;
	end = org + v_forward * iDistance;
	traceline(org,end,0,self);
	if(trace_fraction ==1)
		return;
	if(trace_ent.takedamage)
		T_Damage (trace_ent, self, self, iDamage);
	else
		sound (self, CHAN_AUTO, "weapons/knife_hitwall1.wav", 1, ATTN_NORM);
}
self.knife.PrimaryAttack(); // to attack
Sorry for my english :)
Max_Salivan
Posts: 96
Joined: Thu Dec 15, 2011 1:00 pm

Re: QuakeC class in FTEQCC

Post by Max_Salivan »

maybe a bug,when you compile struct with "Automatic pototyping"
fteqcc says:error: struct foo is already defined


so....structs
struct wepspread_t
{
float MaxSpreadX;
float MaxSpreadY;

float SpreadX;
float SpreadY;
};

struct wepspread_t wepspread_s;

void() DefaultFire(entity pl,float cShots,wepspread_t spread);

just crashed fteqcc
Sorry for my english :)
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: QuakeC class in FTEQCC

Post by Spike »

regarding classes, 'self' is deprecated while inside class functions purely because its type is wrong.
instead, there's a 'this' variable (which actually aliases onto 'self' thereby allowing builtins etc to all work properly still).
the difference is that 'this' has the correct type for the class that was called.
note that class.method() will also automatically switch over self for the duration of the call.

polymorphism also works, thus the following should be okay, but I was too lazy to actually test it.

class cWeapon : entity
{
virtual void() attack;
};
.cWeapon weapon;

class cKnife : cWeapon
{
virtual void() attack =
{
print("die die die!\n");
}
};
void(entity someplayer) givethatplayeraknife =
{
someplayer.weapon = spawn(cKnife, owner:someplayer);
someplayer.weapon.attack(); //put that in response to pressing attack, etc.
};

with structs, if you've not updated fteqcc for a while then passing structs will probably do bad things. try updating if you didn't already do so (revision 5000+ should be okay).
also, your function definition is a function that returns a function, which is almost certainly not what you want.
Max_Salivan
Posts: 96
Joined: Thu Dec 15, 2011 1:00 pm

Re: QuakeC class in FTEQCC

Post by Max_Salivan »

hmm,thanks,Spike,i'll try to understand this

i am usin last fteqccgui from http://triptohell.info/moodles/fteqcc/
Sorry for my english :)
OneManClan
Posts: 247
Joined: Sat Feb 28, 2009 2:38 pm
Contact:

Re: QuakeC class in FTEQCC

Post by OneManClan »

Max_Salivan wrote:hmm,thanks,Spike,i'll try to understand this

i am usin last fteqccgui from http://triptohell.info/moodles/fteqcc/
An example of FTE Class polymorphism

Code: Select all

///// THE DEFINITIONS
class FooParent : entity
{
          
        // constructor
	void() FooParent =
        {
              dprint("I am a FOO\n");
	};
       
       
    virtual void () WhereAmI =
    {
        dprint("In FooParent\n");
       
    };
   
   
};
 
class FooChild: FooParent
{
   
    virtual void () WhereAmI=
    {
        dprint("In FooChild\n");
       
    };
   
   
};


SPAWNING:

Code: Select all

FooParent  e = spawn();
    e.WhereAmI();
FooChild e2 = spawn();
    e2.WhereAmI();
///// OUTPUT:
I am a FOO
In FooParent
I am a FOO
In FooChild
Post Reply