Nested Table as 2d Array issue

Place to get help with not working mods / modding interface.
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Nested Table as 2d Array issue

Post by Ranakastrasz »

Trying to get this to work. surface.get_tile is giving an error

Code: Select all

bad argument #-2 to 'get_tile' (number expected, got nil)
https://forums.coronalabs.com/topic/174 ... alization/
Used this as a reference, I thought I did the reference correctly, but apperently not.

Code: Select all

	if (game.tick % RanaMods.Fishing_Pole.config.spawn.tickRate) == 0 then
        for z, surface in pairs(game.surfaces) do
            for coord in surface.get_chunks() do
                local X,Y = coord.x, coord.y
                if surface.is_chunk_generated{X,Y} then
                    local area = {{X*32, Y*32}, {X*32 + 32, Y*32 + 32}}
                    -- Quick Method. Select random tile If deep water or Shallow water, 1/60 chance of fish
                    local selectedTile = {math.random(area[1][1],area[2][1])},{math.random(area[1][2],area[2][2])}
                    if math.random(1,60) == 60 then
                        local tileName = surface.get_tile(selectedTile[1],selectedTile[2]).name
                        if tileName == "water" or tileName == "deepwater" then
                            create_entity{name = "fish", position = selectedTile, force=game.forces.neutral}
                        end
                    end
                end
            end
        end
    end
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Nested Table as 2d Array issue

Post by Choumiko »

Code: Select all

local selectedTile = {
    math.random(area[1][1],area[2][1]),
    math.random(area[1][2],area[2][2])
}
You had },{ in between, effectively making it local selectedTile = {}, {}
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Nested Table as 2d Array issue (RESOLVED)

Post by Ranakastrasz »

Yep. That fixed it. Thanks.

Friggin hate how I can't see the actual code, just the code I think I wrote.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Post Reply

Return to “Modding help”