Issue with miniwindows - function not found

Posted by AdInfinitum on Sun 29 Mar 2015 07:12 PM — 8 posts, 32,767 views.

#0
I got the core of this script from Nick's Vimeo Video about an inventory miniwindow. I managed to get it to work like I wanted, for the most part. Then I was stuck on adding a drag handler until I found a post that outlined it nicely with the WindowDragHandler function. Incorporating that worked, again, for the most part. When I attempt to move a window, it'll move, but then I get an error message saying "function dragmove not found" and that it's nil. I can't understand what is happening, and need some guidance/code correcting. Additionally, I'd like it to remember the position so it doesn't reset each time (which I understand may have to be put into a plugin, and no problems there).

Here is the code. **Disclaimer: Private clan information has been redacted, but the trigger portion works**

[EDIT]Code below is now defunct and should be ignored.

require 'wait'

function mousedown(flags, hotspot_id)
  startx, starty = WindowInfo (my_mini_win, 14), WindowInfo (my_mini_win, 15)
 end -- mousedown

function dragmove(flags, hotspot_id)
  local posx, posy = WindowInfo (my_mini_win, 17),
                     WindowInfo (my_mini_win, 18)
                                                        
  -- move the window to the new location
  WindowPosition(my_mini_win, posx - startx, posy - starty, 0, 2);
  
  -- change the mouse cursor shape appropriately
  if posx < 0 or posx > GetInfo (281) or
     posy < 0 or posy > GetInfo (280) then
    check (SetCursor ( 11))   -- X cursor
  else
    check (SetCursor ( 1))   -- hand cursor
  end -- if
  
end

