I was attempting to make a script to clone a unit (just to see if I could) and cannot figure out how to use the Create function. I tried a code based on one to create a barbarian in the tutorial.lua but am having problems.
this is the relevant part:
It works fine until the last line above which I get the error "function expected instead of nil."
I also tried a slightly different code I found in worldbuilderplacement:
but received same error.
Thanks for any help
this is the relevant part:
Spoiler script :
local pUnit = UI.GetHeadSelectedUnit();
if (pUnit ~= nil) then
local unitType = GameInfo.Units[pUnit:GetUnitType()].Index;
local player = pUnit:GetOwner();
local plotX = pUnit:GetX() + 1
local plotY = pUnit:GetY()
print("pUnit", pUnit, "player", player, "unitType", unitType, plotX, plotY);
local pPlayer = Players[player];
local playerUnits = pPlayer:GetUnits();
print("playerunits", playerUnits);
local unit = playerUnits:Create(unitType, plotX, plotY);
if (pUnit ~= nil) then
local unitType = GameInfo.Units[pUnit:GetUnitType()].Index;
local player = pUnit:GetOwner();
local plotX = pUnit:GetX() + 1
local plotY = pUnit:GetY()
print("pUnit", pUnit, "player", player, "unitType", unitType, plotX, plotY);
local pPlayer = Players[player];
local playerUnits = pPlayer:GetUnits();
print("playerunits", playerUnits);
local unit = playerUnits:Create(unitType, plotX, plotY);
It works fine until the last line above which I get the error "function expected instead of nil."
I also tried a slightly different code I found in worldbuilderplacement:
Spoiler code :
WorldBuilder.UnitManager():Create(unitType, player, plot);
but received same error.
Thanks for any help