My question is that, can you script it in Mudlet such that you send a command to the game, and then don't do anything until the game registers it? Maybe some way to trigger on just the next gmcp event.
For example, I have this script that gets all the 'takeable' items in the current room. It works off gmcp.Char.Items.List, which I update with sendGMCP("Char.Items.Room"), and then sending a blank command. This does update the room, but if I have no delay, then the rest of the code runs off of the old Char.Items.List, which is whatever it was when I last looked at the room. As it is, it seems that there is always some variance in the time that the command takes to process. Of course, I could just put a large delay and hope for the best, but I would prefer to keep the delay as minimal as possible.
function getTakeableItems ()
sendGMCP([[Char.Items.Room]])
send("\n")
tempTimer(.2, function()
for key, value in pairs(gmcp.Char.Items.List.items) do
if string.find(gmcp.Char.Items.List.items[key].attrib, "t") then
send("get "..gmcp.Char.Items.List.items[key].id)
end
end
echo("\nGot Everything!\n")
end)
end
So, what I'm asking is, is there a simple, clean way within a single function for some code to fire, wait for an event and then the rest of the code to go? It's been suggested that it's possible using multiple functions, where you have one part that sets up the command and then activates a trigger, and then when the trigger goes, that calls another function, one that does the second part of whatever you need done.
Another possibility I can see is that there's some universal variable, like onPrompt, and then a trigger that makes onPrompt = true whenever a prompt comes, aka a command goes through. Thus, in the function, you would turn onPrompt false and then loop until onPrompt was true again, after which you would run the rest of the function. I haven't actually tried this, but maybe it would work?
EDIT: I just tried my second thought, and Mudlet just went unresponsive. That might be coincidence, but probably isn't.
Comments