Inside3D!
     

More code migraines from lack of quakeC lore

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
TargetPractice



Joined: 30 Nov 2006
Posts: 17

PostPosted: Thu Nov 08, 2007 5:11 am    Post subject: More code migraines from lack of quakeC lore Reply with quote

I've run into yet another hive of bugs with my efforts at coding. I think the error results from my lack of understanding of how to use trace_ent, how to check for a flag, and how to bond strings. Not to mention general rustiness (I've been focused on other matters).

The game seems to be ignoring my command to activate the code entirely, despite my invoking it with an impulse. FrikQCC claims that the code has 'no errors'.

The code in question(shortened):

void() Scan =
{
local vector src;
makevectors(self.v_angle);
src = self.origin + v_forward*10;
src_z = self.absmin_z + self.size_z * 0.7;//Stolen from axe code
traceline(src, src+v_forward*2048, FALSE, self);

//Yes, max range is 2048.
if ((trace_fraction == 1) || (trace_ent.classname == "world") || (trace_ent.flags & FL_MONSTER)) //Potential error
return;
//Has to hit a monster- first two check to see if it hit something, third checks to see if it wants to kill you.


string maxhealth, monstname, paininneck; //Strings to be incorporated into the centerprint later.

//This is a giant IF loop; the full loop lists ALL the monsters in quake. Trust me when I say that I'm saving you time by showing the first example.
//No ELSE statements; frikQCC complained for some reason, and quieted when I removed them. I'll try reinserting them later.
if (trace_ent.classname == "monster_army")
{
monstname = "Soldier";//Name from manual
maxhealth = "30";//From code, initial health
}

// paininneck = (monstname, "\n" + ftos(trace_ent.health) + "/" + maxhealth + "\n");


centerprint(self, monstname/* + "\n" + ftos(trace_ent.health) + "/" + maxhealth + "\n"*/);//Commented out code here to try to get the thing to quit complaining about improper centerprint use.
centerprint(self, "\n");
};


//Inserted between 12 and 255 in-code
if (self.impulse == 13)
Scan ();

I think these are the only alterations to the code. Thank you for any aid you offer, in advance.
Back to top
View user's profile Send private message
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Thu Nov 08, 2007 5:47 am    Post subject: Reply with quote

You can't call centerprint twice like that, the second one will override it and just print an invisible newline...

Just skip the "\n" printing, because centerprints don't need the newline at the end like sprint/bprint does.

Also, + isn't a string concatenator in QuakeC. Quake originally had no string concatenation support (every string was constant). What you can do is redefine centerprint in defs.qc as:

void(entity e, string s, ...) centerprint = #whatever;

This should allow you to pass one or more strings into centerprint and they will basically be concatenated by the engine centerprint() implementation.

centerprint(self, monstname, "\n", ftos(trace_ent.health), "/", maxhealth);

But you can only use 8 arguments in a call to a builtin function, so watch out. A more portable alternative without varargs (which requires FrikQCC) is:

void(entity e, string a) centerprint = #whatever;
void(entity e, string a, string b) centerprint2 = #whatever;
void(entity e, string a, string b, string c) centerprint3 = #whatever;
...
void(entity e, string a, string b, string c, string d, string e, string f, string g) centerprint7 = #whatever;

Also, if you were to call ftos() twice it would bugger up (requiring strzone probably) but it's a good thing you aren't... Actually, it looks like you are already aware of this, as you are storing maxhealth in a string...
_________________
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Thu Nov 08, 2007 12:08 pm    Post subject: Reply with quote

(trace_ent.flags & FL_MONSTER)

You probably want to logical-not (!) that too.



and yeah, string+string is meant to be a syntax error, except that frikqcc silently ignores them because they could be really really evil hacks that otherwise work. FTEQCC generates errors. Smile

Small note:
void(...) centerprint = #whatever;
The above works for any qcc (when compiled its the same as the multiple versions of centerprint, so works with any engine too). But note that while you can do it like that in any qcc, you loose type checking.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
TargetPractice



Joined: 30 Nov 2006
Posts: 17

PostPosted: Thu Nov 08, 2007 2:57 pm    Post subject: Reply with quote

Okay, let's see if I understand what to do correctly:

1)Peel off the extra newline centerprint.
2)Fiddle with defs.qc to create concatenated string lines(I'll use the latter technique; it may be less elegant, but it's more universal)
3)Negate the FL_Monster check to its correct application
4)Alter my code to perfect the effects intended

I found out about ftos() when I was glancing through the wiki.quakesrc.org for code functions I could use; I saw it, took a look at its description, and learned about the bug. The other reason I handled maxhealth like that is because I failed to observe any "self.maxhealth = wakka" lines attached to the monsters' code, and so decided to store them in the main function of the new code (makes it easier to transplant into another mod).

Would it be possible to overload centerprint thusly?

void(entity e, string a) centerprint = #whatever;
void(entity e, string a, string b) centerprint = #whatever;
void(entity e, string a, string b, string c) centerprint = #whatever;
//Repeat for all 8 variants

Thanks for the aid.
_________________
I never thought hearing pained, fearful screams could make one feel so... uplifted.

What?
Back to top
View user's profile Send private message
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Thu Nov 08, 2007 3:26 pm    Post subject: Reply with quote

Note that the "whatever" is actually a specific builtin number, you'll need to look it up (dpmod source is one place to find those). Doing what you said won't work, it will probably complain about re-defining a builtin or something. They need individual names. And because of that, I'd recommend using the centerprint(entity e, string s, ...) technique, since that allows virtually infinite strings to concatenate into a single call, as well as the flexibility to choose the amount of parameters to feed it.
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
TargetPractice



Joined: 30 Nov 2006
Posts: 17

PostPosted: Fri Nov 09, 2007 12:33 am    Post subject: Reply with quote

I am now aware of the error of trying to overload centerprint() like I suggested; frikQCC complained when I tried it.

I've pulled the appropriate max health for each critter from the appropriate creature QC files.

And now I have the function working. I had to make the code recognize Cthon and Shubby, but it works.

Now to form a tutorial. Thanks, all!
_________________
I never thought hearing pained, fearful screams could make one feel so... uplifted.

What?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group