Community Forum

Script compile error

Forum Overview >> Farming Simulator 2009

CategoryFarming Simulator 2009
Created08.08.2009 20:49


Jim Panousis (Jimi540) 08.08.2009 20:53
Hello guys!
I have a mod and i decided to write some script for it. So, i wrote a little lua to open a light but... i have this error in the log.txt:

[string "E:/Documents and Settings/Jimi/My Documents/My Games/FarmingSim..."]:64: '<name>' expected near 'M'
Error running lua function: init
[string "g_asd_tempSpec = zzz.MAN_silo"]:1: attempt to index global 'zzz' (a nil value)
Error running lua function: mouseEvent
[string "dataS/scripts/main.lua"]:246: attempt to call method 'mouseEvent' (a nil value)
Error running lua function: update
[string "dataS/scripts/main.lua"]:279: attempt to call method 'update' (a nil value)
Error running lua function: draw
[string "dataS/scripts/main.lua"]:294: attempt to call method 'render' (a nil value)
Error running lua function: update
[string "dataS/scripts/main.lua"]:279: attempt to call method 'update' (a nil value)
Error running lua function: draw
[string "dataS/scripts/main.lua"]:294: attempt to call method 'render' (a nil value)
Error running lua function: update
[string "dataS/scripts/main.lua"]:279: attempt to call method 'update' (a nil value)
Error running lua function: draw

and the 4 lines above continuing some times more. What's the problem with the mouseEvent?
I didn't wrote anything inside this function.
Just:
function bla bla bla
end;

B. Benjamin (Bayn_TSF3) 09.08.2009 13:37
Hello,

The error is not in the mouseEvent function but in your entire script. I don't know how to explain that because I'm just learning .lua, but when I had this in the log, I knew that I made a mistake somewhere in my script.
In your case, it seems this mistake is located at line 64 in your script. Try to have a look at this, or post your script.

I hope this will help you.
Best regards,
Bayn

Jim Panousis (Jimi540) 09.08.2009 15:24
Hello Bayn,
Thanks for your advice but nothing happens with many test in the script. So, this is the script:

MAN_silo = {};

function MAN_silo.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;

function MAN_silo:load(xmlFile)

self.extra_lights = {};
self.extra_lights.back_light = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.extra_lights.back_light#index"));

self.back_lightActive=false;
end;

function MAN_silo:keyEvent(unicode, sym, modifier, isDown)

if isDown and sym == Input.KEY_4 then
self.back_lightActive = not self.back_lightActive;
setVisibility(self.extra_lights.back_light, self.back_lightActive);
end;

if isDown and sym == Input.KEY_0 then
self.helpPanel = not self.helpPanel;
end;

end;

function MAN_silo:update(dt)
end;

function MAN_silo:draw()

if not self.helpPanel then
renderText(0.8335, 0.17, 0.02, "Help Panel: press 0 (NULL)");
else
renderText(0.8335, 0.17, 0.02, "Help Panel: press 0 (NULL)");
end;
if self.helpPanel then
renderText(0.7, 0.84, 0.025, "- MAN Silo Truck User panel-");
renderText(0.7, 0.815, 0.02, "Back help light : press 4");
end;

end;

function MAN_silo:onEnter()
end;

function MAN_silo:onLeave()
-- self.back_lightActive = false;
end;

function MAN_silo:delete()
end;

function MAN_silo:mouseEvent(posX, posY, isDown, isUp, button)
end;

In my .xml i have this:

<extra_lights>
<back_light index="12" />
</extra_lights>

The errors in the log.txt are these:

Mods are located at: E:/Documents and Settings/Jimi/My Documents/My Games/FarmingSimulator2009/mods
[string "E:/Documents and Settings/Jimi/My Documents/My Games/FarmingSim..."]:64: '<name>' expected near 'M'
Error running lua function: init
[string "dataS/scripts/SpecializationUtil.lua"]:41: attempt to call a nil value
Error running lua function: mouseEvent
[string "dataS/scripts/main.lua"]:246: attempt to call method 'mouseEvent' (a nil value)
Error running lua function: update
[string "dataS/scripts/main.lua"]:279: attempt to call method 'update' (a nil value)
Error running lua function: draw

Line 64 in the script is the: function MAN_silo:onEnter()
and the line 41 is the: function MAN_silo:update(dt)

I don't know if i must write something in these functions. I just want to open a back light. Please help.

Best Regards,
Jimi.

B. Benjamin (Bayn_TSF3) 09.08.2009 15:44
Hello,

Is this a script from LS 08 ?
self.rootNode needs to be replaced by self.components.

try this :

MAN_silo = {};

function MAN_silo.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;

function MAN_silo:load(xmlFile)

self.extra_lights = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.extra_lights#index"));
self.extra_lightsActive=false;
end;

function MAN_silo:keyEvent(unicode, sym, modifier, isDown)

if isDown and sym == Input.KEY_4 then
self.extra_lightsActive = not self.extra_lightsActive;
end;

if isDown and sym == Input.KEY_0 then
self.helpPanel = not self.helpPanel;
end;

end;

function MAN_silo:update(dt)

if self.extra_lightsActive then
setVisibility(self.extra_lights, true);
else
setVisibility(self.extra_lights, false);
end;
end;

function MAN_silo:draw()

if not self.helpPanel then
renderText(0.8335, 0.17, 0.02, "Help Panel: press 0 (NULL)");
else
renderText(0.8335, 0.17, 0.02, "Help Panel: press 0 (NULL)");
end;
if self.helpPanel then
renderText(0.7, 0.84, 0.025, "- MAN Silo Truck User panel-");
renderText(0.7, 0.815, 0.02, "Back help light : press 4");
end;

end;

function MAN_silo:onEnter()
end;

function MAN_silo:onLeave()
-- self.extra_lightsActive = false;
end;

function MAN_silo:delete()
end;

function MAN_silo:mouseEvent(posX, posY, isDown, isUp, button)
end;

And in the .xml file :
<extra_lights index="12" />

I hope it will work as I can't test it myself. ( And I didn't have a good level at scripting in .lua ^^ ).

Best regards,
Bayn

Jim Panousis (Jimi540) 09.08.2009 16:23
No Bayn, it didn't work.
So am i. I'm learning lua from others, so i started with something simple but i can't understand why the wrong is. The script is from LS09, so i must use rootnode. I'll try to make some experiments seeing another script to understand the way.
Thanks again,
Best regards!

B. Benjamin (Bayn_TSF3) 09.08.2009 18:33
What is the error in the log.txt ?
It's strange because I use this in one of my script and it works.

Jim Panousis (Jimi540) 09.08.2009 19:16
The error is this:

Mods are located at: E:/Documents and Settings/Jimi/My Documents/My Games/FarmingSimulator2009/mods
Error running lua function: init
[string "dataS/scripts/SpecializationUtil.lua"]:41: attempt to call a nil value
Error running lua function: mouseEvent
[string "dataS/scripts/main.lua"]:246: attempt to call method 'mouseEvent' (a nil value)
Error running lua function: update
[string "dataS/scripts/main.lua"]:279: attempt to call method 'update' (a nil value)
Error running lua function: draw
.
.
.
This error i see always with rootnode or components. But i think rootnode is the right.
I also have issues for this line:
return SpecializationUtil.hasSpecialization("something", specializations);
At the place of the "something" i'm seeing others to put motorized, others steerable.
I don't know which are the criteria from choosing the right. I tried different many times but nothing.

:( i don't know what to do.

Stefan Geiger - GIANTS Software 10.08.2009 09:20
Do you have any other mods installed? Is the mod called 'zzz' the mod you have posted the code of?

The log file says that there is a bug at line 64, however the code you posted of the MAN_silo only has 56 lines.

Jim Panousis (Jimi540) 10.08.2009 12:00
Hello Stefan,
Yes, i have 278 mod's installed and they are playing all. Only mine is problematic i think, nevertheless the code is so simple. I make some changes in the code and the line 64 is no more in the log file. Only this is in the log file:
-----------------------------------------------------------------------------------------
Mods are located at: E:/Documents and Settings/Jimi/My Documents/My Games/FarmingSimulator2009/mods
Error running lua function: init
[string "dataS/scripts/SpecializationUtil.lua"]:41: attempt to call a nil value
Error running lua function: mouseEvent
[string "dataS/scripts/main.lua"]:246: attempt to call method 'mouseEvent' (a nil value)
Error running lua function: update
[string "dataS/scripts/main.lua"]:279: attempt to call method 'update' (a nil value)
Error running lua function: draw
********************with the 4 last lines repeated many times************************
--------------------------------------------------------------------

From the previous script i delete some comments, that's why they are 56 lines. But the script with above errors is this exactly:
____________________________________________________________
MAN_silo = {};

function MAN_silo.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;

function MAN_silo:load(xmlFile)

self.back_light = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.back_light#index"));
self.back_lightActive = false;
self.helpPanel = false;

-- self.hudInfo = Utils.getFilename("hud_help_base.png", self.baseDirectory);
-- self.hudInfoPoxX = 0.012;
-- self.hudInfoPoxY = 0.1825;
-- self.hudInfoWidth = 0.425;
-- self.hudInfoHeight = 0.1625;
-- self.hudInfoOverlay = Overlay:new("hudInfoOverlay", self.hudInfo, self.hudInfoPoxX, self.hudInfoPoxY, self.hudInfoWidth, self.hudInfoHeight);

end;

function MAN_silo:keyEvent(unicode, sym, modifier, isDown)

if isDown and sym == Input.KEY_4 then
self.back_lightActive = not self.back_lightActive;
setVisibility(self.back_light, self.back_lightActive);
end;

if isDown and sym == Input.KEY_0 then
self.helpPanel = not self.helpPanel;
end;

end;

function MAN_silo:update(dt)

if self.isEntered then

-- WorklightBack
if self.back_lightActive then
setVisibility(self.back_light, self.back_lightActive);
else
setVisibility(self.back_light, self.back_lightActive, false);
end;

end;
end;

function MAN_silo:draw()

if not self.helpPanel then
renderText(0.8335, 0.17, 0.02, "Help Panel: press 0 (NULL)");
else
renderText(0.8335, 0.17, 0.02, "Help Panel: press 0 (NULL)");
end;
if self.helpPanel then
renderText(0.7, 0.84, 0.025, "- MAN Silo Truck User panel-");
renderText(0.7, 0.815, 0.02, "Back help light : press 4");
--renderText(0.7, 0.8, 0.02, "Heckscheibe: Taste 4");
--renderText(0.7, 0.785, 0.02, "Arbeitslicht vorne: Taste NUM4");
--renderText(0.7, 0.77, 0.02, "Arbeitslicht hinten: Taste NUM6");
--renderText(0.7, 0.755, 0.02, "Reifen wechseln: Taste 6");
--renderText(0.7, 0.74, 0.02, "Drehzahlbegrenzer niedriger: Taste NUM2");
--renderText(0.7, 0.725, 0.02, "Drehzahlbegrenzer hoeher: Taste NUM8");
end;

end;

function MAN_silo:onEnter()
end;

function MAN_silo:onLeave()

self.back_lightActive = false;
setVisibility(self.back_light, false);

end;

function MAN_silo:delete()

self.back_lightActive = false;
setVisibility(self.back_light, false);

end;

function MAN_silo:mouseEvent(posX, posY, isDown, isUp, button)
end;

--function key_convert(key)
-- if key ~= nil then
-- local keyname = "";
-- if key > 32 and key < 123 then
-- keyname = string.upper(string.char(key));
-- elseif key > 255 and key < 266 then
-- keyname = "NUM "..string.char(key-208);
-- else
-- keyname = "";
-- end;
-- return(keyname);
-- end;
--end;
_____________________________________________________________


The modDesc.xml has this:
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
<specialization name="MAN_silo" className="MAN_silo" filename="MAN_silo.lua"/>
</specializations>
<vehicleTypes>
<type name="MAN_silo" className="Vehicle" filename="$dataS/scripts/vehicles/Vehicle.lua">
<specialization name="motorized" />
<specialization name="attachable" />
<specialization name="trailer" />
<specialization name="steerable" />
<specialization name="hirable" />
<specialization name="MAN_silo"/>
</type>
</vehicleTypes>
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------

And the vehicle xml has this:

<back_light index="12" />


That's all folks. I can't see anything wrong. I hope you can help as you helped many guys.
Best Regards,
Jimi.

Michael Pillkahn - N/A 10.08.2009 21:50
in your :update

function setVisibility(integer transformId, boolean visibility)

you check with else and set ,false... 3rd argument?

i think you need in line 42 something like:
elseif not self.back_lightActive then

and using true and false

ELSE
you go back to your last running version and check your doing

Jim Panousis (Jimi540) 11.08.2009 17:47
Hello Michael,
You're right. I wrote this lines most for experiment. The third argument "false", was my fault, i didn't see it, but this is not the error. Because as i was said i'm learning. I think the problem is more general because the script is very simple and there is not some serious fault from the code side. As i'm continuing learning and reading tutorials and other posts i want to ask if i must set user attributes in my 3D model and then use them in the script like:

self.back_lightActive = false;

or

self.helpPanel = false;

I must create the back_lightActive attribute in my 3D model? And what about helpPanel?

I thought that i create them in the script like variables. Or that is doing only the "local" ???
Sorry for my "baby" questions but i want to learn.
Anyway, i'll continue searching and experiment. Thanks all for your help and proposals.

Regards,
Jimi

Stefan Geiger - GIANTS Software 13.08.2009 14:07
There is no script error in your script.

[string "dataS/scripts/SpecializationUtil.lua"]:41: attempt to call a nil value

This error message comes from some game script code. This might happen if the specialization part of your modDesc.xml is not correct.

How does it look like?

Jim Panousis (Jimi540) 14.08.2009 12:03
The modDesc.xml has this:
________________________________________________________________________________________
<specializations>
<specialization name="MAN_silo" className="MAN_silo" filename="MAN_silo.lua"/>
</specializations>
<vehicleTypes>
<type name="MAN_silo" className="Vehicle" filename="$dataS/scripts/vehicles/Vehicle.lua">
<specialization name="motorized" />
<specialization name="attachable" />
<specialization name="trailer" />
<specialization name="steerable" />
<specialization name="hirable" />
<specialization name="MAN_silo"/>
</type>
</vehicleTypes>
____________________________________________________________________________________

But i think the problem is here in the script:

function MAN_silo.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;

Motorized?
Isn't it?

Stefan Geiger - GIANTS Software 17.08.2009 09:41
Both your xml and the script excerpt look perfectly ok.


SpecializationUtil.hasSpecialization(Motorized, specializations);
returns true, if you have listed the Motorized in the list of specializations in the vehicle type part in the modDesc.xml, which is the case for your xml. If its not, there is a nice error message, and no error update function etc.


Have you ever removed all your mods, and then tried again? If not, you should do so. If it's still not working, can you send me the lua and modDesc.xml?

If it is, you should find the mod, that does not work together with your mod, by inserting the mods again, piece by piece.

Jim Panousis (Jimi540) 17.08.2009 16:10
Stefan, i had tried only with my mod and it couldn't load it. Only one mode, mine.
When i'm making comments the specialization part in the modDesc.xml, the first version without the script it works. But this is natural.
How can i send you the files?
At the licensing@giants-software.com ?

Jim Panousis (Jimi540) 29.08.2009 10:32
Hey Stefan!
Where are you? Vacations?
if I do not become indiscreet, where did you go? Maybe i was near by :)
Regards,
Jimi.

Stefan Geiger - GIANTS Software 01.09.2009 10:36
Hey, yes I was on vacations, a few days camping at Côte d&#8217;Azur and in barcelona ;)

You can send me your mod to (edited@edited.com)

Jim Panousis (Jimi540) 08.09.2009 10:31
Stefan i sent my mod to edited@edited.com
Did you get it or i typed the wrong email?

Stefan Geiger - GIANTS Software 08.09.2009 17:00
I worry that I accidentally deleted your mail, or you did type the wrong address.

Can you send it again?

Jim Panousis (Jimi540) 09.09.2009 20:28
I resent it yesterday to edited@edited.com
Cheers

Stefan Geiger - GIANTS Software 16.09.2009 17:55
I finally had the chance to test your mod. Everything works as it should, there's no error message except for the warning that the store.png could not be found, but that's an easy one.

Have you changed any files in the game directory? Maybe you should try with a clean install of the game and the patch 1.1

Jim Panousis (Jimi540) 16.09.2009 18:16
Hi, Stefan. Thanks for your time. I have a clean install of the game with the patch 1.1 right now, but it isn't working. I'll try a few times more. I had never any problem with the store.png. Thanks again.
Keep walking.
Jimi.


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