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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Miniwindows ➜ all in script part

all in script part

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


Posted by Mahony   (27 posts)  Bio
Date Thu 16 Oct 2014 09:05 PM (UTC)
Message
Hi
I have all in script part and I suspect that this is the problem. OnPluginInstall, WindowCreate,...
See code


<script>
<![CDATA[
require "checkplugin"
require "tprint"
require "movewindow"

win = GetPluginID () .. "_ident"
font = "f"
report = {}

function OnPluginInstall ()
print("OnPluginInstall")
  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, 6)  -- default to 6 (on top right)
  -- make window so I can grab the font info
  WindowCreate (win, 0, 0, 0, 0, 1, 0, 0)

  -- add the font                 
  WindowFont (win, font, "Lucida Console", 9)  
    
end -- OnPluginInstall

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

local font_height = WindowFontInfo (win, font, 1)
local max_width = WindowTextWidth (win, font, "Report")
local window_width = max_width + 10
local window_height = font_height * (#report + 2) + 10

-- make window correct size

tprint(windowinfo)
--WindowCreate (win, 
--                 windowinfo.window_left, 
--                 windowinfo.window_top, 
--                 window_width, window_height,              -- width, height
--                 windowinfo.window_mode,   
--                 windowinfo.window_flags,
--                 ColourNameToRGB "#373737") 

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

-- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, font_height)

The client complains

[string "Plugin"]:185: bad argument #7 to 'WindowCreate' (number expected, got nil)


I found out that when I try tprint(windowinfo) in the OnPluginInstall it is ok but outside it complains

MUSHclient\lua\tprint.lua:34: bad argument #1 to 'pairs' (table expected, got string)

So it doesnt know anything about table windowinfo. I use this construct in another plugin where only the OnPluginInstall is in <script> section and rest is in alias body.

I don't know why it doesn't work. I'm lost. Help please.
Thank you
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #1 on Thu 16 Oct 2014 09:59 PM (UTC)

Amended on Thu 16 Oct 2014 10:02 PM (UTC) by Fiendish

Message
Quote:
I have all in script part and I suspect that this is the problem.

That's irrelevant. The problem is that your code is wrong.

Quote:
See code

Most of your plugin is missing, so we can't see it. Post the whole thing.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Mahony   (27 posts)  Bio
Date Reply #2 on Thu 16 Oct 2014 10:29 PM (UTC)

Amended on Fri 17 Oct 2014 06:09 AM (UTC) by Nick Gammon

Message
Sorry, I just didn't want to overload and I thought that the rest of the code is not important. I have a plugin that can report stats to the main window using Note. I just wanted to move the output to miniwin. I didn't get past the part I posted first... Thanx for help

<script>
<![CDATA[
require "checkplugin"
require "tprint"
require "movewindow"

win = GetPluginID () .. "_ident"
windowinfo = ""
font = "f"
report = {}

function OnPluginInstall ()
print("OnPluginInstall")
  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, 6)  -- default to 6 (on top right)
  -- make window so I can grab the font info
  WindowCreate (win, 0, 0, 0, 0, 1, 0, 0)

  -- add the font                 
  WindowFont (win, font, "Lucida Console", 9)  
    
end -- OnPluginInstall

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

local font_height = WindowFontInfo (win, font, 1)
local max_width = WindowTextWidth (win, font, "Report")
local window_width = max_width + 10
local window_height = font_height * (#report + 2) + 10

-- make window correct size

tprint(windowinfo)
--WindowCreate (win, 
--                 windowinfo.window_left, 
--                 windowinfo.window_top, 
--                 window_width, window_height,              -- width, height
--                 windowinfo.window_mode,   
--                 windowinfo.window_flags,
--                 ColourNameToRGB "#373737") 

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

-- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, font_height)

-- Tables --                                                           

All = {}                                  														--table will contain all info gotten from bid item#
flags = {}                                                                                      --table for working with ill,so,reson
--Other variables--
s = ""                                                                                          --string containing the output from the mud
a = 0
 
-- regtotable --                       
 
function regtotable (a,b)                                                                       --Fucntion to help with getting the data from bid item
        re = rex.new (a)                                                                        --and putting it in the All table
        _,_,t = re:match (s)
        if t ~= nil then
                table.remove (t,1)
                for k, v in pairs (t) do
                        if k == 1 then
                                table.remove (t,1)
                        elseif k == 2 then
                                table.remove (t,2)
                        else
                                All [k] = (v)
                        end -- if
                end -- for loop
        else
                All  [b] = "0"
                SaveState ()
        end
end -- regtotable
-- auction_to_channel--
function auction_to_channel(name,line,wildcards,styles)                                         --Function gets called by the alias or the triger
        if name == "AuctBroad" then                                                             --Alias calls the function
                SetVariable("aType", "bid ")
                if (wildcards.Auct_type) == "r" then
                        SetVariable("aType", "Rbid ")
                elseif  (wildcards.Auct_type) == "l" then
                        SetVariable("aType", "Lbid ")
                elseif (wildcards.Auct_type) == "" then
                        SetVariable("aType", "Bid ")
--moje uprava
				elseif (wildcards.Auct_type) == "o" then
                        SetVariable("aType", "oo ")
						if tostring(wildcards.Auct_nbr) then
						 All["Nbr"] = wildcards.Auct_nbr                                               --Add the item# to All table
						 EnableTrigger ("GetAuctLine", true)
						 Send ((GetVariable("aType")) .. wildcards.Auct_nbr)                           --Send bid item# to the mud
						end --if

				end --if
                if tonumber(wildcards.Auct_nbr) then
                 All["Nbr"] = wildcards.Auct_nbr                                                     --Add the item# to All table
				 EnableTrigger ("GetAuctLine", true)                                                 --Enables the trigger so the output from bid gets captured
				 SendNoEcho ((GetVariable("aType")) .. wildcards.Auct_nbr)                           --Send bid item# to the mud
                end --if
        end -- if
Top

Posted by Mahony   (27 posts)  Bio
Date Reply #3 on Thu 16 Oct 2014 10:39 PM (UTC)

Amended on Fri 17 Oct 2014 06:09 AM (UTC) by Nick Gammon

Message
...continue because I reached 6000chars and I had to cut something because I have still more than 6000ch


 

		Wstring = "report: "
        atype =  (GetVariable ("aType"))
                        if tonumber(All.Str) ~= 0 then
                                Wstring = (Wstring..string.format("%6s", All.Str).." Str")             
						else
								Wstring = (Wstring..string.format("%6s", " ").."    ")
						end
                        if tonumber(All.Int) ~= 0 then
                                Wstring = (Wstring.." "..string.format("%6s", All.Int).." Int")
						else
								Wstring = (Wstring..string.format("%6s", " ").."     ")
                        end
                        if tonumber(All.Wis) ~= 0 then
                                Wstring = (Wstring.." "..string.format("%6s", All.Wis).." Wis")             
						else
								Wstring = (Wstring..string.format("%6s", " ").."     ")
                        end
                        if tonumber(All.Dex) ~= 0 then
                                Wstring = (Wstring.." "..string.format("%6s", All.Dex).." Dex")             
						else
								Wstring = (Wstring..string.format("%6s", " ").."     ")
                        end
                        if tonumber(All.Con) ~= 0 then
                                Wstring = (Wstring.." "..string.format("%6s", All.Con).." Con")             
						else
								Wstring = (Wstring..string.format("%6s", " ").."     ")
                        end
                        if tonumber(All.Luck) ~= 0 then
                                Wstring = (Wstring.." "..string.format("%6s", All.Luck).." Luc")            
						else
								Wstring = (Wstring..string.format("%6s", " ").."     ")
                        end
                        if tonumber(All.Dr) ~= 0 then
                                Wstring = (Wstring.." "..string.format("%6s", All.Dr).." Dr")               
						else
								Wstring = (Wstring..string.format("%6s", " ").."     ")
                        end
                        if tonumber(All.Hr) ~= 0 then
                                Wstring = (Wstring.." "..string.format("%6s", All.Hr).." Hr")               
						else
								Wstring = (Wstring..string.format("%6s", " ").."    ")
                        end

				if All.Type == "Weapon" then
                        Wstring = (Wstring.." ["..All.Name.."]".." L "..All.Lvl.." "..All.Wtype.." -- |".."Dam Type "..All.Wdtype.."|, |".."AvD "..All.Wdmg.."|, & |"..All.Tstats.." TS")   
                        if flagstring ~= "" then
                                Wstring = (Wstring.." Fl ".."["..flagstring.."]")
                        end            
                else
                        Wstring = (Wstring.." ["..All.Name.."]".." L "..All.Lvl.." ["..All.Wear.."] -- ".."["..All.Tstats.." TS")   
						if tonumber(All.Tpoints) ~= 0 then        
                         Wstring = (Wstring.."] = ["..All.Tpoints.." TP".."]")
						else
                         Wstring = (Wstring.."]@w")
						end
						if flagstring ~= "" then
                                Wstring = (Wstring.." Fl ".."["..flagstring.."]")
                        end    
                end    
				Note(Wstring)
				table.insert (report, Wstring)
				local y = font_height * 2 + 5
			for k, v in pairs ( report ) do
				-- work out max width
				max_width = math.max (max_width, WindowTextWidth (win, font, v))
				x = x + WindowText (win, font, v, x, y, 0, 0, "yellow")
				y = y + font_height
			end --for
		WindowShow (win, true)
        SaveState ()
end -- Var_from_file
 
]]>
</script>
[/code
Top

Posted by Mahony   (27 posts)  Bio
Date Reply #4 on Thu 16 Oct 2014 10:46 PM (UTC)
Message
I had to cut something from the middle that helps construct the Wstring. But it is not miniwin related. The important part is at the beginning. The WindowCreate is commented because it complains about argument #7 is nil. When I try to tprint(windowinfo) right before the WindowCreate it doesn't know the table windowinfo at all...
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Fri 17 Oct 2014 06:22 AM (UTC)

Amended on Fri 17 Oct 2014 06:24 AM (UTC) by Nick Gammon

Message
You have put things in a really weird order. These lines:


local font_height = WindowFontInfo (win, font, 1)
local max_width = WindowTextWidth (win, font, "Report")
local window_width = max_width + 10
local window_height = font_height * (#report + 2) + 10

-- make window correct size

tprint(windowinfo)
--WindowCreate (win, 
--                 windowinfo.window_left, 
--                 windowinfo.window_top, 
--                 window_width, window_height,              -- width, height
--                 windowinfo.window_mode,   
--                 windowinfo.window_flags,
--                 ColourNameToRGB "#373737") 

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

-- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, font_height)

-- Tables --                                                           

All = {}     --table will contain all info gotten from bid item#
flags = {}    --table for working with ill,so,reson
--Other variables--
s = ""    --string containing the output from the mud
a = 0


... are not inside any function and are thus executed before anything else.

For example, you are trying to find the font height, before you have created the window. And you are using windowinfo before OnPluginInstall is called, and thus it won't be valid. You have to move that stuff inside OnPluginInstall.

More correct is this:


function OnPluginInstall ()

  print("OnPluginInstall")
  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, 6)  -- default to 6 (on top right)
  -- make window so I can grab the font info
  WindowCreate (win, 0, 0, 0, 0, 1, 0, 0)
  tprint(windowinfo)

  -- add the font                 
  WindowFont (win, font, "Lucida Console", 9)  

  font_height = WindowFontInfo (win, font, 1)
  max_width = WindowTextWidth (win, font, "Report")
  local window_width = max_width + 10
  local window_height = font_height * (#report + 2) + 10

    -- make window correct size
  
  WindowCreate (win, 
                   windowinfo.window_left, 
                   windowinfo.window_top, 
                   window_width, window_height,  -- width, height
                   windowinfo.window_mode,   
                   windowinfo.window_flags,
                   ColourNameToRGB "#373737") 
  
  WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)
  
  -- add the drag handler so they can move the window around
    movewindow.add_drag_handler (win, 0, 0, 0, font_height)
  
  -- Tables --                                                           
  
  All = {}       --table will contain all info gotten from bid item#
  flags = {}     --table for working with ill,so,reson
  --Other variables--
  s = ""           --string containing the output from the mud
  a = 0
   
  
