Skip to content

Lua script return values don't behave as expected #399

Description

@EpicJake72

I have a Lua script that looks for a village within a specific coordinate range. When found, it returns the coordinates of the village, just like how the "Village along the way from A to B" example script does it.

However, if I then try to search for something else, like biomes or structures, and set the relative location to the Lua script, instead of the search being centered on the village found from the script, it will always revert to 0, 0.

So how do I properly set the relative location of another condition through a Lua script? The return value doesn't seem to work, but I could be missing something.

Code:

-- Look for a village located between the first two dependent conditions
function check(seed, at, deps)
	local x1, z1, x2, z2 = -220, 82, -700, 102
	vils = getStructures(Village, x1, z1, x2, z2)
	if vils == nil then return nil end
	for i = 1, #vils do
		-- calculate the square distance to the line a -> b
		local dx, dz = x2 - x1, z2 - z1
		local d = dx * (vils[i].z - z1) - dz * (vils[i].x - x1)
		d = (d * d) / (dx * dx + dz * dz + 1)
		if d < 8*8 then -- village intersecting the line
			if getBiomeAt(vils[i].x, vils[i].z) == plains then
				return vils[i].x, vils[i].z
			end
		end
	end
	return nil
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions