Forum

QuakeC class in FTEQCC

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

QuakeC class in FTEQCC

Postby Max_Salivan » Tue Aug 02, 2016 5:22 pm

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: 81
Joined: Thu Dec 15, 2011 1:00 pm

Re: QuakeC class in FTEQCC

Postby Max_Salivan » Tue Aug 02, 2016 8:16 pm

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 :)
Max_Salivan
 
Posts: 81
Joined: Thu Dec 15, 2011 1:00 pm

Re: QuakeC class in FTEQCC

Postby Spike » Wed Aug 03, 2016 2:06 am

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.
Spike
 
Posts: 2771
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: QuakeC class in FTEQCC

Postby Max_Salivan » Wed Aug 03, 2016 6:18 pm

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

i am usin last fteqccgui from http://triptohell.info/moodles/fteqcc/
Sorry for my english :)
Max_Salivan
 
Posts: 81
Joined: Thu Dec 15, 2011 1:00 pm

Re: QuakeC class in FTEQCC

Postby OneManClan » Tue Jan 03, 2017 1:24 pm

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: 242
Joined: Sat Feb 28, 2009 2:38 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 9 guests