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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ AutoIt for scripting
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
| Posted by
| Eloni
(28 posts) Bio
|
| Date
| Reply #15 on Fri 03 Dec 2010 07:59 AM (UTC) |
| Message
| I think I understand the bit about the scope of the function. I probably understand enough to implement it.
As for the link:
http://www.gammon.com.au/forum/?id=4957
I think this is the same link I linked as my source. I wouldn't be able to make the wait function work without Nick's specific example (that he included on this thread)--because I have little idea what the code on the other thread means, and the vocabulary used to describe it was beyond my understanding.
Not to say I won't be try to google definitions, read the chapter on coroutines again and try my best to experiment with the code from the other thread.
Thanks for the all the help guys ;) | | Top |
|
| Posted by
| Eloni
(28 posts) Bio
|
| Date
| Reply #16 on Sat 04 Dec 2010 06:36 PM (UTC) Amended on Sat 04 Dec 2010 06:38 PM (UTC) by Eloni
|
| Message
| Nick said that perhaps a coroutine could work in my case, but I couldn't really make sense of them based on what I read. I understand that I can yield the coroutine, but I don't know of any timers I can use to make the coroutine resume after a set period.
Speaking of timers, I attempted to use LuaAddTimer to create the same timer I made using the MushClient GUI, but I received an error message. It seemed the large multiline piece of code was the problem. The timer looked something like this:
LuaAddTimer { name = "mytimer",
minute = 5,
second = 3,
send "A GIGANTIC
MULTI LINE
PIECE OF CODE"
}
I'd like to know how to make timers in my lua document so that I can use LUA to recreate them with new (random) times after every execution. So the send would look something like:
send " doSomething
doSomethingElse
timerTime = math.random(5)
LuaAddTimer { name="mytimer"
minute = 0
second = timerTime
--etc
}
Here's my confused attempt at making a coroutine accomplish what I want.
--coroutine made to yield
function newRegen()
--a trigger makes fighting = true if it maches something from combat
if fighting == true then
coroutine.resume(theCoroutineThatChecksIfINeedToSleepOrFight)
else
function timer(10)
coroutine.resume(theCoroutineThatChecksIfINeedToSleepOrFight)
--somehow make a timer that makes above fire after 10 seconds
--AKA a timer function is something I don't know how to create :(
end
end
end
Here's another attempt at making it work with 'wait'.
wait.make (function ()
Send ("sleep")
ifCombatStarts = wait.match (fighting, 10)
--I don't know if 10 is part of a 'sendto'
--'12' sends to script
--or if 10 stands for 10 seconds? <<this might be a stretch
if ifCombatStarts == true then
print ("IFCOMBATSTARTS = TRUE, REACTING NOW BY STANDING")
Send ("stand")
else
wait.time (10) --assuming I was right about the above
print("Time Has Elapsed, TIME TO WAKE UP")
Send ("wake")
end
end)
Also I didn't expect my code to work anyway so I never tested it. However when I tried to compile something earlier I received this message. Don't know if it's something I need to worry about:
Run-time error
World: Alter Aeon
Immediate execution
C:\Program Files\MUSHclient\lua\wait.lua:159: Timers not enabled
stack traceback:
[C]: in function 'assert'
C:\Program Files\MUSHclient\lua\wait.lua:159: in function 'make'
[string "Script file"]:100: in main chunk
| | Top |
|
| Posted by
| Eloni
(28 posts) Bio
|
| Date
| Reply #17 on Sat 04 Dec 2010 06:41 PM (UTC) |
| Message
| I just realized my attempt at a coroutine makes even less sense now since the 'if check' for 'fighting' would only be called after the coroutine that checks if I was fighting has yielded.
:'( I'll be spending more time trying to understand this. | | Top |
|
| Posted by
| Twisol
USA (2,257 posts) Bio
|
| Date
| Reply #18 on Sat 04 Dec 2010 07:11 PM (UTC) Amended on Sat 04 Dec 2010 07:13 PM (UTC) by Twisol
|
| Message
|
Eloni said: Nick said that perhaps a coroutine could work in my case, but I couldn't really make sense of them based on what I read. I understand that I can yield the coroutine, but I don't know of any timers I can use to make the coroutine resume after a set period.
Go into the Timers menu (Game -> Configure -> Timers) and click Add. You can configure a timer from there. Of course, for transient timers like what you'd use for a coroutine, creating a timer from your script is probably better (like you tried below).
Eloni said:Speaking of timers, I attempted to use LuaAddTimer to create the same timer I made using the MushClient GUI, but I received an error message. It seemed the large multiline piece of code was the problem. The timer looked something like this:
LuaAddTimer { name = "mytimer",
minute = 5,
second = 3,
send "A GIGANTIC
MULTI LINE
PIECE OF CODE"
}
"" and '' quoted strings are single-line (unless you add a single \ at the end of the line, which tells Lua to treat the next line as part of the string too). What you want here are Lua's multi-line string, delimited by [[ and ]].
Also, don't forget the '=' after 'send'. You're passing in keys and values to a function, not calling code (yet).
Eloni said:I'd like to know how to make timers in my lua document so that I can use LUA to recreate them with new (random) times after every execution. So the send would look something like:
send " doSomething
doSomethingElse
timerTime = math.random(5)
LuaAddTimer { name="mytimer"
minute = 0
second = timerTime
--etc
}
Tricksy! There are a couple ways to do this, but the easiest by far is just to give your timer a label and use SetTimerOption to reconfigure what you want. That way you don't have to go through the pain of defining a timer that creates a timer that creates a timer, ad infinitum... ;)
Eloni said:--somehow make a timer that makes above fire after 10 seconds
--AKA a timer function is something I don't know how to create :(
Go to Help -> Function list and type "Timer" into the filter box. Double-click on any of the functions in the list to view the documentation.
Eloni said:--I don't know if 10 is part of a 'sendto'
--'12' sends to script
--or if 10 stands for 10 seconds? <<this might be a stretch
The only purpose of wait.match() is to wait for some text to match, then resume the coroutine. There's no "send to" setting involved, unless wait.match() puts "coroutine.resume(whatever_it_is)" in the Send field, in which case it would be 12 (but that's only relevant for the immediate contents of the Send field of that particular trigger).
Indeed, if you go here [1] and scroll down, you'll see that the second parameter to wait.match() is a timeout period. If the given text isn't received in that amount of time it'll yield to the coroutine again. Timeout can be nil, in which case it'll only resume if the text comes in.
Eloni said:Also I didn't expect my code to work anyway so I never tested it. However when I tried to compile something earlier I received this message. Don't know if it's something I need to worry about:
Run-time error
World: Alter Aeon
Immediate execution
C:\Program Files\MUSHclient\lua\wait.lua:159: Timers not enabled
stack traceback:
[C]: in function 'assert'
C:\Program Files\MUSHclient\lua\wait.lua:159: in function 'make'
[string "Script file"]:100: in main chunk
Sure is: Go to Game -> Configure -> Timers and make sure the "Enable timers" checkbox is checked. Otherwise none of your timers - nor the wait library, since it uses timers - will work at all.
Eloni said: I just realized my attempt at a coroutine makes even less sense now since the 'if check' for 'fighting' would only be called after the coroutine that checks if I was fighting has yielded.
:'( I'll be spending more time trying to understand this.
I'm impressed that you're thinking so actively about this. :) You're doing better than what 90% of people would do just because of that.
[1] http://www.gammon.com.au/forum/?id=8608 |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | | Top |
|
| Posted by
| Eloni
(28 posts) Bio
|
| Date
| Reply #19 on Sat 04 Dec 2010 07:33 PM (UTC) |
| Message
|
*facepalm*
So that's how you search the help files... I feel like a whole new world of options is open to me now.
Thanks a lot for the reply! I'm still trying to soak it all in and make changes. It might take a while : ) | | Top |
|
| Posted by
| Eloni
(28 posts) Bio
|
| Date
| Reply #20 on Sat 04 Dec 2010 08:41 PM (UTC) |
| Message
| Well after fooling with AddTimer, addxml.timer, and LuaAddTimer for an hour or so I finally got one to do what I wanted it to.
Here's the code, except it doesn't work as I would expect it to.
First, the timer never starts with a second value of 2, even if I put two in "". (second = "2")
Second, SetTimerOption doesn't work as expected. It does the same thing whether I use randomTen, or math.random(10). Instead of picking a random number between 1-10 it seems to pick 1 or .1 over and over, making the timer repeat 'print "TIMER WORKS"'. Also, if I inspect the timer in the GUI it has a 0 in seconds, instead of a 1. This seems significant because if you try to save a timer with "0" in all the time fields it wont' allow you. This might mean that instead of picking .1 or 1 it picks something other value that it can get away with.
LuaAddTimer { name = "cows",
second = 2,
send_to = "12",
send = [[
print "TIMER WORKS"
randomTen = math.random(10)
SetTimerOption ("cows", "second", "math.random(10)")
]]
}
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,169 posts) Bio
Forum Administrator |
| Date
| Reply #21 on Sat 04 Dec 2010 09:05 PM (UTC) |
| Message
| What are you doing here? You are making a timer, that once it fires changes its own time interval to some other interval?
This won't work for a start:
SetTimerOption ("cows", "second", "math.random(10)")
Try doing this in the command window and you'll see what I mean:
/print ("math.random(10)") --> math.random(10)
Then try:
/print (math.random(10)) --> 6
Try something like:
LuaAddTimer { name = "cows",
second = math.random (10),
send_to = "12",
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,169 posts) Bio
Forum Administrator |
| Date
| Reply #22 on Sat 04 Dec 2010 09:16 PM (UTC) |
| Message
| As for the coroutines, I think you want to move away from "how do I pause a script?" and more towards "how do I solve my problem of healing myself after 10 seconds?".
Think more in terms of incoming events. Mainly these would be:
- Some time elapses (use a timer for this)
- Something happens on the MUD (use a trigger for this)
- You, the player, want to do something (use an alias for this)
So, say for example your health is low and you are poisoned, but you can only do one cure at a time. One approach might be:
Send "cure light wounds"
DoAfter (10, "cure poison") -- 10 seconds later, cure poison
But maybe after 5 seconds you are in a fight and you can't cure the poison. Well instead of DoAfter, which is basically a simple way of adding a timer, you can add a named timer (like what you were doing). And then if you find yourself in a fight, just delete it with DeleteTimer, and add another one later on when you are ready.
Eloni said:
I'd like to know how to make timers in my lua document so that I can use LUA to recreate them with new (random) times after every execution.
It's Lua by the way, not LUA.
Lua is not an acroynym, it is the name of something. For example, your name is not ELONI, right?
Do you really need to recreate themselves? Why not just have one timer create another one, with a different time? That might be simpler.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Twisol
USA (2,257 posts) Bio
|
| Date
| Reply #23 on Sat 04 Dec 2010 10:28 PM (UTC) |
| Message
|
Nick Gammon said: Lua is not an acroynym, it is the name of something. For example, your name is not ELONI, right?
Lua is Portuguese for Moon. Thought I'd throw that in there. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | | Top |
|
| Posted by
| Eloni
(28 posts) Bio
|
| Date
| Reply #24 on Sun 05 Dec 2010 12:44 AM (UTC) |
| Message
| I do appreciate you guys correcting my poor vocabulary. I would hate to sound like a dolt for the rest of my life, and I'm positive it will help me understand everyone else.
Also, thanks for the explanations Nick! Now that I think about it, adding and deleting timers is a genius way to handle my wait/coroutine problem. I don't know what it is exactly, but it's like something clicked... It's a much better solution than what I had in mind and I had to make only a few (easier) changes to my code to implement it.
I've made more useful working pieces of code today than ever before thanks to you all's help. Thanks again!
No more questions for now. Surprising right? ;) | | Top |
|
| Posted by
| Eloni
(28 posts) Bio
|
| Date
| Reply #25 on Sun 05 Dec 2010 11:21 AM (UTC) Amended on Sun 05 Dec 2010 11:23 AM (UTC) by Eloni
|
| Message
| So now I'm trying to make a system for movement. I seem to be getting some type of scope error, but I can't figure out what's wrong.
Here are the methods in question:
Immediate execution
[string "Timer: pathTimer"]:5: attempt to index global 'currentPath' (a nil value)
stack traceback:
[string "Timer: pathTimer"]:5: in main chunk
If check to see that conditions are ideal for moving
...
elseif ready == true and fighting == false and timeToMove == true then
timeToMove = false
pickRandomPath()
onAPath = true
newMoveIdea()
...
Pick a random path.
function pickRandomPath () --Picks a random area
-- to go to when the method is called and sets it to currentPath
currentPath = listOfPaths[math.random (3)]
currentPathLocation = 1 -- STARTS CHOSEN PATH OFF AT 1
print ("Current destination: ")
print ("currentPath") --I should also note here that I'm trying to print the
--the name of the array. Neither "currentPath" nor
--currentPath work
end -- pickRandomPath
Move on that path until it's complete. This contains the timer where the area occurs.
function newMoveIdea()
if moveQued == false then
moveQued = true
LuaAddTimer { name = "pathTimer",
enabled = "y",
one_shot = "y",
second = math.random(1,3),
send_to = "12",
send = [[
print "using newMoveIdea()"
--a separate trigger will backstep if you try to move while in combat
--or while out of move
if currentPath[currentPathLocation] == nil then
Send (ColourNote("white", "red", "Area path completed. what now?"))
--switchToAreaPath() --method not made yet, it will be the same as
--newMoveIdea() except when currentPath[currentPathLocation] == nil
-- it will set onAPath == false (so it can cast recall)
elseif onAPath == true then
Send ("currentPath[currentPathLocation]")
currentPathLocation = currentPathLocation + 1
moveQued = false
end
]]
}
end --if moveQued
end --newMoveIdea()
| | Top |
|
| Posted by
| Eloni
(28 posts) Bio
|
| Date
| Reply #26 on Sun 05 Dec 2010 06:46 PM (UTC) |
| Message
| After playing with the timers a bit I came up with a few good ideas as to how to use them. I'm proud to announce that I've made my first seemingly intelligent exp-getter-script :D
Thanks a lot for the help guys. I wouldn't have been able to do it without you. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,169 posts) Bio
Forum Administrator |
| Date
| Reply #27 on Sun 05 Dec 2010 10:57 PM (UTC) |
| Message
|
Eloni said:
This contains the timer where the area occurs.
You haven't said what the error is, so it's kind of hard to help.
Anyway, you may want to look up some code tidy-ups. Using the addxml.timer (which ships with MUSHclient, it isn't clear if you are using that) you can now use "true" and "false" for flags, see example below. Also use sendto.script instead of "12" for better documentation.
I'm not sure about this:
Send ("currentPath[currentPathLocation]")
Do you really mean to quote that? It will just literally send those words.
You also don't really need to do this:
Boolean values like true and false can just be tested, eg.
This is my cleaned-up version. I don't promise it will do what you want, but it illustrates how you can make the code clearer:
require "addxml"
addxml.timer {
name = "pathTimer",
enabled = true,
one_shot = true,
second = math.random(1,3),
send_to = sendto.script,
send = [[
print "using newMoveIdea()"
--a separate trigger will backstep if you try to move while in combat
--or while out of move
if currentPath[currentPathLocation] == nil then
Send (ColourNote("white", "red", "Area path completed. what now?"))
elseif onAPath then
Send (currentPath[currentPathLocation])
currentPathLocation = currentPathLocation + 1
moveQued = false
end
]]
}
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | 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.
111,523 views.
This is page 2, subject is 2 pages long:
1
2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top