Community Forum

How to call API function

Forum Overview >> Farming Simulator 19

CategoryFarming Simulator 19
Created02.09.2021 11:20


Vasya Pupkin (GLeBaTi) 02.09.2021 11:20
Hello.
In game i can press 'O' and pipe change self state (move up/down).
I was try to change state of pipe in script. But have error:
dataS/scripts/vehicles/specializations/Pipe.lua(492) : attempt to index local 'spec' (a nil value)

My code:

function autogramma:pipeDown()
local vhcl = g_currentMission.controlledVehicle;
if vhcl ~= nil then
local pipeSpec = g_specializationManager:getSpecializationObjectByName("pipe")
if pipeSpec:getIsPipeStateChangeAllowed(0) then
pipeSpec:setPipeState(0)
end
end
end

Help me please :)

Bilbo Beutlin (BBeutlin) 02.09.2021 12:37
g_specializationManager:getSpecializationObjectByName() gives you the class, not the instance.


----- example code -----
local vhcl = g_currentMission.controlledVehicle;
if vhcl ~= nil then
local spec = vhcl.spec_pipe;
if spec ~= nil then
-- now you can apply the Pipe:function() to the vehicle, eg.
-- vhcl:getIsPipeStateChangeAllowed(pipeState)
-- vhcl:setPipeState(pipeState)


See for reference LUADOC/Script/Specializations/Pipe

Vasya Pupkin (GLeBaTi) 02.09.2021 12:47
i was think what object it is a instance (not class) after c# :)

Thanks for help. It working! :)


Note: Log in to post. Create a new account here.