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!

P#74068 2020-03-20 06:57

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...)

P#74069 2020-03-20 07:07

Awesome, thanks so much!

P#74071 2020-03-20 08:14

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-06-01 05:46 | 0.010s | 2097k | Q:13