• Print

Author Topic: Tables and Derma  (Read 4594 times)

0 Members and 1 Guest are viewing this topic.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Tables and Derma
« on: March 07, 2015, 10:17:18 am »
I've made it further than usual before asking for help!

Basically, I'm in the works of a whitelist addon
I got that part working, but I want to add a derma window ingame where a player with a specific rank can view and edit the whitelist (which works via SteamID)

I have the window and rank check working fine
My problem lies with DListView

My list of SteamIDs is in a table called whitelist

I'm not sure how I would go about adding all values of that table into the DlistView, though I would imagine I use the for loop

Here's my derma window as it stands currently

Code: Lua
  1. net.Receive("OpenWhitelistWindow", function()
  2.         gui.EnableScreenClicker(true)
  3.  
  4.         DF = vgui.Create("DFrame")
  5.         DF:Center()
  6.         DF:SetSize(300,300)
  7.         DF:SetTitle("Zee's Whitelist Menu")
  8.         DF:SetDraggable(true)
  9.         DF:ShowCloseButton(false)
  10.         DF:MakePopup()
  11.         DL = vgui.Create("DListView")
  12.         DL:SetMultiSelect(false)
  13.         DL:AddColumn("SteamIDs")
  14.                
  15.         CloseButton = vgui.Create("DButton", DF)
  16.         CloseButton:SetPos(275)
  17.         CloseButton:SetText("X")
  18.         CloseButton:SetSize(20,20)
  19.         CloseButton.DoClick = function()
  20.                 DF:Close()
  21.                 gui.EnableScreenClicker(false)
  22.         end
  23. end )

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Tables and Derma
« Reply #1 on: March 07, 2015, 11:50:29 am »
Code: Lua
  1. for k, v in pairs(whitelist) do
  2.     DL:AddLine(v)
  3. end

Boom. Simple.

If you want the code broken down, here ya go:
Code: Lua
  1. for k, v in pairs(whitelist)
This basically says, "for each entry in the whitelist table, assign the key to that entry to k, and the value at that key to v".
Code: Lua
  1. DL:AddLine(v)
This says, "In each iteration of the above for loop, add the current value we're working with (v) to the DListView".
Code: Lua
  1. end
._.
bw81@ulysses-forums ~ % whoami
Homepage

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Tables and Derma
« Reply #2 on: March 07, 2015, 11:52:42 am »
How is your table structured? Is it just an ordered table of steamids?

If all that is in the table is SteamIDs then you would need to do something like this:

Code: Lua
  1. for k, v in pairs( whitelist ) do
  2.     DL:AddLine( v )
  3. end

Just add that code after you initiate the DListView element. Probably before the CloseButton lines.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Tables and Derma
« Reply #3 on: March 07, 2015, 12:02:27 pm »
How is your table structured? Is it just an ordered table of steamids?

If all that is in the table is SteamIDs then you would need to do something like this:

Code: Lua
  1. for k, v in pairs( whitelist ) do
  2.     DL:AddLine( v )
  3. end

Just add that code after you initiate the DListView element. Probably before the CloseButton lines.
Hey! That's my code! >:C
bw81@ulysses-forums ~ % whoami
Homepage

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Tables and Derma
« Reply #4 on: March 07, 2015, 12:13:38 pm »
Peeeeeeeeeerfecto!

Thank you, gentlemen

I should be close to releasing version 2 now!

I wasn't sure what I would put in the () of for k, v in pairs, since the only other time I have used that is for player.GetAll()

PS: You have each been complimented

  • Print