Results 1 to 2 of 2

Thread: [lua] - Anyone know how to add to list[string][string] tables together?

  1. #1

    [lua] - Anyone know how to add to list[string][string] tables together?

    I have a number of large lists that are formatted like this...

    Code:
    listA = {}
       listA['Suburb Name A']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
       listA['Suburb Name B']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
       listA['Suburb Name C']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
       listA['Suburb Name D']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
       excreta... .. .
    Code:
    listB = {}
       listB['Suburb Name E']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
       listB['Suburb Name F']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
       listB['Suburb Name G']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
       listB['Suburb Name H']['Street Name'] = {data1 = 'Stuff', data2 = 'stuff, data3 = 'stuff}
       excreta... .. .
    What I am trying to do is copy these lists into a new list, a new list that is both the list combined.

    Something like this..

    Code:
    ListNew = {}
    ListNew = Add(listA, ListNew )
    ListNew = Add(listB, ListNew )
    ListNew = Add(listC, ListNew )
    Any ideas?
    My Boardgame uTube chan - Tragic's Table Top
    BGG Guild of BoardGame uTubers - Tube Tables

  2. #2
    Got it...

    Code:
    function add(target, source)
    	for i in pairs(source) do
    		if target[i] == nil then
    			target[i] = {}
    		end
    		for j in pairs(source[i]) do
    			target[i][j] = source[i][j]
    		end
    	end
    end
    
    -- used like this
    newList = {}
    add(newList, listA)
    add(newList, listB)
    add(newList, listC)
    My Boardgame uTube chan - Tragic's Table Top
    BGG Guild of BoardGame uTubers - Tube Tables

Similar Threads

  1. Replies: 5
    Last Post: 08-19-2018, 08:56 PM
  2. [ADDED] onPlayerChat(string message, string player_color)
    By JotaFaD in forum Scripting Suggestions
    Replies: 2
    Last Post: 08-25-2017, 05:45 PM
  3. setBackground(string url)
    By JotaFaD in forum Scripting Suggestions
    Replies: 8
    Last Post: 01-29-2017, 01:06 PM
  4. Replies: 0
    Last Post: 06-06-2016, 12:03 PM
  5. Replies: 1
    Last Post: 04-28-2016, 05:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •