LUADOC - Farming Simulator 22

AIParameterPosition

Parent
AIParameter
Functions

getPosition

Description
Definition
getPosition()
Code
71function AIParameterPosition:getPosition()
72 return self.x, self.z
73end

getString

Description
Definition
getString()
Code
77function AIParameterPosition:getString()
78 return string.format("< %.1f , %.1f >", self.x, self.z)
79end

loadFromXMLFile

Description
Definition
loadFromXMLFile()
Code
38function AIParameterPosition:loadFromXMLFile(xmlFile, key)
39 self.x = xmlFile:getFloat(key .. "#x", self.x)
40 self.z = xmlFile:getFloat(key .. "#z", self.z)
41end

new

Description
Definition
new()
Code
16function AIParameterPosition.new(customMt)
17 local self = AIParameter.new(customMt or AIParameterPosition_mt)
18
19 self.type = AIParameterType.POSITION
20
21 self.x = nil
22 self.z = nil
23
24 return self
25end

readStream

Description
Definition
readStream()
Code
45function AIParameterPosition:readStream(streamId, connection)
46 if streamReadBool(streamId) then
47 local x = streamReadFloat32(streamId)
48 local z = streamReadFloat32(streamId)
49 self:setPosition(x, z)
50 end
51end

saveToXMLFile

Description
Definition
saveToXMLFile()
Code
29function AIParameterPosition:saveToXMLFile(xmlFile, key, usedModNames)
30 if self.x ~= nil then
31 xmlFile:setFloat(key .. "#x", self.x)
32 xmlFile:setFloat(key .. "#z", self.z)
33 end
34end

setPosition

Description
Definition
setPosition()
Code
64function AIParameterPosition:setPosition(x, z)
65 self.x = x
66 self.z = z
67end

validate

Description
Definition
validate()
Code
83function AIParameterPosition:validate()
84 if self.x == nil or self.z == nil then
85 return false, g_i18n:getText("ai_validationErrorNoPosition")
86 end
87
88 if not g_currentMission.aiSystem:getIsPositionReachable(self.x, 0, self.z) then
89 return false, g_i18n:getText("ai_validationErrorBlockedPosition")
90 end
91
92 return true, nil
93end

writeStream

Description
Definition
writeStream()
Code
55function AIParameterPosition:writeStream(streamId, connection)
56 if streamWriteBool(streamId, self.x ~= nil) then
57 streamWriteFloat32(streamId, self.x)
58 streamWriteFloat32(streamId, self.z)
59 end
60end