Announcement
Collapse
No announcement yet.
QuakeC wait/delay function?
Collapse
X
-
Yup, that's exactly what I'm talking about. That's how you do it. That code can be used over and over for all kinds of stuff and that's how it should be.
-
i use this
then at the bottom of that "func" you NEED to add a remove(self); which will remove the entity "work" after the execution of it's think func at said nextthink time.Code:entity (void() func, float t) job = { local entity work; work = spawn(); work.think = func; work.owner = self; work.nextthink = time + t; return work; };
It's much the same manner of how a grenade works. When you fire a grenade, it spawns the entity. If it touches another player it explodes, and the enitity is removed, otherwise it bounces on the ground and will explode per the .think function and nextthink that was assigned when the grenade was spawned.
Leave a comment:
-
or if you want to make something reusable, do exactly what zop said but wrap it in a reusable function that you can call whenever you need it. And anytime you need something keep doing that. Eventually you will have basically a Utils class of useful functions that can be easily used anytime you need.
That's actually one of the things that makes QC not that good (in a generic source sense) a lot of the code is very specific. It's much better to write generic code than keep writing the same code over and over with like 2 differences each time.
I can give you an example. My content manager handles well over 20 filetypes and it does it all in 2 functions (load and loaded). Due to all filetypes implementing the same interface, in a way, there is only 1 filetype. If I wrote the same code the QC way I would have well over 20 functions...(maybe over 40 depending how you look at it)
It's pretty simple to do this. Just write the function specifically and then figure out the parts which can be generic and move them to the arguments interface. For a really simple example, let's say you wanted to add 2 numbers together
(gist code - not QC and doesn't need to be for this example)
function add():Int
{
return 2 + 2;
}
change it to
function add(a:Int, b:Int):Int
{
return a + b;
}
the funny thing is, in QC it would practically be
add2and6()
add1and8()
add...LMAOLast edited by MadGypsy; 12-04-2016, 08:43 PM.
Leave a comment:
-
Chances are that you'll need to make a new entity with a think function that spits out what you want a few times before removing itself.
Leave a comment:
-
For single player mods you can do this without extensions pretty well.
One option is how .pain_finished does it. Trigger a specific time and do actions one it is reached.
Another option is how all the powerups in quake work. They use a similar method but are controlled in PlayerPostThink. That function is used every frame. You will not find a more accurate function in ssqc.
A lot of quake mods use functions like that.
Holding your fire button a specific time to release a more powerful shot. Or push it once and the weapon needs a second to load up before it can actually shoot. It is all possible with vanilla quake.
Leave a comment:
-
FTE has a 'sleep' builtin that waits X seconds before resuming. Specifically, it saves off the current execution context then reloads it once the timer is reached.
Obviously this blocks the caller too... Which is generally not what you want.
Alternatively, FTE has a 'fork' builtin which does the same except does not destroy the current context. The current context returns 0, and the new context returns 1, essentially returning twice... Which *really* confuses the caller, but you can also call the 'abort' builtin which silently kills the current context, which can prevent the function containing fork from screwing up the calling function too.
alternatively:
entity e = spawn(); //warning: do not spam entities. there's a 2 sec grace period so one per frame at 1000fps means you're cycling through 2000 different entities. sometimes you can use self's think function, sometimes its already in use needing a separate entity to do the thinking.
e.think = (void()){bprint("Timer reached\n"); remove(self);}; //I'm going to regret showing this syntax, huh.
e.nextthink = time + 1; // set the timer for 1 sec.
but yeah, QC is event based. There are events happening all over the place, touch events, think events, etc.
you cannot stop and just wait for a bit, at least not without consequences (like FTE's sleep builtin has).
But what you can do, even in vanilla quake, is to just schedule some entity to trigger a think event at the approximate time that you want to carry out the next part of your dasterdly plan. Yes this means multiple functions (possibly nested), but that's a price you'll have to pay for having things run at different times.
Leave a comment:
-
Its called a think function. A think function is a function that is run for a specific entity when the nextthink interval is reached. I'm sure you have seen them being used. Traditional quakec is very basic with think functions, but there are all kinds of neat tricks you can do with them that id never used them for.
It's hard to provide an example without a little more background on what you're trying to do though.
Leave a comment:
-
i do not understadn the concept, do you mean something like 3 shoots at once?? what about if you kkeep the fire button pressed???
Leave a comment:
-
QuakeC wait/delay function?
I'm trying to make a weapon that spawns projectiles at intervals instead of all at once but I can't seem to find any way to delay their spawns to get the effect I want.
Is there any way to delay a missile spawn? Some sort wait or sleep function?Tags: None
Leave a comment: