Important Dates

Latest Posts

Topic: Game Initialization

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, 19:07

Atanase wrote:

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

Lost in the djungle of init.lua-files face-grin.png

Writing scenarios (campaigns) is so troublesome... i am writing one for years now. From time to time i find some motivation to work further but after some time the motivation get lost again, just because it's so annoying to start the scenario from the beginning, find a failure, fix it, start the scenario again from the beginning, find the next failure, start again, check possible playeractions, find a failure again, fix it, and so on, and so on...


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, 20:40

Do you know the motto of Charles de Valois-Bourgogne, taken over by Guillaume d'Orange-Nassau?

There is no need to hope in order to undertake nor to succeed in order to persevere.

I agree. 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
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-20, 12:12

Hello,

It is not always easy to persevere. face-smile.png

The initialization of Economy work very well.
But ......
When I build anything, in fact when I build the road, the Economy turns back to "Default". Which really does not suit me at all, you could even say that it puts me in a dire situation. I start with a very limited supply of Logs and Irons and the blacksmith spoils it by crafting stuff that I don't need at this point in the game.
What can I do?


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-20, 12:22

I would guess you do it in the wrong order. When you connect two previously separate economies, each target setting can become either the first economy's target or the second economy's target. This is resolved by picking the target value which was least recently modified. If they were both modified at the same time, choice is arbitrary (but deterministic). So it seems there may be a problem with too-early or too-late setting of the target amounts.

Edit: If this does not help, please post the code with which the problem can be reproduced

Edited: 2021-04-20, 12:25

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-20, 14:11

But... When is the 'Default' economy initialized?

My initialization is made in file 'starting_conditions.lua' which is the first local include in 'init.lua'.
I deleted the file '../tribes/economy_profils/barbarians', but I got the same result.

I open the economy window, it is as I want it and the name is "-", I click to build a metal workshop, still good, I click on the flag of my headquarter to create the road and just then I see the economy go to 'default' .

To initialize I am using the syntax given by kaputtnik above. Just hq is global variable, not local.

Actually there is a lot of dust in my files. face-wink.png The .tar.bz2 is 1 Mo big. But if you want I can post it. 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-20, 14:22

The "Default" profile is not stored in the tribes/economy_profiles profiles but autogenerated by Widelands at runtime. It is used to default-initialize the target settings of every new economy. From your description I don't see why your procedure shouldn't work though, please upload the tarball 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-20, 15:19

It seemed to me that the 'Default' profile was not stored, I had looked at the file in question and had not found it, but when nothing else works we leave it to chance. face-smile.png face-smile.png

Enclose Atanase.zip

I had to try : .tar.bz2 and .tar.gz before to find that only .zip is allowed. face-wink.png

Edited: 2021-04-20, 15:20

Attachment:
Atanase.zip (1.0 MB)

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-20, 15:37

Okay, the reason for the strange behaviour results from the fact that your code is run outside of a coroutine. This is a bit non-standard so it may have bugs that do not occur otherwise. This way, all modifications happen at gametime 0 which is also the constant used to mark that a setting was never modified and can therefore be safely overwritten.
If you wrap your code in in a coroutine and add a very brief sleeptime as safeguard, like this:

run(function()
   sleep(1)
   include "map:scripting/starting_conditions.lua"
   include "map:scripting/texts.lua"
   include "map:scripting/utility_functions.lua"
   include "map:scripting/mission_thread.lua"
end)

then it works fine.


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-20, 16:56

Ok, thank you, it seems good now.

Until next time..... face-wink.png

I said you that I'm a real hunting dog to find problems that no one has ever seen. face-smile.png face-smile.png face-smile.png 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
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-20, 17:30

You won't end up hating me.

The economy remained as I wanted, perfect. The blacksmith made the three items I asked for (hammer, pick, felling ax)
and ... He made a 2nd pick that I didn't ask for. But no 2nd hammer or 2nd felling ax, just the pick in 2 copies when I only asked for one. face-smile.png face-smile.png
Why 2 Picks? Why not 2 Picks AND 2 Hammers?

Now he is at 0% activity while he still has enough in the forge to make 4 tools.

The purpose of all this is
1) to show the player how to recover resources in the workshops if they are needed elsewhere. So I have to manage to have enough in the forge to build a Lumberjacks Hut and a Quarry and have nothing in stock.
2) to show how we can play very finely by managing the Economies as accurately as possible.

Let's be Eco-friendly and avoid making 25 kitchen tools when we only have 3 big inns and only need 9 kitchen tools. face-smile.png face-smile.png

A true hound I said. face-wink.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