QuakeC class in FTEQCC
Moderator: InsideQC Admins
5 posts
• Page 1 of 1
QuakeC class in FTEQCC
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?
self.knife.PrimaryAttack(); // to attack
- 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: 93
- Joined: Thu Dec 15, 2011 1:00 pm
Re: QuakeC class in FTEQCC
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
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 
- Max_Salivan
- Posts: 93
- Joined: Thu Dec 15, 2011 1:00 pm
Re: QuakeC class in FTEQCC
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.
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.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Re: QuakeC class in FTEQCC
hmm,thanks,Spike,i'll try to understand this
i am usin last fteqccgui from http://triptohell.info/moodles/fteqcc/
i am usin last fteqccgui from http://triptohell.info/moodles/fteqcc/
Sorry for my english 
- Max_Salivan
- Posts: 93
- Joined: Thu Dec 15, 2011 1:00 pm
Re: QuakeC class in FTEQCC
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
- OneManClan
- Posts: 243
- Joined: Sat Feb 28, 2009 2:38 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest