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?
Area Search Function
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: Area Search Function
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...!
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...!
Re: Area Search Function
I thought searchRoomUserData(key, value) was supposed to somehow return room ID's...
I have no idea what 243 means...
- SlySven
- Posts: 1023
- Joined: Mon Mar 04, 2013 3:40 pm
- Location: Deepest Wiltshire, UK
- Discord: SlySven#2703
Re: Area Search Function
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:
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?