vettim89 -> RE: Random Location Generator (6/20/2021 7:48:28 PM)
|
quote:
function RelocateSub (theside, unitguid) local retval,unit = pcall(ScenEdit_GetUnit,{guid=unitguid}) if (retval ==true) and theunit ~=nil then --if the call returned successfully and unit looks valid. math.randomseed(os.time()) math.random(); local rbearing=math.random(1,359) local rdistance=math.random(25,100) local newloc=World_GetPointFromBearing({latitude=unit.latitude, longitude=unit.longitude, DISTANCE=rdistance, BEARING=rbearing}) if newloc ~nil and type(newloc) == 'table' --is valid return table indicating some form. u.latitude = newloc.Latitude --no need for set unit if already have unitwrapper. u.longitude = newloc.Longitude --no need for set unit if already have unitwrapper. --... other stuff if needed... like you aren't checking if this particular location is actually water. ;) --... but maybe for your circumstances it's not an issue and don't need the complication end else print("could not obtain unit with guid" .. unitguid end end local someListOfSubGuids = {'W7ZXL3-0HM9G95HNBS56'} For k,v in pairs(someListofSubGuids) do RelocateSubs ("USSR", v) end You had some minor typos there but I debugged them. However when I run the cal I get this local someListOfSubGuids = {'W7ZXL3-0HM9G95HNBS56', 'W7ZXL3-0HM9G95HNDET3', 'W7ZXL3-0HM9G95HNBTPI', 'W7ZXL3-0HM9G95HNBQME', 'W7ZXL3-0HM9G95HNDKB4', 'W7ZXL3-0HM9G95HNEEQ2'} For k,v in pairs(someListofSubGuids) do RelocateSub ("USSR", v) end ERROR: [string "Console"]:21: syntax error near 'k'
|
|
|
|