Find and access label by name?

Geyser is an object oriented framework for creating, updating and organizing GUI elements within Mudlet.
Post Reply
Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Find and access label by name?

Post by Nyyrazzilyss » Sun Nov 13, 2016 7:51 pm

I need to clean up a bunch of my gui code that's a total unreadable mess. Question:

Is there an existing function to return the geyser label based on the label name?

Example, my existing code:

gGroupStatusWindow = Geyser.Label:new({name="gGroupStatusWindow", x="0%", y="-1c", width="100%", height="1c",})
gGroupStatusWindow:setOnEnter( "closeNests" )

What i'd like to do is get rid of the gGroupStatusWindow variable, and only access that using the "gGroupStatusWindow" window name. Something so

gGroupStatusWindow:setOnEnter( "closeNests" )

could be replaced with something similar to

label:get("gGroupStatusWindow"):setOnEnter( "closeNests" )

(and yes, I need to rename a bunch of those also)

(edit)

Took a look at the instructions :)

Geyser.Label:getWindow(label) -- label is the name, the return value is the object

Buck
Posts: 19
Joined: Tue Aug 30, 2016 8:11 pm

Re: Find and access label by name?

Post by Buck » Wed Dec 14, 2016 9:07 pm

I wrote some code for finding any existing window by name (so not only labels):
Code: [show] | [select all] lua
-- Searches for a geyser window by name

local function addToStack( stack, window_list)
  for name, window in pairs( window_list) do
    table.insert( stack, window)
  end
end

function getWindow( name) 
  local stack = {}
  addToStack( stack, Geyser.windowList)
  
  while table.getn( stack)>0 do
    local window = table.remove( stack)
    if window.name==name then
      return window
    end

    addToStack( stack, window.windowList)
  end
  return false
end
Do note that:
Code: [show] | [select all] lua
gGroupStatusWindow:setOnEnter( "closeNests" )

could be replaced with something similar to

label:get("gGroupStatusWindow"):setOnEnter( "closeNests" )
Would have to find the label with that name every time. It would be better to cache it in a table instead.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests