Log In  


Hi,

I'm iterating over all map cells multiple times, to do various actions:

for t_x = 0, 127 do
	for t_y = 0, 63 do
		-- scan tiles
	end
end

for t_x = 0, 127 do
	for t_y = 0, 63 do
		-- do something
	end
end

for t_x = 0, 127 do
	for t_y = 0, 63 do
		-- place tiles
	end
end

This works, but uses a lot of tokens (do something is actually 4-5 different actions).

As there are a lot of interdependencies between cells, I can not do this:

for t_x = 0, 127 do
	for t_y = 0, 63 do
		-- scan tiles
		-- do something
		-- place tiles
	end
end

Instead, I wanted to do this:

functions = {
	scan_tiles(t_x, t_y),
	do_something(t_x, t_y),
	place_tiles(t_x, t_y),
}

for f in all (functions) do
	for t_x = 0, 127 do
		for t_y = 0, 63 do
			f(t_x, t_y)
		end
	end
end

But I never get the arguments passed to the functions I call.

How to go about this?

All help very much appreciated!



1

almost there - the ‘handle’ to a function is its name, not including parameters.
functions={
scan_tiles,
do_something,
place_tile
}
is the correct syntax (assuming all functions are declared before the funxctions array...)


Awesome, thanks so much!



[Please log in to post a comment]