Important Dates

Latest Posts

Topic: Game Initialization

Atanase
Avatar
Topic Opener
Joined: 2021-04-15, 13:33
Posts: 126
Ranking
At home in WL-forums
Location: Béarn (France)
Posted at: 2021-04-18, 00:24

Hello,

I found out how to initialize 'stocks' with set_wares{} and set_workers{} but it is possible to initialize "Economy options"?

The economic profiles are not stored at the level of the map but above they cannot be forced manually.


La connaissance ne vaut que si elle est partagée par le plus grand nombre.
---------------------------------------
Knowledge is only valuable if it is shared by the greatest number.

Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2514
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2021-04-18, 10:06

Economy options can be set through out the game, not only during initialization.

According to the documentation enomy options can be accessed through a buildings flag properties ware_economy and worker_economy. Setting options can then be made through the functions of the class LuaEconomy

Something like this should work:

local hq = plr:place_building("empire_headquarters_shipwreck", wl.Game().map:get_field(20,50), false, true)
local ware_economy = hq.flag.ware_economy
ware_economy:set_target_quantity("scythe", 2)

local worker_economy = hq.flag.worker_economy
worker_economy:set_target_quantity("donkey", 0)

Top Quote
Atanase
Avatar
Topic Opener
Joined: 2021-04-15, 13:33
Posts: 126
Ranking
At home in WL-forums
Location: Béarn (France)
Posted at: 2021-04-18, 10:42

Ok, thank you.

I was hoping for a somewhat simpler system like the one that allows you to fill stocks. But never mind, I'll add all of this to my init.lua file. face-smile.png


La connaissance ne vaut que si elle est partagée par le plus grand nombre.
---------------------------------------
Knowledge is only valuable if it is shared by the greatest number.

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2724
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2021-04-18, 14:35

Atanase wrote:

Ok, thank you.

I was hoping for a somewhat simpler system like the one that allows you to fill stocks. But never mind, I'll add all of this to my init.lua file. face-smile.png

well, as far as I know you could use the set_target_quantity function like the set_wares function (meaning you can set multiple ware, quantity pairs at once) only thing is to identify the correct economy for the settings (widelands has economies for workers and economies for wares, later in the game you might have multiple economies as each separated warehouse which is not connected to another warehouse has its own economy)


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 2029
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2021-04-18, 14:39

well, as far as I know you could use the set_target_quantity function like the set_wares function (meaning you can set multiple ware, quantity pairs at once)

No, set_target_quantity supports setting the target for only 1 item at a time.


Top Quote
Atanase
Avatar
Topic Opener
Joined: 2021-04-15, 13:33
Posts: 126
Ranking
At home in WL-forums
Location: Béarn (France)
Posted at: 2021-04-18, 15:42

Hello,

Small explanation about this kind of questions that I sometimes ask.

Experience has taught me that some computer languages ​​initialize the variables at creation, others are content to reserve space without cleaning up. This sometimes leads to 'surprising' values ​​for these variables. So I got into the habit of always initializing the variables, even at 0, from their first use so as not to have any unpleasant surprises, whatever the method to use.

I "speak" nearly fluently : Enhanced basic, Fortran, Pascal, C, Prolog, 3 Asm languages and 1 I created for pleasure (not Cobol, I'm not so old) but no modern object oriented language, I'm not familiar with their syntax but I learn. face-wink.png

I will not ask such a question soon. face-smile-big.png

PS: Where can I find the list of the authorized variable I can use in this context ?

Edited: 2021-04-18, 15:49

La connaissance ne vaut que si elle est partagée par le plus grand nombre.
---------------------------------------
Knowledge is only valuable if it is shared by the greatest number.

Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2514
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2021-04-18, 17:01

PS: Where can I find the list of the authorized variable I can use in this context ?

I do not exactly understand your question, what 'authorized variable' refers to. I guess you mean the internal names of wares and so on? For tribe specific things you can find those internal names in our Encyclopedia. In the subpages there is a checkbox to show internal names.

For other things, like global map objects (Rocks, Trees, and so on) you have to dig into the corresponding init.lua files inside the directory /data.

If this does not answer the question, please ask again face-smile.png


Top Quote
Atanase
Avatar
Topic Opener
Joined: 2021-04-15, 13:33
Posts: 126
Ranking
At home in WL-forums
Location: Béarn (France)
Posted at: 2021-04-18, 17:50

Thank you but.... face-wink.png

There are holes in the "economy tables". This probably means that we cannot define values ​​for the missing 'objects'. I can try to force values ​​for all the internal names I found in the Encyclopedia and wait to see the errors generated by the program to remove, one by one, what it doesn't want to initialize, but it might take a long time and tedious, or find the list and initialize only those that are allowed. face-smile.png


La connaissance ne vaut que si elle est partagée par le plus grand nombre.
---------------------------------------
Knowledge is only valuable if it is shared by the greatest number.

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 2029
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2021-04-18, 18:06

You can set a target quantity for any (existing) ware or worker and it will not crash. But some items are hidden from the Configure Economy window because their target quantities are completely ignored. So you can set those as well, and it just has no visible effect. (Except that there might be some lines in the standard output "target quantity configured for ware log, which should not have target quantity, ignoring".)


Top Quote
Atanase
Avatar
Topic Opener
Joined: 2021-04-15, 13:33
Posts: 126
Ranking
At home in WL-forums
Location: Béarn (France)
Posted at: 2021-04-18, 18:31

Do you want the real purpose of it all?

In fact I am preparing a skeleton which will be used again for other 'maps' and other 'campaigns'. Perhaps it can even be used by others wishing to develop in Lua and who have been a little cooled by the research necessary to find the information. I won't tell you how many scripting directories I have already explored, you would be surprised, pleasantly I hope. face-wink.png

Also I prefer not to have 'parasitic' declarations in this template to avoid idle questions like: Why are my initializations not taken into account? from potential future users.

I am retired, so I have time to spend 8 to 12 hours a day on these programs. face-smile-big.png


La connaissance ne vaut que si elle est partagée par le plus grand nombre.
---------------------------------------
Knowledge is only valuable if it is shared by the greatest number.

Top Quote