Forum

hammer time!! (actually, noob time)

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

hammer time!! (actually, noob time)

Postby behind_you » Wed Jun 15, 2011 9:10 am

okay, just got a few questions that are really driving me nuts.

1- whats the difference between a void() and a function()? I use voids all the time, and every once in a while the compiler spits out errors to me saying i need a function() instead of a void(). i change it, everything is fine after. why does it ask me to do that?

2- can someone post an example .skin file? i'm having a lot of trouble with it

3- is there a way to search for a file, delete a file and rename a file through qc alone?

4- i use solid_bsp for my models to make it collide with stuff more accurately. it really lags though. why is this and can i prevent it from doing so?

5- i use find functions regularily. i always see people using .chain during the while (find). this stores all the entities that it finds, right? how do i get the results of chain to use?

thanks!!
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby Spike » Wed Jun 15, 2011 11:53 am

1: huh?
void() foo; returns nothing.
float() foo; returns a float, and you get a warning if it fails to return one.
example please.

2: see q3.

3: you can search for files, but you cannot rename nor delete (if only because they're inside a pak/pk3).

4: hitmodels are slow. don't use them if you can't afford the cost.

5: find() returns a single entity (the next one on from the one that was passed to it).
findrandius() returns a chain of entities. you generally need to iterrate through the entire chain for the vast majority of ways to use findradius.
findradius writes the .chain field. find does not. findradius will freely 'corrupt' the chain field if you use it for anything other than temporary use (that is, don't keep it beyond the end of your function, don't call findradius until you've finished using the chain).
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby behind_you » Mon Jun 20, 2011 8:32 am

Spike wrote:1: huh?
void() foo; returns nothing.
float() foo; returns a float, and you get a warning if it fails to return one.
example please.


I said function(). I never even heard of it before. Look at this little tutorial I posted (viewtopic.php?t=3436&highlight=). I tried making writefirst(); a void but the compiler said that i needed it to be a function(). I changed it, it worked fine. It's real strange.

2- Thanks!

3- so i can rename and delete files that are not in the paks?

4- alright good to know

5- i see. But is .chain a float or string or entity or what? i can't check now since my computer monitor at home doesn't work (FML)
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby Spike » Mon Jun 20, 2011 11:41 am

1. qc compilers don't internally care what the return value is.
They only care about void/float/vector/string/ent/pointer/function. The actual return value of a function is a separate check, so lazy prints will just say function() rather than giving an explicit void() or float() or string() or vector() or entity() message. By function() it means any of those void()-entity() forms, because its too lazy to give you a formal type definition. :)

Theoretically, you *could* have a function that returns a function... but that's generally too painful to mention.

3. no

5. .entity chain; ent.chain.chain.chain etc.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby behind_you » Tue Jun 21, 2011 8:12 am

Alright! Now i get it. Thanks Spike.

But i have some more questions, if that's ok.

1- every human player has his own set of cvars and their values, right? even qc registered ones?

2- let's say i add this to defs.qc:

entity THEMAN;

and in putclientinserver i do this:

THEMAN = self;


if you have more than one human player, who becomes THEMAN? or is 2 THEMAN entites generated?
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby Spike » Tue Jun 21, 2011 10:44 am

1. No. Every client has its own set of cvars, and every server has its own set of cvars.

if you set a cvar on the server, its set on the server. If you set a cvar on a client, it might set it on the server as well.
qc registered cvars registered on the server will be only on the server. qc registered cvars registered on the client will be only on that client and possibly the server. of course, you can register a cvar with the same name on multiple clients, but unless you're doing that in csqc, you probably shouldn't be doing it.

Potentially you may have two players using the same client, in which two players will share the same set of cvars, possibly with the server too... but that gets messy. :)

2. that's exactly identical to saying:
float fred;
fred = 1;
fred = 2;
gives fred two values simultaneously.

which is obviously not the case.
entity types are references to objects. just because you assign a reference somewhere doesn't mean that you create a new instance. your 'self' entity is not destroyed simply because you returned from your think function and another ent overwrote the self global for it's think function. self no longer refers to the old ent, but that doesn't the old ent from existing.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby behind_you » Wed Jun 22, 2011 8:03 am

i c. there should be an extra parm to creating a cvar that says which entity it will belong to ie(registercvar(self, "mycvar", "0");

thanks!
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby behind_you » Sat Jun 25, 2011 8:32 am

I have some more questions:

1- When drawing stuff on csqc, i noticed that it 'refreshes' everything every 0.1 seconds. How can I speed this up?

2- When I use 'while' anywhere, how fast does it loop?

3- I noticed that drawpic is a float. Why is that? Is there a way to figure out if the pic has been found or not when you want to draw it?

4- look at this function for my mouse in menuqc. Its supposed to check if the mouse is inside the desired box and return true or false. problem is that when it's supposed to be true, it rapidly switches between true and false for some reason. why does it do this?

Code: Select all
float check_mouse (vector pos, vector tsize) =
{
   vector smins, smaxs;
   
   smins = pos;
   smaxs = pos;
   smins_x = pos_x;
   smins_y = pos_y - 1;

   smaxs_x = pos_x + tsize_x;
   smaxs_y = pos_y + tsize_y;

   if (mouse_pos_x >= smins_x)
      {
      if (mouse_pos_x <= smaxs_x)
         {
         if (mouse_pos_y >= smins_y)
            {
            if (mouse_pos_y <= smaxs_y)
               return TRUE;
            }
         }
      }

   return FALSE;
}

Thanks again!
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest