Community Forum

UserAttribute on Map onCreate

Forum Overview >> Farming Simulator 2009

CategoryFarming Simulator 2009
Created05.07.2009 19:21


Heady Planet-ls (Headshot XXL) 05.07.2009 19:39
Hello,

my lua file is bind over the modDesc.xml:

<extraSourceFiles>
<sourceFile filename="Mapmilkstation.lua" />
</extraSourceFiles>

this is my script: http://team-flash.eu/Mapmilkstation.lua

this is the Userattribute Code from de Map01.i3d:

<UserAttribute nodeId="13542">
<Attribute name="grainePlane" type="string" value="0"/>
<Attribute name="onCreate" type="scriptCallback" value="Mapmilkstation.onCreate"/>
<Attribute name="playerTrigger" type="string" value="5"/>
<Attribute name="silo" type="string" value="2"/>
</UserAttribute>


does print: "Mapmilkstation loaded"
does not print: "created milk trigger, id:"
the script does not work in "function Mapmilkstation:update(dt)" (has lua erros --> "function Mapmilkstation:new(id, customMt)" not loaded)

why does not load the "Mapmilkstation.onCreate" onCreate scriptCallback ?


edit://

now i have changed the onCreate in the script: http://team-flash.eu/Mapmilkstation2.lua

and the userattributes:

<UserAttribute nodeId="13542">
<Attribute name="grainePlane" type="string" value="0"/>
<Attribute name="onCreate" type="scriptCallback" value="MapmilkstationonCreate"/>
<Attribute name="playerTrigger" type="string" value="5"/>
<Attribute name="silo" type="string" value="2"/>
</UserAttribute>

this is in the log:

created milk trigger, id: 22102
Error running lua function: MapmilkstationonCreate
[string "dataS/scripts/SpecializationUtil.lua"]:16: bad argument #1 to 'pairs' (table expected, got nil)
...
Error running lua function: update
[string "C:/Dokumente und Einstellungen/Headshot XXL..."]:101: attempt to index field 'trailerInSilo' (a nil value)

Stefan Geiger - GIANTS Software 06.07.2009 09:10
You are trying to do some mix between creating a new vehicle class and creating a new specialization class.

If you want to create a new vehicle class, you will have to define some more variables. At least instance.specializations = {}, which causes your error "[string "dataS/scripts/SpecializationUtil.lua"]:16: bad argument #1 to 'pairs' (table expected, got nil)". And you need to load the xmlFile variable.

If you are creating a new specialization, than there is no class:new method, there is a class:load(xml) which is called when the vehicle is created. However you must not call setmetatable, you directly can use self as the instance.

Heady Planet-ls (Headshot XXL) 06.07.2009 20:28
I have the Mod as a Vehicle too. I can this Vehicle buy on the trader with fully function.
But now i add the Mod in the Map with the GiantsEditor for a fix position and to variably position the single objects.

My postet script should be the script to call the Objekts from the Mod in the Map.
For reference i take the tipTrigger-script from Landwirtschafts-Simulator 2008.


Or do you have an idea for a script wich call the Mod that are added with the GiantsEditor to the Map?


Stefan Geiger - GIANTS Software 07.07.2009 09:00
It's ok then, if you remove the calls to callSpecializationsFunction, since this method is only used for specializations of vehicles. You can directly call self:setFillLevel2 etc.

The same for:
instance.onPlayerTrigger = Milkstation.onPlayerTrigger;
instance.onTrailerTrigger = Milkstation.onTrailerTrigger;
These are not needed.

Heady Planet-ls (Headshot XXL) 07.07.2009 20:41
i have the function calls removed, here is the changed script:
http://team-flash.eu/Mapmilkstation3.lua

but i have a lua error:

created milk trigger, id: 22102
Error running lua function: MapmilkstationonCreate
[string "C:/Dokumente und Einstellungen/Headshot XXL..."]:157: attempt to compare nil with number
Error running lua function: update
[string "C:/Dokumente und Einstellungen/Headshot XXL..."]:76: attempt to index field 'trailerInSilo' (a nil value)




Stefan Geiger - GIANTS Software 08.07.2009 08:41
You should remove customMt since you never specify the value of it. That means, you should only have
local instance = {};
setmetatable(instance, Mapmilkstation_mt);

Heady Planet-ls (Headshot XXL) 08.07.2009 17:43
There is only one error:

Error running lua function: update
[string "C:/Dokumente und Einstellungen/Headshot XXL..."]:70: attempt to index field 'trailerInSilo' (a nil value)

The instance variables will not be accepted.

Heady Planet-ls (Headshot XXL) 14.07.2009 22:33
Now i changed instance to Mapmilkstation and it works.

Thank you for your Support.


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