Community Forum

How to use "onCreate" scriptCallback?

Forum Overview >> Farming Simulator 2011

CategoryFarming Simulator 2011
Created18.11.2010 21:04


Andreas Großschedl (Unknown) 18.11.2010 21:10
How can i use the "onCreate" scriptCallback in ls11? I tried the same as in ls09 but this does not work.

UserAttributes(Map): type=scriptCallback name=onCreate value=objectOnCreate

in script:

_G.objectOnCreate=function(id)
print("objectOnCreate test, id= " .. tostring(id));
end;

what do i have to do different in ls11?

Thank you for help.
Andreas

Stefan Geiger - GIANTS Software 20.11.2010 15:46
The table _G is not the same anymore as in LS2009. New functions and variables you add in there, are not seen from the original parts of the game, or from other mods.

You should use the same mechanism that was introduced with Demolition Company to solve the onCreate problem.

You should use the value "modOnCreate.objectOnCreate" for your onCreate user attribute.
And then the code should look like this:


function objectOnCreate(id)
-- do some stuff
end;
g_onCreateUtil.addOnCreateFunction("objectOnCreate", objectOnCreate);


Andreas Großschedl (Unknown) 20.11.2010 19:55
Ok thank you Mr. Geiger! I see that the "level" is different. So I did it like this:

modName={};

function modName:onCreate(id)
-- some stuff
end;

modNameOnCreate=modName.onCreate;
now the function is in the "root" of my mod.

for the onCreate user attribute i do this: "modName.modNameOnCreate"



Linus Ek (Unknown) 26.11.2010 00:46
Neither of these work as expected.

Andreas way works the best because id in his solution is actually the id. Done in Stefan's way the id is a table. Stefan should be right because you is a giants employee.. So it's probably me doing it wrong. I dont wanna do it in Andreas way because I detected some conflict possibilitys that way.

I have two triggers but a triggered callback on number 1 activates a function on trigger number 2

So how to do it correctly?

Stefan Geiger - GIANTS Software 30.11.2010 10:51
Andreas way works only, if the name of the name is exactly as the code expects. If someone renames the zip file, it won't work anymore.


Linus, what is the string you used as the on create in the i3d?

modOnCreate.yourFunctionName or yourModName.yourFunctionName?

It needs to be modOnCreate.yourFunctionName, otherwise you basically end up in the same solution as the one of Andreas, and thus the first parameter is the instance of the mod, and the second parameter is the id.
The code by Andreas does not have a first parameter in the function, because de : in his code has the same meaning as
function modName.onCreate(self, id). It is just a simplification of the code. Semantically it is exactly the same.



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