Area Search Function

All and any discussion and development of the Mudlet Mapper.
Post Reply
herbert
Posts: 16
Joined: Mon May 11, 2015 4:47 pm

Area Search Function

Post by herbert »

I been trying to figure this out for a few days now and thought to ask here incase someone has a better way to do it than I am..

Does anyone have a way (like in mudbot area search -name-) to search an area, info here, and stop when it finds what you are looking for?

As in I'd do AREA SEARCH APPLE and it'll go into all the rooms in that area one after another looking through the info here and when it sees the word 'apple' it'll stop. and area search continue to continue if that apple isn't the one you are looking for?

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Area Search Function

Post by SlySven »

There have been improvements in the Lua getRoomUserData(roomId, key) command in the 3.0.0 previews IIRC, you should also find available a getRoomUserDataKeys() command which, if given a room number will let you find out all the "keys" that you can use to get the data with the first command. Also introduced around the same time was a searchRoomUserData() command which has two forms:
searchRoomUserData(key, value) - look through all room ids for a given user data "key" for the "value" and return a lua "array" of roomids (sort) matching those.
searchRoomUserData(key) - returns a sorted lua "array" of the unique string "values" found against that "key".

Note that these both are linear searches through the whole room collection, there is not anything to limit the results for a single area - so it might be better to just use them once at the start of a session and store a list of rooms you are interested in locally (keep a local index?) in your script and to update that at the same time you add or remove room user data...

Also, introduced was a clearRoomUserDataItem(roomID, key) command to remove the data stored against the specific "key" (and the "key" itelf) - before that was included you could only clear ALL the room user data items or set the specified item to an empty string. The former was problematic because there was no way to find out if there was any other data stored in that room so that you could save it if needed (say data that was needed for an installed package) and the latter was a pain because you would have to examine each and every room to see if it returned anything for a particular key (assuming you knew what to use) and then check the value to see if anything was stored.

This does mean that you can use a specifically named "key" as a "flag" (with no "value") without worrying about the data that is stored against it...! :)

ibaal
Posts: 1
Joined: Mon Jun 13, 2016 10:17 am

Re: Area Search Function

Post by ibaal »

I thought searchRoomUserData(key, value) was supposed to somehow return room ID's...
Code: [show] | [select all] lua
setRoomUserData(2, "mdomain", "islands")
local data = getRoomUserData(2, "mdomain")
local searchData = searchRoomUserData("mdomain", "islands")
display(data)
display(searchData)

--outputs

"islands"

{
  [243] = "islands"
}
I have no idea what 243 means...

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Area Search Function

Post by SlySven »

243 is supposed to be a room id that has a user data item (or "key") "mdomain" with the "value" of "islands" - I wonder if I've balls-ed something up recently in searchRoomUserData(...); so which "version" is this from as that sort of second output item is what I would have expected from:
Code: [show] | [select all] lua
setRoomUserData(243, "mdomain", "islands")
local data = getRoomUserData(243, "mdomain")
local searchData = searchRoomUserData("mdomain")
display(data)
display(searchData)
Why you are only getting 243 in the second case and NOT an entry for 2 AND that you are getting both a room id AND the value rather than just a list of room ids (containing perhaps both 2 and 243) is not clear - I will have to go and check what the current code is doing. Are you certain that you have not set a value in room 243 rather than, or as well as, in 2?

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Area Search Function

Post by SlySven »

Humm, reviewing the code base reveals I did make a mistake in the 2 argument searchRoomUserData( key, value ) case - have raised Pull Requests 313 and 314 to fix things in development and release_30 preview versions on the GitHub repository respectively...

Post Reply