Community Forum

using onCreate-function in LS15

Forum Overview >> Farming Simulator 15

CategoryFarming Simulator 15
Created20.09.2015 11:56


Thomas H. (Patar) 20.09.2015 12:03
Hello,

i want to set a lua-Script to an map-object.

So I first tried the codes like the standard-objectscripts from the documentation --> doesnt work
Then I tried the code from a other map-mod --> doesn`t work
After that I tried a code which I used for FS13 Map-Mod --> doesnt`t work.

My Code is like:


Football = {};
print("load Script: Football");
Football_mt = Class(Football, Object);
InitObjectClass(Football, "Football");


function Football.onCreate(id)
print("onCreate Football");
--g_currentMission:addUpdateable(Barrier:new(id));
end;

.......


that main-part works, so that "load Script: Football" appears in console, but the onCreate-Function did not work. At Giants-Editor I made a UserAttribute with

type "script Callback"
name "onCreate"
attribute "Football.onCreate"


But the print-Text from onCreate-Function won`t be printed...


Greetz Thomas

Emil Drefers (giants.edrefers) 21.09.2015 08:20
Hi,

you have to define the onCreate function outside of the Football class:

e.g.:

function onCreate(id)
print("onCreate Football");
end


Cheers,
Emil

Thomas H. (Patar) 28.09.2015 19:32
Thank you,

but i`ve now changed the code like that:

Football = {};
print("load Script: Football");
Football_mt = Class(Football, Object);
InitObjectClass(Football, "Football");


function onCreate(id)
print("onCreate Football");
--g_currentMission:addUpdateable(Barrier:new(id));
end;


but nothing happens... Like before, "load Script: Football" would be printed, but onCreate-Function doesnt work...

How should the Engine know that callback Football.onCreate should link to that onCreate-Function if there`s nothing before like "function Football:oncreate()" ?

Greetz,
Thomas

Emil Drefers (giants.edrefers) 29.09.2015 08:19
Hi,

here's an example from FS13:
http://fs-uk.com/mods/view/32103
Well, there's a bit more in it than what's actually needed, but it shows that the mentioned way works.

Probably you have just a small error somewhere, maybe just a typo ;)

The attributes line in the i3d should look like this:
<Attribute name="onCreate" type="scriptCallback" value="Football.onCreate"/>

Good luck and Cheers,
Emil


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