end -- OnPluginInstall


At least that displays this:


OnPluginInstall
"dragrelease"=function: 02E03BB0
"window_flags"=0
"preprocess":
"mousedown"=function: 02E05BF0
"window_left"=0
"window_mode"=6
"window_top"=0
"cancelmousedown"=function: 02E06320
"check_map_position"=function: 02E056B0
"mouseover"=function: 02E06440
"cancelmouseover"=function: 02E063B0
"win"="7cc9d7720077333c01c21372_ident"
"dragmove"=function: 02E04F30
"mouseup"=function: 02E00040
"window_friend_deltas":
"window_friends":
"margin"=20

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Mahony   (27 posts)  Bio
Date Reply #6 on Fri 17 Oct 2014 08:08 AM (UTC)
Message
Quote:

... are not inside any function and are thus executed before anything else.

So here is the problem. It is obvious that it is not my code and I took it from somewhere and used it. Now when you say this it's all clear. I thought that it runs the function OnPluginInstall first because it is before the rest of the code.
Thank you! I'll try to adapt the code.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #7 on Fri 17 Oct 2014 09:19 AM (UTC)
Message
The code outside any function is run when the plugin is loaded. Then it calls OnPluginInstall. I suppose the distinction might be fine, but it makes sense to have a function called rather than just say "leave anything you want done first outside a function".

- 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.


19,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.