miniwindow startup issue

Posted by Herl on Fri 30 Jan 2015 01:58 PM — 8 posts, 29,128 views.

#0
So I made a miniwin plugin that works wonders.... if it's reinstalled. The issue I have is that if close my world, and open it again, the miniwin stops working. It only displays the window, but nothing ever is written once the trigger that updates the writing is activated. If I go to File > plugins > reinsttall, the plugin comes back to life and works exactly as intended.

Aditionally, I installed movewindow into it, and whenever I reload the world, the plugin begins at the initial position, top left, and stays there for a few seconds before it jumps back to the last saved position in the screen.

I deconstructed the code to leave only the essential part of how it works in an attempt to find what's the issue, however I'm not particularly an expert in Lua or plugins, and so I haven't found the problem. I paste this oversimplified version of the code I deconstructed that still preserves the same problem I've been having. Any help would be most amazing!

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<!-- Bits of this plugin and ideas were borrowed and remixed from the MUSHclient community.-->

<muclient>
    <plugin
    name="test"
    author="H"
    id="8c1ab2792ea52210aa67798f"
    language="Lua"
    purpose="Displays test"
    date_written="2015-01-28"
    date_modified="2015-01-29"
    requires="4.52"
    version="2.0"
    save_state="y"
    >
    
<description trim="y">

</description>
  
</plugin>

<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   keep_evaluating="y"
   match="Hall of the Fellowship."
   script="test_update"
   sequence="100"
  ></trigger>

</triggers>


<script>


require "movewindow"  -- load the movewindow.lua module

win = GetPluginID ( )
font = "f"

window_width = 200
window_heigth = 300
WINDOW_POSITION = miniwin.pos_top_left 

WindowFont ( win, font, "arial", 10, false)

WindowCreate ( win, 0, 0, window_width, window_heigth, WINDOW_POSITION, 0, 0x000000)
WindowRectOp( win, miniwin.rect_draw_edge, 2, 2, -2, -2, miniwin.rect_edge_etched, miniwin.rect_edge_at_all)

WindowText ( win, font, "this", 50, 100, 0, 0, ColourNameToRGB ( "red" ) )

WindowShow ( win )

-- windowinfo = movewindow.install (win, WINDOW_POSITION)
-- movewindow.add_drag_handler (win, 0, 0, 0, 0)


function test_update ()
refresh()
WindowText ( win, font, "that", 100, 100, 0, 0, ColourNameToRGB ( "red" ) )
WindowShow ( win )
end 

function refresh()
WindowRectOp (win, miniwin.rect_fill, 0, 0, 0, 0, ColourNameToRGB ("black"))
WindowRectOp( win, miniwin.rect_draw_edge, 2, 2, -2, -2, miniwin.rect_edge_etched, miniwin.rect_edge_at_all)
end

-- hide window on removal
function OnPluginClose ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginClose

-- hide window on disable
function OnPluginDisable ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginDisable

-- show window on enable
function OnPluginEnable ()
    WindowShow (win,  true)  -- show it
end -- OnPluginEnable

function OnPluginInstall()
    WindowShow (win,  true)  -- show it
end

function OnPluginSaveState ()
  -- save window current location for next time  
--  movewindow.save_state (win)
end -- function OnPluginSaveState


</script>
</muclient>


For example, this code should display "this," and after the trigger happens, it should display "that". On reinstall, this is exactly how it works. If I get out of the world and reopen it again, "this" won't be displayed, only the black window will be there, and the trigger won't change anything. On reinstall, it goes back to working right.
Amended on Fri 30 Jan 2015 02:03 PM by Herl
USA Global Moderator #1
Quote:
WindowShow ( win )

Doesn't WindowShow take a second parameter?
Australia Forum Administrator #2
It defaults to true if omitted.
#3
yeah, that's not the issue :/ it's differently written in different parts of the code because the code is a bunch of other plugins found here in the forum stitched together.
#4
I think maybe the font installation must be after the window creation.
Australia Forum Administrator #5
Here's your problem:


WindowFont ( win, font, "arial", 10, false)

WindowCreate ( win, 0, 0, window_width, window_heigth, WINDOW_POSITION, 0, 0x000000)


WindowFont adds a font to an existing window. However the window is created a line further down. Thus it fails to load the font, thus it cannot draw the text.

A good trick is to use the "check" function when things are not going as expected. For example:


check (WindowFont ( win, font, "arial", 10, false))


Now we get the message:


Run-time error
Plugin: test (called from world: smaug2)
Function/Sub: OnPluginInstall called by Plugin test
Reason: Executing plugin test sub OnPluginInstall
[string "Plugin"]:37: Requested miniwindow does not exist
stack traceback:
        [C]: in function 'error'
        [string "Check function"]:1: in function 'check'
        [string "Plugin"]:37: in function <[string "Plugin"]:27>
Error context in script:
  33 :   window_width = 200
  34 :   window_heigth = 300
  35 :   WINDOW_POSITION = miniwin.pos_top_left 
  36 :   
  37*:   check (WindowFont ( win, font, "arial", 10, false))
  38 :   
  39 :   WindowCreate ( win, 0, 0, window_width, window_heigth, WINDOW_POSITION, 0, 0x000000)
  40 :   WindowRectOp( win, miniwin.rect_draw_edge, 2, 2, -2, -2, miniwin.rect_edge_etched, miniwin.rect_edge_at_all)
  41 :   



That would give you a clue.

Move the WindowFont call down to after the window is created. It worked when you reinstalled because the window existed then, and it was able to add the font.

I got a clue from the "summary" plugin, like this:


Window: '8c1ab2792ea52210aa67798f', at (0,0,200,300), shown: yes
        width: 200, height: 300, position: 4, hotspots: 0, fonts: 0, images: 0



When I saw that I thought "fonts: 0? There should be a WindowFont call there!".

And there was, but then I spotted it was in the wrong place.
Amended on Sat 31 Jan 2015 02:05 AM by Nick Gammon
#6
How come it's always the small things huh?

Thank you very much guys!
Australia Forum Administrator #7
Donecce said:

I think maybe the font installation must be after the window creation.


Donecce was right. :)