First off, I realized that the php base or something was interpreting my less-than-or-equals sign as some kind of tag, which was ruining the code. You can now download the code at:
http://roody.gerynarsabode.org/JC/findpath.h
Also, I forgot to mention that it is nice that you can get the gist of it even though I didn't comment it very well. In any case, I thought I'd go over some of my tricks for those who
don't see what's going on.
forward property- proximity to start room; the closer it is, the higher the number is
backward property- same thing with end room
dirsteps property - this is just property array used to hold each of the steps that will eventually be fed into the character script array (number of elements determined by MAXDISTANCE constant)
Checking-every-object code-
When I run out of better ways to do things, I check every object "by hand", using a for loop. What makes this convenient is the objects global variable, which the compiler sets to the total number of objects in the game. That'll obviously be the last value of our for loop. To begin with, you'll notice that if you compile with HugoFix on and look at the object tree, the 29th object is a last_library_object defined by HugoFix. This means that non-lbrary objects start at their
earliest at object number 29, which is where our for loop should start.
In your own games, you could create a "firstobject" object after hugolib.h is included, allowing a for loop like this:
Code: Select all
for ( i = firstobject ; i (is less than or equal to) objects ; i++)
Using properties-as-numbers- In one way, I guess I've known that properties are basically number values for a while, especially when it comes to the idea that aliases are a-different-name-with-the-same-value. I recently read Kent's reply in this thread, though:
http://www.joltcountry.com/phpBB2/viewt ... f0c98c4ade
So, in findpath.h, I wanted to check every exit of the room using a for loop. First, I tried using the
order defined values listed on the HbE properties page. These turned out to be way off from actual values, so I went and figured out each value by writing a program with a loop and wrote them all down by hand. Of course, aliases explained some discrepancies, but I also hadn't taken into account that numbering started at 0, not 1.
So, now I knew I could refer to n_to as 24, but I still wasn't happy with that since, as unlikely as it is that properties would be reordered in a future iteration of the library, a change would definitely break my system. Then it finally occurred to me that I didn't need to use an actual number at all, I could just do this:
Code: Select all
for ( i = n_to ; i (is less than or equal to) out_to ; i++)
(n_to is the first defined property; out_to is the last)
Now, the engine will always get that right.
character script-
The syntax for setting a character script looks like a mess. I'd say that character scripting is one of Hugo's worst offenders in terms of do-it-this-way-without-really-understanding-what's-going-on. It doesn't help that when I look at the Script routine, Kent uses an "o" as the local variable, and it always takes me a minute or so to remember that those aren't all zeros.
When it comes down to it, though, Script(char,steps) does some important stuff, but in terms of that "setscript[Script(character object,number of steps in script)]" command, it just basically returns a number so you can build a character routine like this:
Code: Select all
setscript[0] = &CharMove, e_obj , &CharWait, 0, &LoopScript, 0
(where setscript[0] = &CharMove, setscript[1] = e_obj , setscript[2] = &CharWait, etc.)
My code just first ran Script(char,steps) to get the initial return number, then fills out the setscript array in a more leisurely fashion with a while loop:
Code: Select all
b = 1
a = Script(char, PropertyCount(char,dirsteps))
while b <= PropertyCount(char,dirsteps)
{
setscript[a++] = &CharMove
setscript[a++] = char.dirsteps #(b++)
}
Ok, so I think those are the most interesting things that my code does, but if anyone has any other questions, feel free to ask!
First off, I realized that the php base or something was interpreting my less-than-or-equals sign as some kind of tag, which was ruining the code. You can now download the code at: http://roody.gerynarsabode.org/JC/findpath.h
Also, I forgot to mention that it is nice that you can get the gist of it even though I didn't comment it very well. In any case, I thought I'd go over some of my tricks for those who [i]don't[/i] see what's going on.
[b]forward property-[/b] proximity to start room; the closer it is, the higher the number is
[b]backward property-[/b] same thing with end room
[b]dirsteps property -[/b] this is just property array used to hold each of the steps that will eventually be fed into the character script array (number of elements determined by MAXDISTANCE constant)
[b]Checking-every-object code-[/b]
When I run out of better ways to do things, I check every object "by hand", using a for loop. What makes this convenient is the objects global variable, which the compiler sets to the total number of objects in the game. That'll obviously be the last value of our for loop. To begin with, you'll notice that if you compile with HugoFix on and look at the object tree, the 29th object is a last_library_object defined by HugoFix. This means that non-lbrary objects start at their [i]earliest[/i] at object number 29, which is where our for loop should start.
In your own games, you could create a "firstobject" object after hugolib.h is included, allowing a for loop like this:
[code]
for ( i = firstobject ; i (is less than or equal to) objects ; i++)
[/code]
[b]Using properties-as-numbers-[/b] In one way, I guess I've known that properties are basically number values for a while, especially when it comes to the idea that aliases are a-different-name-with-the-same-value. I recently read Kent's reply in this thread, though: http://www.joltcountry.com/phpBB2/viewtopic.php?t=1726&sid=cf606282808c972c1767eaf0c98c4ade
So, in findpath.h, I wanted to check every exit of the room using a for loop. First, I tried using the [url=http://hugo.gerynarsabode.org/index.php?title=Properties#Predefined_properties]order defined[/url] values listed on the HbE properties page. These turned out to be way off from actual values, so I went and figured out each value by writing a program with a loop and wrote them all down by hand. Of course, aliases explained some discrepancies, but I also hadn't taken into account that numbering started at 0, not 1.
So, now I knew I could refer to n_to as 24, but I still wasn't happy with that since, as unlikely as it is that properties would be reordered in a future iteration of the library, a change would definitely break my system. Then it finally occurred to me that I didn't need to use an actual number at all, I could just do this:
[code]
for ( i = n_to ; i (is less than or equal to) out_to ; i++)
[/code]
(n_to is the first defined property; out_to is the last)
Now, the engine will always get that right.
[b]character script[/b]-
The syntax for setting a character script looks like a mess. I'd say that character scripting is one of Hugo's worst offenders in terms of do-it-this-way-without-really-understanding-what's-going-on. It doesn't help that when I look at the Script routine, Kent uses an "o" as the local variable, and it always takes me a minute or so to remember that those aren't all zeros.
When it comes down to it, though, Script(char,steps) does some important stuff, but in terms of that "setscript[Script(character object,number of steps in script)]" command, it just basically returns a number so you can build a character routine like this:
[code]
setscript[0] = &CharMove, e_obj , &CharWait, 0, &LoopScript, 0
[/code]
(where setscript[0] = &CharMove, setscript[1] = e_obj , setscript[2] = &CharWait, etc.)
My code just first ran Script(char,steps) to get the initial return number, then fills out the setscript array in a more leisurely fashion with a while loop:
[code]
b = 1
a = Script(char, PropertyCount(char,dirsteps))
while b <= PropertyCount(char,dirsteps)
{
setscript[a++] = &CharMove
setscript[a++] = char.dirsteps #(b++)
}
[/code]
Ok, so I think those are the most interesting things that my code does, but if anyone has any other questions, feel free to ask!