You are not logged in.

Applications: [GameMaster: OPEN] | [Volunteer Testers: OPEN]


This forum will be permanently shut down on Friday 13.07.2018
Please copy or save all important information from old forum before they will be deactivated
We have moved to new board. https://forum.runesofmagic.gameforge.com/Come join us.

1

Tuesday, August 11th 2015, 1:55am

Nightmare with GuildWarScore

Hello there... This is Stoneforge from Govinda. I've been making my addon (currently beta almost out) and would like to both update and get info from the GuildWarScore frame. I know this exists, because I can get the command /run

Source code

1
GuildWarScore:Show();
to work. So the Frame does exist. It has some children however... That I need to access... Now normally I go to http://runesofmagic.gamepedia.com/Comple…_Global_Widgets to find the children. However... there is no such frame that exists according to there. I don't see any way to list the children of a frame either. So how am I supposed to go about finding a way to manipulate this frame, if I can't call its children. Can someone update this list somehow? Can I find out somehow? Sort of troublesome... Brute forcing the combinations, even with some intelligence would take far more time then I would like to expend.

Peryl

Intermediate

Posts: 313

Location: Elsewhere

  • Send private message

2

Tuesday, August 11th 2015, 3:29am

I can't think of any easy way of doing it since there is no function to get the a child frame.

The only way I can think of is to brute force the issue by going through all entries in the global environment (_G) and if it is a frame, see if it is parented to GuildWarScore.

Something like this (written on the spur of the moment, so likely buggy)

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
childlist = {}
for k,v in pairs(_G) do
  if type(v) == "table" and v.GetParent ~= nil then
    if  v ~= GuildWarScore then
      -- follow parent chain
      local f, done, found  = v, false, false
      while not done do
        f = f:GetParent()
        if f == GuildWarScore then
          found = true
          done = true
        elseif f == WorldFrame or f == UIParent or f == nil then
          done = true
        end
      end
      if found then
        childlist[#childlist + 1] = k
      end
    end
  end
end

At the end of this, childlist should contain the names of all frames that have GuildWarScore as a parent somewhere in it's parent list.
2013... The year from hell....

3

Tuesday, August 11th 2015, 3:50am

Peryl sir, not only did this work, but it solves this problem for all future occurrences. I thank you very much for the solution. If I have any problems in the future I know who to come to. :) I printed them out as they were found rather than at the end. But I got EXACTLY what I needed...



Edit: Printing them out is a little bit of a bother, as default chat frame is too slow, and a custom channel is even worse... I'm only seeing 6 results returned.



Double Edit: I lied. It took severeal relogs. But it started to give me a list of 30 things. Looks correct... so far. All good.

This post has been edited 2 times, last edit by "ftwoplay" (Aug 11th 2015, 4:05am)


Peryl

Intermediate

Posts: 313

Location: Elsewhere

  • Send private message

4

Tuesday, August 11th 2015, 3:59pm

Glad to know it worked.

Anyway, for those not too familiar with RoM addons and/or Lua, here is a rehash of the above code with extra comments added in for those who want to know what is going on in that code.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- Define a variable to hold all the names of the frames that we may find
childlist = {}

--[[
    Go through all the variables defined in global space. RoM by default will 
    create all of its objects (frames, buttons, etc) in global space so this 
    should work. It will not find any objects that are only defined in a local 
    scope however.

    The lua iterator pairs() will iterate through all entries in the given table
    and return the key (name index) of the entry (this is usually a string) as
    well as the entry itself. So here, k will contain the name of the entry and
    v will be the object itself.
--]]
for k,v in pairs(_G) do

  -- Check if this is a frame. I'm actually cheating here as there is no way to
  -- figure out if it really is a frame so instead we check if the GetParent entry
  -- exists in this table. If so we'll assume that it is a function and that it is 
  -- therefore a frame (though this could be defeated easily enough)
  if type(v) == "table" and v.GetParent ~= nil then

    -- Check that we aren't looking at the GuildWarScore object itself.
    -- Not really needed, but kind of pointless to scan it. Could also skip
    -- WorldFrame and UIParent here as well.
    if  v ~= GuildWarScore then

      -- Now to follow the parent chain. We set a couple of flags (done and 
      -- found) to false and have a local variable called f (for frame) that will
      -- contain the parent object of the current object.
      local f, done, found  = v, false, false
      while not done do

        -- Get the parent of the current object (f)
        f = f:GetParent()

        if f == GuildWarScore then
          -- If the parent is GuildWarScore, then obviously the original object
          -- (v) has it as a parent somewhere in its chain. So flag it as found 
          -- and exit loop (by setting done to true)
          found = true
          done = true
        elseif f == WorldFrame or f == UIParent or f == nil then
          -- If the parent is WorldFrame or UIParent, or there isn't a parent at
          -- all, we are at the end of the chain so just exit the loop.
          done = true
        end
      end

      -- If we found GuildWarScore in the parent list, then the name (or key)
      -- of the original object (k) needs to be saved in our list.
      if found then
        -- this is a quick way to add something to the end of a list. #childlist
        -- will return the current size of the list.
        childlist[#childlist + 1] = k
      end
    end
  end
end
2013... The year from hell....

This post has been edited 3 times, last edit by "Peryl" (Aug 11th 2015, 4:08pm) with the following reason: Arranged the comments so they fit the window in the post and avoid scrolling the box.