Problems with tempTimer()

Post Reply
jakykong
Posts: 9
Joined: Fri Jun 01, 2012 5:43 am

Problems with tempTimer()

Post by jakykong »

Hello,

I am creating a (hopefully) simple semi-autowalk script for Achaea. When I'm already familiar with an area, and just want to quickly go from point A to point B, entering a series of commands is nice. So far, my alias executes my series of movement commands precisely, in a for loop.

I'm running into a snag while trying to ensure that doors are handled properly. Rather, I don't want doors to be handled at all - I want the path to terminate if a door is in the way. If the path continues after it fails to move because of a door, I end up in the wrong place. If there is a door, I don't want it to open automatically. If I did, I would have put "open door" in my path.

What I would like to do is run my script with a pause after moving, which allows the MUD to catch up to me and allows a trigger to set a variable if it finds a door, then at the end of my script reset the variable so paths will work next time. So, C's sleep() or #wait in Nexus.

Here's the crux of the problem: tempTimer(sec,script) executes a script after a set number of seconds, completely independently of the rest of the script. It won't pause my script. tempTimer() is great for some things, but not great for what I'm trying to do.

What is the normal way to handle this kind of thing? Has anyone else had a similar issue?

One solution I did come up with was this:
Code: [show] | [select all] lua
timerDone = false
tempTimer(0.5, [[timerDone = true]]
while timerDone == false do uselessVar = true end
timerDone = false
This does wait a half a second, doing nothing else. It's taking advantage of the global scope of variables.

It's also incredibly inefficient, because the script continues to run even when we are intentionally doing nothing. It polls the timer variable until the tempTimer has executed (thus setting the variable), and just because Lua won't let you have an empty block, we even needed to assign a pointless variable to waste cycles.

I was hoping to find a much more efficient method than this. The best one, by far, would be a simple wait method that doesn't allow further execution until the time is up.

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: Problems with tempTimer()

Post by chris »

Make a function which handles your movements, like doMove(), have the timer call that script every x seconds.

jakykong
Posts: 9
Joined: Fri Jun 01, 2012 5:43 am

Re: Problems with tempTimer()

Post by jakykong »

That makes a lot of sense. I hadn't thought of that, I guess I was thinking about what I could do with just the alias inline script.

User avatar
Omni
Posts: 131
Joined: Fri Feb 12, 2010 10:26 am

Re: Problems with tempTimer()

Post by Omni »

There is a speedwalk function built into mudlet, though can't recall if you can pause it or not

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Problems with tempTimer()

Post by Vadi »

The said speedwalk function does accept delays: http://wiki.mudlet.org/w/Manual:Mapper_ ... #speedwalk

jakykong
Posts: 9
Joined: Fri Jun 01, 2012 5:43 am

Re: Problems with tempTimer()

Post by jakykong »

I tried (and didn't really care much for) the speedwalk function. But the offered solutions have been helpful. I am using a table as a queue now, and if I spot a door or movement falis for some other reason that I spot, I just empty the queue.

Thanks for the ideas, they have been very helpful!

Post Reply