Author Topic: add_item  (Read 3070 times)

Offline petriomelony

  • Acquaintance
  • *
  • Posts: 34
    • View Profile
add_item
« on: April 13, 2009, 06:43:24 PM »
I was working my way through the new discworld creator LPC for dummies guide (which is fantastic, if anyone wants to know.  a big props to Drakkos for it), and I got to a part about making items in the room searchable.  Now I know that skylib != dw, but they have quite a few similarities.  I just could not get the searchable items thing working (without defining a search string comparison).

This is what the guide said to try:

Code: [Select]
add_item ("jagged rock",
({
  "long", "This is a jagged rock.",
  "searchable", "#search_rock",
  "position", "on the jagged rock",
  ({"kick", "punch"}), "Ow! That stung!\n",
}));

and this is what I ended up doing:

Code: [Select]
int do_search(string str)
{
  if (str == "rock")
  {
    call_out ("search_rock", 3);
    return 1;
  }
  return -1;
}

I know call_outs are bad, which is why I wanted to avoid this code, but this is what was used in one of the stock rooms (part of the creator school). 

Note: Using the example code from the DW LPC guide, I could literally type "searchable rock" and it would return the string "#search_rock".  I also tried changing "searchable" to just "search", but that would just do a room search if i typed "search rock".

I guess my question is: does anyone know of a better way to make something searchable in skylib?

Thanks!
« Last Edit: April 13, 2009, 06:45:47 PM by petriomelony »

Offline vexcesban

  • Acquaintance
  • *
  • Posts: 25
  • -Noobie Mud Admin-
    • View Profile
Re: add_item
« Reply #1 on: April 14, 2009, 10:35:39 AM »
There is nothing wrong with calls out really, so long as you use them properly. A call out in a room that kept looping over and over searching for something could be bad if there are a LOT of them in the mud, but as far as this code is concerned the call_out is fine. Just make sure to remove the call_out in the function search rock so that you don't loop.

int do_search(string str)
{
  if (str == "rock")
  {
    call_out ("search_rock", 3);
    return 1;
  }
  return -1;
}

search_rock()
{
  remove_call_out("search_rock");
  write("You search the rock.\n"); 
  return 1;
}

The one problem however with something like this is that if the player spams search rock, its going to call the search_rock function as many times as they enter it, which could look bad from a players perspective :), i know in my mud we have temporary attributes we can set to stop this. I know nothing about either of those libs as i use h7, so maybe someone with experience with the lib knows of something in place to do so , or has a better way. GL
« Last Edit: April 14, 2009, 10:38:01 AM by vexcesban »

Offline chaos

  • BFF
  • ***
  • Posts: 291
  • Job, school, social life, sleep. Pick 2.5.
    • View Profile
    • Lost Souls
Re: add_item
« Reply #2 on: April 14, 2009, 12:02:30 PM »
Just make sure to remove the call_out in the function search rock so that you don't loop.

call_outs don't loop on their own; they loop because you perform another call_out to the same function within it.  Calling remove_call_out() in this case isn't preventing looping, it's making it so that if a player is spamming searches, they will get 1 search executed for every 2 they initiate.

call_outs are a little complex, but they aren't black magic.  If people find them confusing, I'd recommend some experimentation with simple cases containing a lot of debug feedback, so you can see what happens with them as you change them around.

Offline quixadhal

  • BFF
  • ***
  • Posts: 618
    • View Profile
    • A Waste of Time
Re: add_item
« Reply #3 on: January 29, 2014, 03:49:16 PM »
Woot!  Thread necromancy FTW!

Just because I happend to browse across this and thought of it...

What you could do to prevent call_out() spamming is make the function that is being called set a property somewhere (perhaps in the player object that caused the call_out?) that the function can check.  If the property is set, just return.  If it's not set, set it and do whatever you wanted to do, perhaps scheduling a call_out a bit in the future to remove the property (assuming you want them to be able to do it multiple times, just not 20 times in 2 seconds).