Mudlet Timing Conundrum

MelaliMelali Member Posts: 245 Capable
edited March 2016 in Mechanic's Corner
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

  • SynkarinSynkarin Nothing to see here Member Posts: 3,216 Transcendent
    If you really just want one function - you can try your hand at coroutines in lua

    You can also use the event system to automatically run a script when the gmcp.Char.Items.room is returned. 

    Out of curiosity - why aren't you taking advantage of the Add/Remove gmcp messages to gather your takeable stuff? 

    Everiine said:
    "'Cause the fighting don't stop till I walk in."
    -Synkarin's Lament.
  • MelaliMelali Member Posts: 245 Capable
    I'll look into coroutines!

    As for the event system, I don't particularly want to try and get things everytime I enter a room, which is when gmcp.Char.Items.List is returned. Everytime I look/ql, to be exact. I suppose what I could do is have the alias I use set a variable, like taking, to true, and then fire the gmcp event. And then it would turn itself off afterwards.

    As for the Add/Remove gmcp messages, they only record what happens when I'm in the room. I've mostly been in the Newton caverns, but there's random stuff, like rivets, or junk, or corpses other people killed that's lying around. They don't appear on the Add/Remove lists. There's also the Update list. So, I thought it would be simpler to just run through one list of items.


Sign In or Register to comment.