The simplest way I can think of to do this would be
Code:
--Call from your function that determines how many to pull
--Feed this function the script zone as well as the # of obj to take
function takeFromZone(zone, howMany)
for i=1, howMany do
zone.takeObject(params)
end
end
You could make a list of eligible objects to pull in that function too, like this, if you wanted them to have certain names. In this example, it would pull objects from a script zone that are tagged as being a "Dice". It also has built-in error protection, not allowing you to try to take more dice from the zone than there are.
Code:
--Call from your function that determines how many to pull
--Feed this function the script zone as well as the # of obj to take
function takeFromZone(zone, howMany)
local func_dice = function(o) return o.tag=="Dice" end
local objList_all = zone.getObjects()
local objList_dice = tableRefine(objList_all, func_dice)
for i, dice in ipairs(objList_dice)
dice.setPosition(whatever)
if i == howMany then
break
end
end
end
--Refines a table, only returning entries that match func's requirement
--Example func: function(o) return o.name=="Entry's Name" end
function tableRefine(t, func)
if func==nil then error("No func supplied to refineTableBy") end
local refinedTable = {}
for _, v in ipairs(t) do
if func(v) then
table.insert(refinedTable, v)
end
end
return refinedTable
end