Latest Posts

Topic: Editor Extensions

Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 10:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2020-12-01, 15:10

Hello, first of all thanks for such a great game!! I've known and looked at Widelands for about the last 10 years now and was always happy to get a quick nostalgia fix. However now with more friends staying at home and playing online games at night we are staying longer than just for 5 games.

I got curious about creating my own maps then and spent some hours "painting" in the editor. It really felt like that and after i had 1 players area to my liking i could not go through with repeating the process for the others. I looked everywhere for some copy/paste capabilities but got nowhere. Well not nowhere, but to those threads that talk about map symmetry since about 2013. And boy those maps that 'gnarfk' made are REALLY hitting a nerv with me. I desperately want to play his hilbert curve map (the others too), but as soon as a geologist hammers at the >20 resource nodes the game crashes. I would love to repair it (it seems so easy) and adapt it for personal use but i cant see myself doing that 2 hours in the editor switching resource tools and sizes like a maniac.

So could anyone of you that know how to create a map by script share his/her knowledge or code here? May be release an editor extension or something like that? I would already be happy with a "repeat east" feature for X players. We are regularly between 3 to 7 so it would really help us if we could extend a map to the number of players that show up to play.

Edited: 2020-12-01, 15:24

Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-12-01, 16:14

Well, this is not that simple. Bottom line is that you can use LUA scripts to edit maps. Basically would create new empty map of expected size and using console (F6 button) you can execute your script.


Top Quote
Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 10:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2020-12-01, 17:24

thx for the advice i already tried F6 but nothing happened. i guess i need a development version? then write my own script from scratch? i am not a programmer, just always edited scripts to my own liking in other games, but i might manage. something like 1)extend map dimensions 2) go to first new point and set everything to the same as "50" points before, repeat 3) end when you reach 0,0 ??

Edited: 2020-12-01, 17:24

Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-12-01, 19:39

Yes, you would need development build

Syntax of LUA script is like:

f=base.map:get_field(0, 0)
f.terr='summer_meadow1'
f.resource='coal'
f.resource_amount=20
f.height=15
base.map:place_immovable('rocks', f, "world")

With this you can read and write, but what you probably cannot is to resize the map - but let others say

Also there should be some wiki about LUA somewhere.


Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-12-01, 19:39

Yes, you would need development build

Syntax of LUA script is like:

f=base.map:get_field(0, 0)
f.terr='summer_meadow1'
f.resource='coal'
f.resource_amount=20
f.height=15
base.map:place_immovable('rocks', f, "world")

With this you can read and write, but what you probably cannot is to resize the map - but let others say

Also there should be some wiki about LUA somewhere.


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 14:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2020-12-02, 09:49

The editor has a tool for map resizing, so you wouldn't need Lua for that.

For our scripting commands, see https://www.widelands.org/documentation/index.html


Busy indexing nil values

Top Quote
Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 10:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2020-12-21, 11:37

So i played around a little and got a simple print command to run from the console in mapeditor. (cant see it though because i dont know how to turn off the FPS counter)
I also got a *.lua file placed in the main Widelands directory to run. (the one where the exe is in)

So i tried running those lines you gave me but "f=base.map:get_field(0, 0)" is trying to INDEX a nil value (global 'base').
Trying to learn from the documentation here i changed it to ...wl.map:... but that is trying to CALL a nil value (method 'get_field').

And now i am lost again. I understand the script logic, but i got no idea how it is implemented.
Pease help.

Edited: 2020-12-21, 11:38

Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 19:48
Posts: 2439
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2020-12-21, 11:56

You have to use wl.Game().map:get_field(0,0).

Best is to take a look at some scenarios which are shipped with the game. You may find them in the subfolder campaigns below the datadir.

If you want to execute a script saved in a file from the debug console, you can do that by typing dofile("full/path/to/script.lua"). Not sure but i think on windows you have to use '/' as path delimiter here, not windows style '\'.


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

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 17:07
Posts: 1949
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-12-21, 12:15

kaputtnik wrote:

You have to use wl.Game().map:get_field(0,0).

In the editor, wl.Editor() needs to be used instead of wl.Game()


Top Quote
Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 10:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2020-12-21, 12:54

Yeah i learned that "dofile" from another post here, however i didnt care about any path, i just put it in the main dir. After all i am just trying to create a "simple" copy/paste script for map editing.
Yes i looked at the Island Hopping and the Atlantian water rising scripts too, but didnt find anything to help me (yet).

So trying to run f=wl.Game().map:get_field(0,0) --> attempt to call a nil value (field 'Game')

Sorry to bother you with error messages.

just saw the last post ... thanks

Edited: 2020-12-21, 12:55

Top Quote