Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Breaking stacked commands.
|
Breaking stacked commands.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #15 on Wed 12 Apr 2006 05:18 AM (UTC) |
| Message
| I'm not sure why it doesn't work because I don't know where you've put it in the code. I tested it on some sample data, and it returns correctly for the four or five test strings I gave it.
By the way, it's a little weird for your function to return false on success and true on failure. The reason that str_cmp returns 0 on success is because it returns -1, 0 or 1. The idiom of writing 'if ( !strcmp("a", "a") )' is actually very horrible because it messes with your mind regarding 'true' and 'false'. That being said, most of the SMAUG functions like str_prefix return false on success, so I guess that at least it's consistently weird... :-)
Also, you could improve the efficiency of this code by jumping ahead by however many characters of prefix there actually were. In your case, if I was searching for the string "aab" in "aaaaaaab", it would waste all kinds of time by examining every character after the first twice. Still, it's probably not worth it for the relatively minor gain you'll see in practice, given how small the search buffers are. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Gohan_TheDragonball
USA (183 posts) Bio
|
| Date
| Reply #16 on Wed 12 Apr 2006 10:14 AM (UTC) Amended on Wed 12 Apr 2006 10:26 AM (UTC) by Gohan_TheDragonball
|
| Message
|
Quote:
Also, you could improve the efficiency of this code by jumping ahead by however many characters of prefix there actually were. In your case, if I was searching for the string "aab" in "aaaaaaab", it would waste all kinds of time by examining every character after the first twice. Still, it's probably not worth it for the relatively minor gain you'll see in practice, given how small the search buffers are.
Sorry, not exactly sure what you are saying. How is the code I am using inefficient. From what I gathered you are saying, in the case of your example with "aab", I should jump ahead 3 characters each time, and since that sounds stupid I am going to assume that I misinterpreted what you wrote.
And to be honest, its not my code, i just modified str_infix() which was already in my code from smaug.
Also, what does it matter where I put it, I said in the previous post I just commented out where I called my str_infix_n() function and called yours instead. However for arguments sake I wrote a command: do_test()
void do_test( CHAR_DATA *ch, char *argument )
{
ch_printf( ch, "Testing str_has_command() with argument(%s): %s\n\r", argument, str_has_command(argument,argument) ? "Found" : "Not Found" );
return;
}
> test
Testing str_has_command() with argument(): Not Found
> test test
Testing str_has_command() with argument(test): Not Found | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #17 on Wed 12 Apr 2006 04:02 PM (UTC) |
| Message
| What I was saying is that the for loop doesn't need to advance one character at a time. It needs to advance, rather, by one character, plus the number of characters that were also matched in the prefix search.
It's a little hard to explain quickly. Basically the problem is that it's potentially examining characters twice. But like I said it's not a big deal in practice.
Anyhow, as for why the function is not working for you is very strange because it's working all happy scrappy for me. Did you copy/paste the code exactly or did you make modifications? How are 'bool', 'true' and 'false' defined in your code, which I assume is C and not C++? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Gohan_TheDragonball
USA (183 posts) Bio
|
| Date
| Reply #18 on Wed 12 Apr 2006 05:04 PM (UTC) |
| Message
| #if !defined(FALSE)
#define FALSE 0
#endif
#if !defined(TRUE)
#define TRUE 1
#endif
And yes I did a fresh copy/paste before replying just to be sure. As to the other thing, I think I kind of understand what you are trying to say, but its still beyond me. I am a capable mud owner and implementor but advanced progammer I am not, I can't even get a decent grasp on creating a 3dmmorpg! | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #19 on Wed 12 Apr 2006 05:27 PM (UTC) |
| Message
| That's FALSE and TRUE; my code uses false and true. Are those defined for your MUD, and if so, how? Or did you change false and true in my code to FALSE and TRUE?
And for what it's worth, going from a MUD to a 3D MMORPG is a pretty big step! Besides, before going to a 3D MMORPG, you need to try implementing even "just" a MUD code base from scratch. It's a pretty hard task.
If you're curious about the text searching stuff, check out these slides:
http://www.stanford.edu/class/linguist139p/FSAMotivation.pdf
They explain the bit about how to avoid checking letters twice.
Implementing the search as a state machine solves that, except for one little hack that I used because I was lazy (and I noted it in comments). |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
64,940 views.
This is page 2, subject is 2 pages long:
1
2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top