Community Forum

Add Trigger

Forum Overview >> Farming Simulator 2009

CategoryFarming Simulator 2009
Created21.06.2009 01:38

Andreas Großschedl (unknown) 21.06.2009 01:42

I've tried to add a trigger on one of my test model. To add the trigger is not the problem, but I never get into the trigger callback function. Can you help me? What is wrong?

ps.: same problem with the onCreate function ... i never get there

Christian Ammann - GIANTS Software 21.06.2009 12:13
Please post your onCreate script code here. Its quite difficult to help you otherwise.

Andreas Großschedl (unknown) 21.06.2009 12:55
First i add a userAttribute in the Editor:
Type: Script Callback Name: onCreate Attribute: onCreateTest


function onCreateTest(id)
print("Test onCreate callback");

This code i put into an "extrasourcefile".

Christian Ammann - GIANTS Software 21.06.2009 14:59
Please post your script code were you create your trigger etc.

Andreas Großschedl (unknown) 21.06.2009 15:09
function Test_Trigger:load(xmlFile)
triggerId0=Utils.indexToObject(self.rootNode, "1|0");
print("triggerID: "..triggerId0);
addTrigger(triggerId0, "triggerTest");

at the end of the script:

function Test_Trigger:triggerTest(triggerId1, objectId1, rein, raus, bleiben)

print("trigger rein/raus/bleiben: ".. rein .. raus .. bleiben);


Matthias B. (unknown) 21.06.2009 23:23
function Test_Trigger:load(xmlFile)
self.myTrigger = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.myTrigger#index"));
print("triggerId:" .. self.myTrigger);
addTrigger(self.myTrigger, "triggerCallback", self)


function Test_Trigger:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)

-- now you need a objekt which handles the function: like a pipe and a trailer appears your trigger
if yourTrailer ~= nil then
if onEnter then
print("Trigger has been entered by:" .. yourTrailer)

if onLeave then
print("Trigger has been leaved by:" .. yourTrailer)


Note (GIANTS Documentation:)

Add Trigger:

Adds a trigger callback function

The transformId must have set the trigger flag and must be a static or a kinematic rigid body.
The given triggerFunctionCallback is called, whenever a dynamic or kinematic body enters or leaves the region defined by the trigger geometry. Static objects do not trigger an event.
See "trigger callback" in section "Custom callbacks"

Stefan Geiger - GIANTS Software 22.06.2009 12:06
All mods are loaded in an separate namespace (to avoid variable and function name clashes between multiple mods). The namespace is equal to the name of the folder/zip of the mods.
Therefore you can only call the function as .onCreateTest. You should adjust your user attribute in the i3d. However this requires all users to have the name of the zip exactly the same.

Another solution is to use this code:
_G.onCreateTest= function(id)
print("Test onCreate callback");
With this, you can use "onCreateTest" as the User Attribute in the i3d.
But if you use this, you should use a very distinct name, to avoid name clashes with other mods. Eg onCreate

The problem here is, that the engine tries to call the global function triggerTest, which does not exist. You only have the function Test_Trigger:triggerTest. To fix this, you should add, self as the 3rd parameters to addTrigger. And add the line self.triggerTest = Test_Trigger.triggerTest
Check to code of Mattias B.

Andreas Großschedl (unknown) 24.06.2009 13:32
To add a trigger is no problem any longer! Thank you!

But with the onCreate i still have problems to get there.

Now i changed the user Attribute in GE: Name: onCreate Attribute: .onCreateTest

in Code:

function onCreateTest(id)

Did i missunderstand something?

Matthias B. (unknown) 25.06.2009 22:12
what do you want to do? load an trigger via extrafile.lua?

Andreas Großschedl (unknown) 27.06.2009 08:03
For example, yes. But now this is only for understanding. I want to add an object (i3d) to the map with the editor and when the object gets loaded, i want to call this "onCreate" callback (like in the tutorial). Stefan wrote that it is also possible to bind a script direct to a i3d file!? Maybe you can also tell my how?


Matthias B. (unknown) 27.06.2009 17:25
i think you only have to include your scriptfile to your i3d folder

Andreas Großschedl (unknown) 05.07.2009 10:39
I tried but this does not work.

Matthias B. (unknown) 05.07.2009 20:57
yes i know!

B. Benjamin (unknown) 06.07.2009 18:03

Is there some " news " about a way to add a trigger to an object on a map ? For example a trigger that allow to open a simple door when entering the area.

Thanks for your help,

Matthias B. (unknown) 06.07.2009 18:18
just look in the upper threads!

B. Benjamin (unknown) 06.07.2009 18:25
Yep, okay, the upper threads are talking about adding a trigger on a vehicle.
What i want is adding a trigger on a object, on the map. ( NOT as the "pesticideTrigger ")

I can't call the .lua script or i don't know how to declare it as it's not a specialization. So I was wondering it there is something new about all this...

Thanks for your answer.

Edit : I'm sorry Matthias, by "threads" I understood " message" ! ^^ I'll have a look at the other threads so! Thanks :)

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