Page 1 of 1

QuakeC class in FTEQCC

Posted: Tue Aug 02, 2016 5:22 pm
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

Re: QuakeC class in FTEQCC

Posted: Tue Aug 02, 2016 8:16 pm
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

Re: QuakeC class in FTEQCC

Posted: Wed Aug 03, 2016 2:06 am
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.

Re: QuakeC class in FTEQCC

Posted: Wed Aug 03, 2016 6:18 pm
by Max_Salivan
hmm,thanks,Spike,i'll try to understand this

i am usin last fteqccgui from http://triptohell.info/moodles/fteqcc/

Re: QuakeC class in FTEQCC

Posted: Tue Jan 03, 2017 1:24 pm
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