Community Forum

Info Lua

Forum Overview >> Scripting

CategoryScripting
Created22.02.2015 13:36


Ludovic Fritz (mrludo40) 22.02.2015 13:37
hello is it possible the captured fruittype in lua like the "self : getAttachedTrailersFillLevelAndCapacity ();"

if so how to please
thank you

Emil Drefers (Unknown) 24.02.2015 09:11
Hi,

there are basically two variables which define what and how much is filled into a vehicle which has the Fillable specialization:

self.fillLevel
self.currentFillType

But there is no function which returns the fillTypes of all attached trailers.

Cheers,
Emil

Ludovic Fritz (mrludo40) 24.02.2015 12:20
thank you,
but have Fillable specialization can not install it on a tractor?


because after for captured fruits I use this snippet of code

Then if self.currentFillType == Fillable.FILLTYPE_WHEAT
massPerLiter = 0.780 ;
elseif self.currentFillType == Then Fillable.FILLTYPE_BARLEY
massPerLiter = 0.700 ;
elseif self.currentFillType == Then Fillable.FILLTYPE_MAIZE
etc ...


Emil Drefers (Unknown) 02.03.2015 11:50
Hi,

you can insert the Fillable specialization into a tractor or truck.
That should be no problem at all.

But your shown example code is massively wrong!

By the way, every fruit has a different "massPerLiter" by default.
The actual values are half of the real values ;)

Cheers,
Emil



Ludovic Fritz (mrludo40) 04.03.2015 06:35
ok thank you I'll test it

so my code is mass per liter

eg:
Local massPerLiter = 1.0 ; --1000 Liters ( density )

it 'll serve me to do a weight volume

Emil Drefers (Unknown) 20.06.2016 07:36
Hi,

the capacity is loaded by the Fillable specialization
http://ls-mods.de/scriptDocumentation.php?lua_file=vehicles/specializations/Fillable
and is available in the vehicle's table already ...
self.capacity
and
self.fillLevel
is there too. So you can easily claculate to what percentage the trailer is filled.

Personally, I have to say that I am not really sure if that approach will give you the desired behavior.
Well, it might just not feel that real. But I also might be completly wrong on that ...
Anyhow, have fun modding.

Cheers,
Emil

Brooks Kirschmann (Unknown) 20.06.2016 12:56
Thank you for your reply.
What other suggestions do you have?

How do I get the current the current value of the trailer's brakeforce and max speed into the LUA script?
I'm trying to understand if the self.* is necessary and to learn the syntax used in the LUA scripts.

Thanks again for the help.
I'm very new to scripting and trying to work my way through it.

Emil Drefers (Unknown) 21.06.2016 07:34
Hi,

the "self" is mostly unavoidable.
Well, in the end it depends on how you implement the solution.

Assuming you write another specialization, it is unavoidable.

The current brakeForce is already present ...
just search for "brakeForce" in the "Attachable" specialization:
http://ls-mods.de/scriptDocumentation.php?lua_file=vehicles/specializations/Attachable

A trailer has by default no speedLimit ... how should it? It all depends on the tractor.
(Not sure, if there are any trailers IRL whcih brake if they get pulled faster than X km/h ... but, I don't think so)

Cheers,
Emil





Brooks Kirschmann (Unknown) 26.06.2016 20:26
Here is my lua file. I am trying to get the fill level, the capacity, the brake speed, and the max speed of the trailer this is added to. I am not able to get a value other than nil when I print out the variables. What am I doing wrong? Most of my variables are there because I've been trying different ways of getting the information but not having any success.

CapacitySpeed = {};


function CapacitySpeed.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(Trailer, specializations);
end;

function CapacitySpeed:load(xmlFile)
local getFillLevel = Fillable.getFillLevel;
local Capacity = Fillable.getCapacity;
local PowerConsumption = Utils.getNoNil(getXMLInt(xmlFile, xmlKey .. "PowerConsumer#neededPtoPower"), 0);
local Speed = Utils.getNoNil(xmlFile,"CapacitySpeed.speedLimit");
local name = Utils.getNoNil(xmlFile, "vehicle#filename");
local brakeForce = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.brakeForce"), 0)*10;

end;

Emil Drefers (Unknown) 27.06.2016 07:57
Hi,

your second line is pretty dangerous:
Fillable = {};
with that you overwrite a complete class and empty it ... not quite that what you want, right?

Did you make sure that your new specialization is loaded?
(Adding prints is very helpful)


---
local PowerConsumption = Utils.getNoNil(getXMLInt(xmlFile, xmlKey .. "PowerConsumer#neededPtoPower"), 0);

Should give you a valid value which is unequal to nil.
But you need to define the "xmlKey" to get the actual value in the "xmlFile".


Cheers,
Emil



Brooks Kirschmann (Unknown) 27.06.2016 16:01
Emil
Here is my entire script.
CapacitySpeed = {};

function CapacitySpeed:load(xmlFile)
local getFillLevel = Fillable.getFillLevel;
local Capacity = Fillable.getCapacity;
local PowerConsumption = Utils.getNoNil(getXMLInt(xmlFile, xmlKey .. "PowerConsumer#neededPtoPower"), 0);
local Speed = Utils.getNoNil(xmlFile,"CapacitySpeed.speedLimit");
local name = Utils.getNoNil(xmlFile, "vehicle#filename");
local brakeForce = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.brakeForce"), 0)*10;
end;

print("Capacity Speed is registering!")

Samuel H. (modelleicher) 27.06.2016 16:28
I hope its okay if i take a shot at answering a few of the questions?

To dumb things down:
1. self is a table including every variable and table (and function) the particular vehicle has. (all not local variables etc. from all specializations the vehicle has including the variables etc. within the vehicle.lua)
Meaning, self.fillLevel can be accessed in every specialization within the trailer itself, not just the Fillable specialization. So assuming your CapacitySpeed script is a specialization of a trailer you can just access self.fillLevel and self.capacity ect. directly to get those values.

Variables and tables are accessed as self.variable and self.table whilest functions are accessed as self:function()

2. xmlKey
xmlKey is nothing but a local variable that has the path to the xml key stored. Its not neccessary and is usually used when the same xml key is needed a lot.
example:
local xmlKey = "vehicle.capacitySpeed"
local speed = getXMLFloat(xmlFile, xmlKey.."#speedLimit");
local otherValue = getXMLFloat(xmlFile, xmlKey.."#otherValue");
-- a bunch of other values

It is exactly the same as
local speed = getXMLFloat(xmlFile, "vehicle.capacitySpeed#speedLimit");

The whole thing is the exact path to the value within the XML File:
<vehicle>
<capacitySpeed speedLimit="VALUE" />
</vehicle>
As every vehicle XML has vehicle as its main tag every xml key starts with vehicle.

This probably doesn't answer all the questions but maybe it helps you understand two main issues you have with your code right now ;)

greetings,
modelleicher






Brooks Kirschmann (Unknown) 28.06.2016 13:33



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