Returning table values

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

Returning table values

Post 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?
Muris
Party member
Posts: 131
Joined: Fri May 23, 2014 9:18 am

Re: Returning table values

Post 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.
Bindie
Party member
Posts: 151
Joined: Fri Jan 23, 2015 1:29 pm

Re: Returning table values

Post by Bindie »

Edit: I solved it.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests