Page 1 of 1

Returning table values

Posted: Sun Jan 25, 2015 10:33 pm
by Bindie
Hey, trying to make an alternative map making system.

Code: Select all

function Corridorx1North(a,b,length, t)

		for i = 1, length do

		t[#t+1] = {tile = 9, x = a-map.tilesize, y = b+map.tilesize*length}
		t[#t+1] = {tile = 1, x = a, y = b+map.tilesize*length}
		t[#t+1] = {tile = 11, x = a+map.tilesize, y = b+map.tilesize*length}

		end

		return t

	end
Is there someway to input the sub-table values back into the table t?

Re: Returning table values

Posted: Sun Jan 25, 2015 11:17 pm
by Muris
Bindie wrote: Is there someway to input the sub-table values back into the table t?
Umm can you clarify a bit more what do you mean? In your code example you are adding tables into table t. Also the t you pass into the function does get altered.

In other words:

Code: Select all


local function testFunc( t )
	t.x = 200
	return t
end
local temp = {}
local temp2 = testFunc(temp)
print( temp2.x ) -- prints 200
print( temp.x ) -- also prints 200
Although I do not think this is what you are meaning, so I guess giving bit better description of what you want to do would help out a lot.

Re: Returning table values

Posted: Mon Jan 26, 2015 5:31 pm
by Bindie
Edit: I solved it.