News | Forum | People | FAQ | Links | Search | Register | Log in
Coding Help
This is a counterpart to the "Mapping Help" thread. If you need help with QuakeC coding, or questions about how to do some engine modification, this is the place for you! We've got a few coders here on the forum and hopefully someone knows the answer.
First | Previous | Next | Last
Yeah I Know 
Any sensible person would design a DB in MySQL, but we are not allowed to use MySQL (go figure?!) - which sucks because any real-world application would use MySQL or SQL or even .net + access or whatever, but 'noooooo', not my retarded course. php + XML is the recipe of the day. Fuck it, I guess I'll learn something at the end of the day ... 
Dude 
ditch array_search and iterate through the arrays manually. It's pretty simple. 
Could You Perhaps Show Me An Example Of A Loop? 
I can handle a stupified approach, I just wanna get a fucking A. I don't care if I have to re-design my data structure completely, I have been thinking about this for far to long now and my brain hurts... 
 
Hey, XML can be fun and it is quite simple if you use a good parser. seriously! 
 
I enjoy the transition from, "Stupid class, can't use a database, have to use XML, *grumble*" to "can you show me an example of a loop?"

Walk before you run, Ricky. :) 
Ricky 
If you don't know what a loop looks like, how can you expect to get an A in a programming class?

Here is an explanation of the most important loop constructs in PHP:
http://nefariousdesigns.co.uk/loopy.html 
Lol - I Do Know What A Control Loop Looks Like 
However that is a rather good reference!
Thanks :)

I don't really know that many types of loop, just while loops and for loops.

I think I'm getting somewhere with it now, I used the following bit of code to remove the extra level of array which was preventing me from being able to use the array_search function:

$b=$a['Rrestaurant'];

Dumb, huh? I thought I was going crazy!

Also - I WILL get an 'A'. I could have done the lame thing and just planned a static website. The level of the course is not so high that I have to do a PHP website, but I really want to learn some programming, so I set myself the challenge.

August last year, I had never coded anything really, since messing around with BASIC like 15 years ago.

Now I have coded a text-based version of minesweeper (which is 200KB, fuck)(the second half of the assignment will be probably a discussion of how I can use functions to simplify my code).

And this flippin XML/PHP project. You've got to start somewhere!

But seriously, thanks again. 
Success! 
OK, so now that I've figured out how to access my arrays within the array that was within an array, and started iterating through it manually with my loops, I'm having success :)


$search = 'the';

$resultsCounter = 0;

function object2array($object){return@json_decode(@json_encode($object),1);}
$xml = simplexml_load_file("places.xml");
$a = object2array($xml);
$b=$a['Rrestaurant'];
$count = count($b);
for ($x=0;$x<=($count-1);$x++){
$c = $b[$x];
$d = $c['Rinfo'];
if (strpos($d,$search)) { echo $c['Rname'] . '<br /><br />' . $c['Rinfo'] . '<br /><br />' . $c['Rindex'] . '<br /><br />'; $results[$resultsCounter] = $c['Rindex']; $resultsCounter++; }
}
$count = count($results);
for ($x=0;$x<=($count-1);$x++){
echo $results[$x] . ' ';
}


I'm sure that's probably pretty hideous, but its giving me nice search results :) :) :) 
Doh! 

$search = 'the';

$resultsCounter = 0;

function object2array($object) {return@json_decode(@json_encode ($object),1);}
$xml = simplexml_load_file ("places.xml");
$a = object2array($xml);
$b=$a['Rrestaurant'];
$count = count($b);
for ($x=0;$x<=($count-1);$x++){
$c = $b[$x];
$d = $c['Rinfo'];
if (strpos($d,$search)) { echo $c['Rname'] . '<br /><br />' . $c['Rinfo'] . '<br /><br />' . $c['Rindex'] . '<br /><br />'; $results[$resultsCounter] = $c['Rindex']; $resultsCounter++; }
}
$count = count($results);
for ($x=0;$x<=($count-1);$x++){
echo $results[$x] . ' ';
}
 
Now Try: 
some better variable names and have a look at foreach 
Yeah 
Don't call variables 'a' or 'b' - give them a name that reflects their meaning in the program. 
Ah - Good Idea. 
$wholeArray
$wholeCumbrianRD
$wholeRrestaurant
$wholeKey
 
Craving Your Indulgences Again 
I don't do much qc but whenever I do I find myself running into brick (BRICKL_0 or similar) walls.

I have a procedure that I want to run x times as selected from the editor (self.something = x). I want to say along the lines of:-

void () Proc1

do some stuff

while (self.something >0)
do this
wait random y to z seconds
self.something = selfsomething - 1
ewhile
do some other stuff

endproc

(I know I am mixing languages, I am just trying make it look obvious what I am doing)

When looking at 'think' and 'nextthink' examples, they all seem to act on an external procedure/function before returning to the calling procedure/function. I also see use of recursion i.e. a procedure/function calling itself.

Is it necessary to use 'think' and 'nextthink' for timing purposes in my ditty above or is there some other construct available. If I need to use 'think' and 'nextthink' is it therefore advisable to separate the 'while/ewhile' (or whatever loop is used) into its own proc/func? 
 
you are thinking about it the wrong way.
best to think about what gets done in a frame and what doesn't.

nextthink and think is what you need to delay over multiple frames.
doing a while loop will do everything in the same frame.

in this case, you don't want a while loop at all.

void() proc1
{
//some stuff here

self.think = proc1; //run this again
self.nextthink = time + (some random amount here);
}


the way nextthink works sort of is that the engine looks at what nextthinks are > current time and when they become < current time, the engine sets nextthink the 0 and runs the .think function with self as the 'thinking' entity. 
Necros 
So the engine is not waiting for my procedure but it will have my 'thinks' queued up? Also, do I not think of this a true recursion?

By the way, I just ovelayed the draflam2.spr with the bigexp.spr (just via an entity choice in the editor and using two entities) and it looks pretty smart. I am not sure what it will look like to a player seeing it for the first time in a game - you know how fussy Quake people are :) But it looks good enough to blow the head of a Vermis! 
 
no, it is not recursion.
recursion is when a function calls itself.
you can accomplish this in qc with the usual method:

void() proc1
{
//stuff
proc1();
}

this also does everything on the same frame, just like for and while loops.

when you use thinks, it is the engine that is calling the function when nextthink ticks by.

for the explosion, if you're feeling adventurous, you could try throwing a bunch of MOVETYPE_TOSS invisible entities out of the explosion point that spawn explosion sprites themselves. ;)
looking forward to seeing it. 
Queuing 
To add, there is no queue with think functions, you only get one. So if you have code like

self.nextthink = time + 0.5;
self.think = CleanTheDishes;

self.nextthink = time + 2;
self.think = CookDinner;

the second think function overwrites the first one and so you end up eating off dirty plates. One way to fix that is to move the code which sets up CookDinner into the CleanTheDishes function, chaining the functions one after another.

This worked because our two functions were dependent. If you need your entity to think about two independent things one solution is
to have a master think function. This should think regularly, and check timers on your entity manually. The way that playerprethink and playerpostthink handle powerups running out is an example of this pattern.

If that's too complicated, the other way is to have two separate entities, as each one has its own think function and nextthink timer. 
Preach 
Nice analogy; because we don't want to be eating off dirty plates now, do we?

It is falling into place, so thanks. 
QCC 
I have been compiling my own progs.dat file using the tools from the ID FTP. Is there a good base of .QC files? Has the community got an agreed on base? Any recommendations? Something to start from? 
All Can Be Found Here: 
Door Key Use Sound Troubadour Verily 
Ok, this is fairly what-the-christ.

So, I'm running around my mod opening doors with keys. Use a key, door opens - it just plays the door open sound. I'm thinking hang on...didn't it used to play a "use key" sound before when it opened?

I then check vanilla quake. But no, even playing vanilla quake - no mods - key doors are only making the door open sound when they open.

I look in the QC - vanilla QC - the door is *trying* to make a "use key" sound, but it's immediately getting overridden by the "door open" sound (same channel). Looks like that's how it behaves all the time. So, another id bug to fix then. But why do I have a very clear memory of hearing the use key sound in vanilla Quake??

And more creepily, why did Scampie hear it on some compiles of his map, but not on others??

What is this door devilry?? 
 
sock: and definitely use a new compiler.
you can use more c conventions like for loops and increment and decrement operations.
also removes arguably useless stuff like needing semicolons after function braces.

kinn: not sure, but maybe because czg's progs from his last map pack had a fixed variation where the key sound plays and the door opens after a short delay? 
More Door Bollox 
ok, so i've fixed the key use sound thing, and also for visual effect added a small delay between the key being used and the door actually opening. This introduced me to something that I never knew anything about before. Namely this:

in door_touch, if I replace the call to door_use(), with:


self.nextthink = time + 1;
self.think = door_use;


The door actually opens after about 10 seconds, not 1 second. (whu?)

if I write:


self.nextthink = self.ltime + 1;
self.think = door_use;


The door opens after 1 second, as expected.

do doors play by totally different rules when it comes to time and nextthink shizzle? 
Hah 
wrote that before seeing necros' post :}, didn't know czg did this but maybe that's where i'm remembering it from... 
 
preach made a fantastic post about this explaining how nextthinks work on MOVETYPE_PUSH entities:
http://celephais.net/board/view_thread.php?id=60097&start=330&end=330 
First | Previous | Next | Last
You must be logged in to post in this thread.
Website copyright © 2002-2024 John Fitzgibbons. All posts are copyright their respective authors.