this should be trivial to some but I don’t get it :s
if Message == "!kanebot" then
pos = {}
pObj = Get_GameObj(pID)
pos = Get_Position(pObj)
pos2:AssignX(pos2:GetX()+ 4*math.cos(Get_Facing(Get_GameObj(pID))*(math.pi / 180)))
pos2:AssignY(pos2:GetY()+ 4*math.cos(Get_Facing(Get_GameObj(pID))*(math.pi / 180)))
pos2:AssignZ(pos2:GetZ()+ .3)
reinf = Create_Object("Nod_Kane", pos)
Attach_Script_Once(reinf, "M01_Hunt_The_Player")
Attach_Script_Once(reinf, "M00_No_Falling_Damage_DME")
InputConsole("%s has bought a kanebot.", Get_Player_Name_By_ID(pID))
end
The error given is: Attempt to index global ‘pos2’ (a nil value)
Any ideas?
You get the position into the variable
pos, then are indexingpos2.pos2is never initialized, so when you try to index it (pos2:blah) you get an error about trying to indexnil.Side note: the
pos = {}line is completely superfluous, because you overwritepostwo lines later. Also, most of these variables should be made local, which is both faster and avoids polluting the global namespace.Minor refactor knowing nothing about your code and/or the API you’re using: