Currently Online

Latest Posts

Topic: Understanding Lua Scripts

toptopple
Avatar
Topic Opener
Joined: 2013-10-30, 08:11
Posts: 156
Ranking
At home in WL-forums
Posted at: 2016-06-16, 21:27

I like to understand Lua scripts better. For instance if we take the following function

  produce_spear = {
     -- TRANSLATORS: Completed/Skipped/Did not start forging a spear because ...
     descname = _"forging a spear",
     actions = {
        "return=skipped unless economy needs spear",
        "sleep=32000",
        "consume=coal iron planks",
        "play_sound=sound/smiths smith 192",
        "animate=working 45000",
        "play_sound=sound/smiths sharpening 120",
        "produce=spear"
     }
  },

1) "--" is a comment line? 2) How does "consume=coal iron planks" exactly work, including any programmed delays?


Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2434
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2016-06-16, 22:06

toptopple wrote:

1) "--" is a comment line?

Yes.

2) How does "consume=coal iron planks" exactly work, including any programmed delays?

This is just a list of wares which the building/worker consumes to produce the spear. Other weapons/tools may require more resources. F.e.you will find in empire/weaponsmithy:

produce_spear_war = {
         -- TRANSLATORS: Completed/Skipped/Did not start forging a war spear because ...
         descname = _"forging a war spear",
         actions = {
            "return=skipped unless economy needs spear_war",
            "sleep=32000",
            "consume=coal:2 gold iron:2 planks",

Producing a war spear will cost 2 coal, 1 gold, 2 iron and one plank.

Delays are managed through the values in "sleep=32000", and "animate=working 45000" (4500).

But i am not sure though face-smile.png


Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2016-06-18, 18:11

Some quick history: before we had Lua scripting, we had our own configuration file language. We invented the command syntax that is listed under actions back then and when we switched to Lua for configuration files, we had to keep this language (otherwise we would have to change the whole engine). So we have kinda a language embedded in Lua - unfortunate.

I think you should start skimming through the documentation which touches on Widelands engine and on scripting: https://wl.widelands.org/docs/wl/. For convenience, here are direct links:


Top Quote
toptopple
Avatar
Topic Opener
Joined: 2013-10-30, 08:11
Posts: 156
Ranking
At home in WL-forums
Posted at: 2016-06-19, 14:27

Thank you for the hints, I had a brief look at it!

I have developed in my spare time a script solution for what I regard the "notorious production delays" in the smelting-works and the various smithies! I found the current situation not desirable and even not intended. I filed a bug report long time ago but basically found the same situation again.

E.g. smelting-works: if you supply only iron ore (provided coal is amply available) you reach productivity of max. 70% which correlates to the 2 iron calls vs. 1 gold call in a single action round. Likewise I predict - though not tested - that you reach only 40 % productivity when only gold is supplied. Similar delays occur in the smithies which likewise produce multiple products in dependence of various input constraints.

In my solution both the smithies and the smelting-works operate incessantly, undelayed. The solution has a backlash as statistics don't work correctly and don't reflect the new industriousness. So statistics would have to be readjusted somehow. I can't add to the "how" because I don't understand them.

If you are interested in this solution I could open a separate thread for it. If on the other hand you say "no, this is ok as it is" then I will drop it.


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2016-06-20, 19:42

It would be interesting to have a link to the bug and to see your solution so far face-smile.png


Busy indexing nil values

Top Quote