function dragrelease(flags, hotspot_id)
return
end -- dragrelease

  wait.make(function ()

  local background_colour         = ColourNameToRGB "black"
  local border_colour             = ColourNameToRGB "dimgray"
  local default_text_colour       = ColourNameToRGB "white"
  local text_offset               = 4
  local border_width              = 1
  local line_spacing              = 1
  local font_name                 = "Dina"
  local font_size                 = 8
  local title                     = "Test Title"
  local font                      = "f"
  my_mini_win                     = "my_mini__" .. GetPluginID()

  if not WindowInfo(my_mini_win, 1) then
    WindowCreate (my_mini_win, 0, 0, 0, 0, 6, 0, 0)
    WindowFont (my_mini_win, font, "Dina", 8)
  end

  
  Send("command")

  -- wait for my_mini_ to start

  local x = wait.match("trigger matches fine", 10)

  if not x then
    ColourNote("white", "blue", "Nothing returned in 10 seconds.")
    return
  end 

  local my_mini_list = {}
  local max_width = WindowTextWidth(my_mini_win, font, title)

  -- loop until end

  while true do
    local line, wildcards, styles = wait.match("*")

    -- see if end

    if string.match(line,"trigger matches fine") then
      break
    end

    -- save my_mini_ 
    table.insert(my_mini_list, styles)
    -- work out max width
    max_width = math.max (max_width, WindowTextWidth (my_mini_win, font, line))

  end

  local font_height = WindowFontInfo(my_mini_win, font, 1)

  local window_width = max_width + 10
  local window_height = font_height * (#my_mini_list + 2) + 10

  -- make window correct size

WindowCreate (my_mini_win, 0, 0, window_width, window_height, 12, 0, background_colour)
WindowRectOp (my_mini_win, 5, 0, 0, 0, 0, 9, 15 + 0x1000)

WindowText (my_mini_win, font, title, 5, 5, 0, 0, ColourNameToRGB("yellow"))

  local y = font_height * 2 + 5

  for i, styles in ipairs(my_mini_list) do

    if styles[1] then
      local x = 5
      for _,style in ipairs (styles) do
        x = x + WindowText (my_mini_win, font, style.text, x, y, 0, 0, style.textcolour)
      end
      y = y + font_height
    end
  end
    
    WindowAddHotspot(my_mini_win, "hs1",
      10, 10, 60, 20,
      "",
      "",
      "mousedown",
      "",
      "",
      "Drag me!",
      1,0)

    WindowDragHandler(my_mini_win, "hs1", "dragmove", "dragrelease", 0)
    WindowSetZOrder(my_mini_win, 20)
    WindowShow(my_mini_win, true)
  
end)


Apologies for the off-kilter spacing - it looks perfectly fine in Sublime Text Editor. And thanks for any help!

[EDIT] You used tabs instead of spaces. I fixed it for you. - Nick
Amended on Sun 29 Mar 2015 09:00 PM by AdInfinitum
#1
So right after I posted this, I saw the problem; apparently it's supposed to be put inside a plugin.

Would putting into a plugin also solve the issue of remembering position?

Edit:

Apparently not. So, how do I remember the position for next time?
Amended on Sun 29 Mar 2015 08:09 PM by AdInfinitum
Australia Forum Administrator #2
Is this in a script file? Or is it all inside an alias?

It works once, you say, and then stops working?
Australia Forum Administrator #3
Perhaps post the entire plugin that demonstrates the issue.
#4
I originally had it as an alias, but I found a topic "dragmove is nil" in which it was stated it needed to be in a plugin, so that issue is fixed.

I've also found the movewindow information, so I'm attempting to incorporate that into the plugin, but I'm not entirely sure I'm doing it right, based on the example. For instance, in the example you provide with movewindow.lua, there's the WindowCreate function with WINDOW_WIDTH and WINDOW_HEIGHT, but nothing defining that - I'm assuming that I have to define those manually myself, so I just changed that to WINDOW_WIDTH or 0 and WINDOW_HEIGHT or 0.

I think the bane of all my issues is the lack of a more in-depth tutorial on miniwindows. I've seen the videos, I see the functions, but I'm more a kinetic learner, so hands on and reading/visual is what helps the most. But I can't find anything that goes step-by-step what to do, unfortunately, and looking at plugins that utilize miniwindows doesn't seem to help, either.

I know once I get this down, I'll have an easier time next time, though!
#5
Okay, so here's the plugin - It's working, though I'm wondering if this is the most efficient way to do this, or if I'm absolutely missing something. Any advice would be greatly appreciated!

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, March 29, 2015, 12:32 PM -->
<!-- MuClient version 4.96 -->
<!-- Plugin "list_mw" generated by Plugin Wizard -->
<muclient>
<plugin
  name="list_mw"
  author="AdInfinitum"
  id="e68357c2401dcaa1ec9953f6"
  language="Lua"
  purpose="Displays a miniwindow"
  save_state="y"
  date_written="2015-03-29 12:30:10"
  requires="4.96"
  version="1.0"
  >
</plugin>
<!--  Aliases  -->
<aliases>
 <alias
  match="^list$"
  enabled="y"
  regexp="y"
  send_to="12"
  sequence="100"
 >
 <send>wait.make(function ()

  local font = "f"
  local title = "list"
  local font_name = "Dina"
  local font_size = "8"
  local win = GetPluginID()
  
  -- send list

  Send "list"

  -- wait for list to start

  local x = wait.match("<matched>", 10) -- 10 is number of seconds to wait for match

  -- check to see if match made

  if not x then
    ColourNote("yellow", "red", "No list generated in 10 seconds.")
    return
  end

  local list = {}
  local max_width = WindowTextWidth(win, font, title) -- initiate max width

  -- loop until end of list

  while true do
    local line, wildcards, styles = wait.match("*")

    -- see if it's the end of list

    if string.match(line, "<matched>") then
      break
    end

    -- save line
    table.insert(list, styles)

    -- work out max width
    max_width = math.max (max_width, WindowTextWidth (win, font, line))

  end -- end loop

  local font_height = WindowFontInfo(win, font, 1)
  local window_width = max_width + 10
  local window_height = font_height * (#list + 1) + 10

  -- make window correct size

  WindowCreate (win,
              wininfo.window_left,
              wininfo.window_top,
              window_width,
              window_height,
              wininfo.window_mode,
              wininfo.window_flags,
              ColourNameToRGB "black"
              )

WindowFont (win, font, font_name, font_size)

WindowRectOp (win, 5, 0, 0, 0, 0, 9, 15 + 0x1000)

  WindowText (win, font, title, 5, 5, 0, 0, ColourNameToRGB "yellow")

  local y = font_height * 2 + 5

  for i, styles in ipairs(list) do

    if styles[1] then
      local x = 5
      for _,style in ipairs(styles) do
       x = x + WindowText(win, font, style.text, x, y, 0, 0, style.textcolour)
      end
      y = y + font_height
    end
  end

movewindow.add_drag_handler (win, 0, 0, 0, 0, 1)

WindowSetZOrder(win, 20)

movewindow.save_state (win)

WindowShow(win, true)

end)</send>
 </alias>
 </aliases>

<script>
<![CDATA[

function OnPluginInstall()

require 'movewindow'
require 'wait'

win = GetPluginID()

wininfo = movewindow.install (win, miniwin.pos_center_right, 0)

if not WindowInfo (win, 1) then
    WindowCreate (win,
              wininfo.window_left,
              wininfo.window_top,
              0,
              0,
              6,
              0,
              0
              )
  WindowFont (win, "f", "Dina", 8)
end

end
]]>
</script>
</muclient>
Australia Forum Administrator #6
I tend to move away from "send to script" for big projects, because the script is recompiled every time it (the alias) is called, whereas if you just set a script function that is compiled once.

I don't see anything amazingly bad about what you have done.

I try to document individual functions in the help file (and the miniwindow pages: http://gammon.com.au/mushclient/mw_intro.htm). Then there are various example pieces of code in the distribution, and also the example pages in this part of the forum.
#7
Yeah, I'm still relatively new to MUSHclient, though I've been using it for over a year now. It pales in comparison to the 13-14 years I spent with zMUD/CMUD, and I finally decided to make the change last April.

I've read through some of the tutorials, but I think I might need to go through them again, a bit more slowly this time. I'm absolutely in love with MUSHclient now, even if I haven't been able to actually port all my other scripts to MUSH yet. I had one script in CMUD that would display the actual weather in a small window - easy to do since CMUD offered multi-threading and didn't lock up the client when I datamined from URLs. But Fiendish has shown me the async module, which helped me with one of my projects.

Truth be told, I have plenty of miniwindow projects I want to bring back. A miniwindow for updated scores for NFL games (essentially a scoreboard, which I am learning I can do much more beautifully in MUSH), among other things, is on my list of things to conquer.

Thanks for the insight; as I mentioned, I'm going to go through the tutorials once again and see what I can make of it. I have a dummy MUSHclient window for sandboxing, and I'm glad I can come here when I run into issues. You've been a great help in the past, and it's nice to see an author a client be so involved!