Community Forum

Call function from Vehicle.lua

Forum Overview >> Farming Simulator 2011

CategoryFarming Simulator 2011
Created03.05.2011 11:17


Florian Otte (Unknown) 03.05.2011 11:18
Hello There.

Currently i'm playing a bit with lua and i was wondering how i can call a function from the vehicle.lua file - since there is a documentation, it should be possible somehow.

In this case i would like to call this function:
function Vehicle:setRelativePosition(positionX, offsetY, positionZ, yRot)

- self.Vehicle.set.... does not work.
so does Vehicle.setRel... not work.

this is the error i receive:
..../Vehicle.lua(990) : bad argument #1 to 'getn' (table expected, got nil)

Well since self.components seems to be the problem i assume that i try calling it at the wrong object. the line 990 is:

990 local numComponents = table.getn(self.components);

I simply added a transformgroup to the vehicle - the script bound to this transformgroup shall call stuff from the vehicle.lua file

could you give me any insight on how to get the corresponding object to call this function on?

Thanks in Advance - Florian

-- I also posted this in the scripting subforum a while ago, but did not receive an answer - hopefully just because no one read it - if there is no answer i'm sorry for bugging you folks again!

Tobias F (JD6930) 03.05.2011 22:30

function Vehicle:setRelativePosition(positionX, offsetY, positionZ, yRot)

Is loaded in every Script. You can call the function by this:

self:setRelativePosition(positionX, offsetY, positionZ, yRot);

Florian Otte (Unknown) 08.06.2011 14:39
Well yes,
but actually there is something off - since i cannot call all the functions from vehicle.lua from my specialization. i dont even know if specialization is the right word:

i simply added a script with an index to my vehicle - from this script i can call a few functions and open a tcp client to receive commands over network.

The thing is: when i try to use the setWorldPosition(x, x, x, x, x, x) command i get an error while trying to access self.components[i]. it is in line 1032 vehicle.lua.

any suggestions?


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