Hotspot problem - stack overflow

Posted by Mendacitas on Thu 05 Aug 2010 02:34 PM — 21 posts, 81,089 views.

#0

atkwin = "knightattacks"
dslcolor = "silver"

function knightAI:attackwindow()
WindowCreate (atkwin, 640, 325, 175, 200, 6, 2, ColourNameToRGB("black"))
WindowShow (atkwin, true)
WindowFont (atkwin, "a","Trebuchet MS", 12, true, false, false, false)
WindowText (atkwin, "f","Attacks:", 4, 0, 0, 0, ColourNameToRGB ("lightgreen"), false)
WindowText (atkwin, "a","DSL", 4, 13, 0, 0, ColourNameToRGB (dslcolor), false)
WindowText (atkwin, "a","SSL", 6.5, 30, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","IMPALE", 4, 47, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","HELLSIGHT/ARC", 40, 13, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","DISEMBOWEL", 40, 30, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "f", "Spells:", 5, 67, 0, 0, ColourNameToRGB ("lightgreen"), false)
WindowText (atkwin, "a","ENGAGE", 4, 80, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","PIETY", 75, 80, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","HEAL", 4, 97, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","REVIT", 55, 97, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","DEMONS", 4, 114, 0, 0, ColourNameToRGB ("silver"), false)
WindowAddHotspot(atkwin, "dsl", 3, 12, 25, 12, "", "", "", "", knightAI:modatk("dsl"), "", 1, 0)

end

function knightAI:modatk(newhit)
if (newhit == "dsl") then
atk = "dsl"
dslcolor = "red"
end
knightAI:attackwindow()
end

I'm working on an automated offense for my Paladin in Aetolia, I want to be able to click on "DSL" in the window defined above, have it change my variable which sets which attack I use to "dsl" and change the colour of the text to red. When I call the function knightAI:attackwindow() with an alias I've created to test however, MUSHClient lags for like 30s and then outputs the following error:

Run-time error
World: AMTS
Immediate execution
.\knightAI.lua:231: stack overflow
stack traceback:
.\knightAI.lua:231: in function 'modatk'
.\knightAI.lua:222: in function 'attackwindow'
.\knightAI.lua:231: in function 'modatk'
.\knightAI.lua:222: in function 'attackwindow'
.\knightAI.lua:231: in function 'modatk'
.\knightAI.lua:222: in function 'attackwindow'
.\knightAI.lua:231: in function 'modatk'
.\knightAI.lua:222: in function 'attackwindow'
.\knightAI.lua:231: in function 'modatk'
.\knightAI.lua:222: in function 'attackwindow'
.\knightAI.lua:231: in function 'modatk'
...
.\knightAI.lua:222: in function 'attackwindow'
.\knightAI.lua:231: in function 'modatk'
.\knightAI.lua:222: in function 'attackwindow'
.\knightAI.lua:231: in function 'modatk'
.\knightAI.lua:222: in function 'attackwindow'
.\knightAI.lua:231: in function 'modatk'
.\knightAI.lua:222: in function 'attackwindow'
.\knightAI.lua:231: in function 'modatk'
.\knightAI.lua:222: in function 'attackwindow'
[string "Alias: "]:1: in main chunk

here's the alias:


<aliases>
<alias
match="^testme1$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>knightAI:attackwindow()</send>
</alias>
</aliases>
#1
Your modatk function calls attackwindow and attackwindow calls modatk when adding the hotspot, thus the infinite loop causing the stack overflow. What you probably want is to wrap the hotspot's modatk call in an anonymous function or alias.
#2
I removed the thing causing the loop, now I have this:

atkwin = "knightattacks"
dslcolor = "silver"

function knightAI:attackwindow()
WindowCreate (atkwin, 640, 325, 175, 200, 6, 2, ColourNameToRGB("black"))
WindowShow (atkwin, true)
WindowFont (atkwin, "a","Trebuchet MS", 12, true, false, false, false)
WindowText (atkwin, "f","Attacks:", 4, 0, 0, 0, ColourNameToRGB ("lightgreen"), false)
WindowText (atkwin, "a","DSL", 4, 13, 0, 0, ColourNameToRGB (dslcolor), false)
WindowText (atkwin, "a","SSL", 6.5, 30, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","IMPALE", 4, 47, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","HELLSIGHT/ARC", 40, 13, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","DISEMBOWEL", 40, 30, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "f", "Spells:", 5, 67, 0, 0, ColourNameToRGB ("lightgreen"), false)
WindowText (atkwin, "a","ENGAGE", 4, 80, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","PIETY", 75, 80, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","HEAL", 4, 97, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","REVIT", 55, 97, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","DEMONS", 4, 114, 0, 0, ColourNameToRGB ("silver"), false)
WindowAddHotspot(atkwin, "dsl", 3, 12, 25, 12, "", "", "", "", knightAI:modatk(), "", 1, 0)

end

function knightAI:modatk()
atk = "dsl"
dslcolor = "red"
end

when I tried that, I got an error saying 'bad argument #11, string required', so I changed it to


WindowAddHotspot(atkwin, "dsl", 3, 12, 25, 12, "", "", "", "", "knightAI:modatk()", "", 1, 0)

But nothing happens when I redraw the window with my 'testme1' alias posted above after clicking in the hotspot, the text should be turning red.
#3
Just realised I was running v3.77 ha. Update to the latest version. So now I'm seeing the text "DSL" change to red when I redraw the window, but without clicking in the hotspot.
Australia Forum Administrator #4
Mendacitas said:

WindowAddHotspot(atkwin, "dsl", 3, 12, 25, 12, "", "", "", "", "knightAI:modatk()", "", 1, 0)


You are supposed to pass the name of a function. "knightAI:modatk()" is not the name of a function (it has brackets). Try "knightAI:modatk" (including the quotes).

[EDIT] However, see next post.

Before when you had:


WindowAddHotspot(atkwin, "dsl", 3, 12, 25, 12, "", "", "", "", knightAI:modatk(), "", 1, 0)


That was *calling* the function. Nor will this work:



WindowAddHotspot(atkwin, "dsl", 3, 12, 25, 12, "", "", "", "", knightAI:modatk, "", 1, 0)


That is the function but not the name of a function.
Amended on Thu 05 Aug 2010 09:46 PM by Nick Gammon
Australia Forum Administrator #5
In fact I would change the ":" to ".".

MUSHclient looks up the function name in the environment table, and finds nested functions at the periods. The ":" notation is for a slightly different case (where you want the table to be passed as the self parameter), but this won't work.
USA #6
Nick Gammon said:


WindowAddHotspot(atkwin, "dsl", 3, 12, 25, 12, "", "", "", "", knightAI:modatk, "", 1, 0)

That is the function but not the name of a function.

It's in fact invalid, the : syntax can only be used when calling a function.
Australia Forum Administrator #7
I've amended the documentation to make it clearer you pass the name of a function, not a function.
Australia Forum Administrator #8
Just to clarify the difference:


print ("math.abs")     --> "math.abs"    (the name of the function)

print (math.abs)       --> function: 01FDC8C8  (the function itself)

print (math.abs (-1))  --> 1   (the result of calling the function)

#9
I changed the hotspot syntax to pass the name of the function, and simplified the function so I could test only the hotspot. Still when I click on the hotspot nothing happens. I wondered if I'd placed the hotspot improperly so I made a rectangle with the same dimensions in the window. Found that I'd made a tiny line for a hotspot. So I worked out the dimensions I wanted with the rectangle, then rewrote the hotspot to fit it. Still, nothing happening when I click inside the rectangle/hotspot.


atkwin = "knightattacks"
dslcolor = "silver"

function knightAI:attackwindow()
WindowCreate (atkwin, 640, 325, 175, 200, 6, 2, ColourNameToRGB("black"))
WindowShow (atkwin, true)
WindowFont (atkwin, "a","Trebuchet MS", 12, true, false, false, false)
WindowFont (atkwin, "f","Trebuchet MS", 10, true, false, false, false)
WindowText (atkwin, "f","Attacks:", 4, 0, 0, 0, ColourNameToRGB ("lightgreen"), false)
WindowText (atkwin, "a","DSL", 4, 13, 0, 0, ColourNameToRGB (dslcolor), false)
WindowText (atkwin, "a","SSL", 6.5, 30, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","IMPALE", 4, 47, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","HELLSIGHT/ARC", 40, 13, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","DISEMBOWEL", 40, 30, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "f", "Spells:", 5, 67, 0, 0, ColourNameToRGB ("lightgreen"), false)
WindowText (atkwin, "a","ENGAGE", 4, 80, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","PIETY", 75, 80, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","HEAL", 4, 97, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","REVIT", 55, 97, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","DEMONS", 4, 114, 0, 0, ColourNameToRGB ("silver"), false)
WindowRectOp(atkwin, 1, 3, 15, 32, 32, ColourNameToRGB("blue"))
WindowAddHotspot(atkwin, "dsl", 3, 15, 32, 32, "", "", "", "", "knightAI.modatk", "", 1, 0)

end



function knightAI:modatk()
Note("hotspot working")
end
#10

atkwin = "knightattacks"
dslcolor = "silver"

function knightAI:attackwindow()
WindowCreate (atkwin, 640, 325, 175, 200, 6, 2, ColourNameToRGB("black"))
WindowShow (atkwin, true)
WindowFont (atkwin, "a","Trebuchet MS", 12, true, false, false, false)
WindowFont (atkwin, "f","Trebuchet MS", 10, true, false, false, false)
WindowText (atkwin, "f","Attacks:", 4, 0, 0, 0, ColourNameToRGB ("lightgreen"), false)
WindowText (atkwin, "a","DSL", 4, 13, 0, 0, ColourNameToRGB (dslcolor), false)
WindowText (atkwin, "a","SSL", 6.5, 30, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","IMPALE", 4, 47, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","HELLSIGHT/ARC", 40, 13, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","DISEMBOWEL", 40, 30, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "f", "Spells:", 5, 67, 0, 0, ColourNameToRGB ("lightgreen"), false)
WindowText (atkwin, "a","ENGAGE", 4, 80, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","PIETY", 75, 80, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","HEAL", 4, 97, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","REVIT", 55, 97, 0, 0, ColourNameToRGB ("silver"), false)
WindowText (atkwin, "a","DEMONS", 4, 114, 0, 0, ColourNameToRGB ("silver"), false)
WindowRectOp(atkwin, 1, 3, 15, 32, 32, ColourNameToRGB("blue"))
WindowAddHotspot(atkwin, "dsl", 3, 15, 32, 32, "", "", "", "", "knightAI.modatk", "", 1, 0)

end



function knightAI:modatk()
Note("hotspot working")
end
Netherlands #11
Been talking to Mendacitas on AIM, and the issue was that he wasn't doing it in a plugin, getting 30035 as the WindowAddHotspot error code.
USA #12
Worstje said:

Been talking to Mendacitas on AIM, and the issue was that he wasn't doing it in a plugin, getting 30035 as the WindowAddHotspot error code.


Wasn't that changed? I swear that was changed. =/
#13
Yeah, I was 99% sure that we could do hotspots without plugins for the last few versions, but I haven't tried them yet myself.
Australia Forum Administrator #14
Depends which version he is using I guess. That functionality was added in version 4.46, the "official" version of MUSHclient on the Downloads page is 4.43.

Two things would help here:

  • If you are having problems with stuff like miniwindows not behaving as you think they should, add "check ( ... )" around function calls.

    For example:

    
    check (  WindowRectOp(atkwin, 1, 3, 15, 32, 32, ColourNameToRGB("blue")) )
    


    That at least confirms the window exists, the arguments are in range, etc.
  • Advise which version of MUSHclient you are using


He still would have got errors or mis-behaviour about things like passing a function rather than a function name, so upgrading to the latest version is not the only issue.

USA #15
It would be nice to at least provide a link to the latest "beta" version announcement topic on the front page.
Australia Forum Administrator #16
On the Downloads page just in front of the link to download the file is this announcement:


Want the very latest version?

The version shown on this page is considered the latest stable version. That is, it has been released for a while with no major bugs reported. However often more recent versions are available on the MUSHclient Announcements part of the Forum. Follow that link to see if there is a more recent version announced. Look for a thread with a heading like "Version 4.xx released".


Can't do much more than that.
Amended on Fri 06 Aug 2010 09:56 PM by Nick Gammon
Australia Forum Administrator #17
Also on the "main" (top) page of this forum for MUSHclient (http://www.gammon.com.au/scripts/forum.php?bbsection_id=1) is always a link to the latest version. Right now it says:


Version 4.55 of MUSHclient now released.

USA #18
Ah, I see. It's not very obvious :( I've had a lot of people not know that there's a newer version. Maybe putting <a href="http://www.gammon.com.au/forum/?id=10458">;(Beta: 4.55)</a> in the heading in both places would make it more obvious.

Very few of the usual users I see visit the forums, so the forums notice misses a lot of people too.

[EDIT] An email newsletter every time a version is released sure would be nice, IMO. Just a thought :D
Amended on Fri 06 Aug 2010 10:17 PM by Twisol
#19
I am on 4.43
Australia Forum Administrator #20
Apart from all the other issues I mentioned, like giving the function name, in quotes, without the brackets, and without the ":" symbol, I would upgrade:

http://www.gammon.com.au/forum/?id=10481