Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ I must be doing something wrong

I must be doing something wrong

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Tcoffeep   Canada  (7 posts)  Bio
Date Sat 10 Jan 2009 07:26 AM (UTC)

Amended on Sat 10 Jan 2009 07:34 AM (UTC) by Tcoffeep

Message
Hello, I have been tinkering with lua for a little bit, and am still trying to get a grip on things. However, I can't seem to figure out why I keep making Mushclient crash whenever I run this function :


area = {"w", "w", "sw", "w", "w", "w", "s", "s", "sw", "s",
 "se", "s", "s", "se", "e", "ne", "e", "n", "n", "w", "w", "nw", "n", "ne", "e", "e", "s", "s", "se", "ne", "ne", 
"se", "se", "s", "s", "e", "e", "e", "e", "se", "e", "e", "ne", "ne", "n", "n", "ne", "ne", "n", "n", "nw", "nw", 
"s", "n", "nw", "nw", "w", "w", "s", "s", "s", "s", "se", "e", "s", "s", "sw", "s", "e", "se", "e", "e", "ne", "ne", 
"n", "n", "ne", "ne", "w", "n", "s", "e", "n", "n", "nw", "nw", "s", "n", "nw", "s", "ne", "sw", "s", "e", "e", "w", 
"w", "w", "n", "s",  "s", "n", "w", "n", "s", "s", "se", "e", "s", "n", "w", "sw", "ne", "nw", "n", "w", "w", "e", 
"e", "nw", "w", "sw", "w", "w", "e", "e", "ne", "e", "n", "ne", "e", "w", "sw", "s", "se", "sw", "w", "e", "sw", "w", 
"w", "w", "w", "n", "s", "s", "w", "n", "n", "w", "s", "s", "ne", "w", "w", "w", "nw", "n", "n", "ne", "n", "n", "nw", 
"nw", "w", "sw"}

function DoWalk ()
  if misc.name == "y" and stats.bal == "eb" and not mob.attack then
    for i=1,166 do
      CheckRoom()
      if mob.room then
        i = i + 1
        mob.room = false
        Send(area[i])
      else
       EnableTimer("basher", true)
      end
    end
  end
end

function CheckRoom ()
  mob.check = true
  Send("look")
  DoAfterSpecial (3, 'mob.check=false', sendto.script)
end


Where am I going wrong? Is it too large of a loop?
Top

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #1 on Sat 10 Jan 2009 07:30 AM (UTC)

Amended on Sat 10 Jan 2009 07:34 AM (UTC) by WillFa

Message
What's the error that you get?
Top

Posted by Tcoffeep   Canada  (7 posts)  Bio
Date Reply #2 on Sat 10 Jan 2009 07:31 AM (UTC)
Message
None.

I run the function, and it stops responding, and it doesn't do anything until I close it via CTRL-ALT-DELETE.

I tried tracing, but, as I've said, it crashes, and it stops responding.
Top

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #3 on Sat 10 Jan 2009 07:35 AM (UTC)
Message

The only thing I see right now is

Send(Area)

Should probably be
Send(Area[i])


Currently you're trying to send the entire table, which should get an error in the Send function (expected string, got table)

What does the CheckRoom() function do? Could you be getting in an infinite loop in there? Does CheckRoom call DoWalk which would also cause a loop... ?
Top

Posted by Tcoffeep   Canada  (7 posts)  Bio
Date Reply #4 on Sat 10 Jan 2009 07:37 AM (UTC)
Message
It just checks the room in case anyone else is in there.

It is, but the forums removed them because it probably was assumed to be code or something.

edit : i edited a few things because of some mistakes. still crashes, though.
Top

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #5 on Sat 10 Jan 2009 07:40 AM (UTC)

Amended on Sat 10 Jan 2009 07:50 AM (UTC) by WillFa

Message
Modifying i in the loop is 'undefined' behavior in Lua.


The way this is written, I don't think it'll do what you want... It looks like you're trying to write a stepper. The loop runs regardless, as fast as possible.

so you'll walk into a room, send look, and walk into the next room before the mu even sends output back.

To make a stepper, you'll need a little bit more complex code using a coroutine. Coroutines let you pause a loop or funtion, and then pick up where you left off.

Nick's wait.lua module shows how they can be used.

Basic logic of it would be:

f = coroutine.wrap(function ()
  if misc.name == "y" and stats.bal == "eb" and not mob.attack then
    for i=1,166 do
      CheckRoom()
      coroutine.yield()
      if mob.room then
        mob.room = false
        Send(area[i])
      else
       EnableTimer("basher", true)
      end
    end
  end
end )

Either your basher timer or prompt trigger would then call f() to resume, after the mud's gotten a chance to send you enough text to trigger on a mob being in the room.

Top

Posted by Tcoffeep   Canada  (7 posts)  Bio
Date Reply #6 on Sat 10 Jan 2009 07:42 AM (UTC)
Message
I'll try adding in


v = i

Send(area[v])


and see if that works?
Top

Posted by Tcoffeep   Canada  (7 posts)  Bio
Date Reply #7 on Sat 10 Jan 2009 07:47 AM (UTC)

Amended on Sat 10 Jan 2009 07:53 AM (UTC) by Tcoffeep

Message
I'll give it a shot. Thanks.

You were right. I have a lot to learn yet!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,636 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.