Correct string to user content

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
zorroot
Posts: 5
Joined: August 23rd, 2019, 12:12 pm

Correct string to user content

Post by zorroot »

Hello Wesnoth community,
I know Wesnoth since many years and have played some of the campaigns. Now I would like to go a bit further and create my own maps and scenarios. Doing this, I encoutered a problem.
I have created a map named k1 and saved it here: "C:\Users\Oliver\Documents\My Games\Wesnoth1.14\editor\maps\k1.map"
I have created a scenario s01 and saved it here: "C:\Users\Oliver\Documents\My Games\Wesnoth1.14\editor\scenarios\s01.cfg"

Within the sceanrio file, I use this statement.

Code: Select all

map_data="Gg, Gg, …"
No problem, everything is fine.

When I use this statement instead

Code: Select all

map_data="k1.map"
I get an error message whenever I try to start a local multiplayer game.
I have tried these statements, too. But all do throw the same error message.
map_data=maps/k1.map
map_data=/maps/k1.map
map_data=editor/maps/k1.map
map_data=/editor/maps/k1.map
map_data="C:\Users\Oliver\Documents\My Games\Wesnoth1.14\editor\maps\k1.map"

So what statement do I have to use to get it right ?
Please note that I am using Wesnoth on a Windows 10 64-bit System.

https://drive.google.com/file/d/1PaTzEG ... sp=sharing
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Correct string to user content

Post by Pentarctagon »

It should be map_data="{path/to/k1.map}". From mainline, for example: map_data="{multiplayer/maps/2p_Aethermaw.map}".
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Correct string to user content

Post by Ravana »

You should instead use map_file if you have path to file
https://github.com/wesnoth/wesnoth/issues/3357
zorroot
Posts: 5
Joined: August 23rd, 2019, 12:12 pm

Re: Correct string to user content

Post by zorroot »

First of all, thx for yours answers.

Second, none of the answers were solving the problem. But after some extensive tests, they led to the answer :-)

Whenever I put the map file into the user data directory, it is recognised by the map editor but it is NEVER recognised by the scenario file.
Whenever I put the map file into the game data directory, it is ALWAYS recognised by the scenario file.
My logical conclusion is that the user data directory is excluded from the Wesnoth search path while the scenario file is being parsed. Can someone please check if he is also affected by this problem ?
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Correct string to user content

Post by Pentarctagon »

You should probably read this page, I think.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Correct string to user content

Post by Celtic_Minstrel »

You might be able to get it to work with map_file="../maps/k1.map"? But I think the best option here is to actually create a proper addon, as described by Pentarctagon's link.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
zorroot
Posts: 5
Joined: August 23rd, 2019, 12:12 pm

Re: Correct string to user content

Post by zorroot »

Well, I think I have to give you much more info.
1. I dont want to publish my user made content at the moment. I am fully aware that if I want to publish it, I have to create an add-on, follow the guidelines, etc.
2. I dont want to use translateable strings. This makes things a little bit easier as I dont need to create a translation file and I dont need to specify a textdomain.

A. To test things out, I have made this little scenario 'scenariotest1.cfg' and saved it at userdata/editor/scenarios. Here is the content.

Code: Select all

current_time=0
description=""
experience_modifier=70
id="scenariotest1"
map_data="Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Ce, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Ce, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Ce, 1 Kh, Ce, Gg, Gg, Gg, Gg, Gg, Ce, 2 Kh, Ce, Gg, Gg, Gg
Gg, Gg, Gg, Ce, Ce, Ce, Gg, Gg, Gg, Gg, Gg, Ce, Ce, Ce, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Ce, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Ce, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Ce, 4 Kh, Ce, Gg, Gg, Gg, Gg, Gg, Ce, 3 Kh, Ce, Gg, Gg, Gg
Gg, Gg, Gg, Ce, Ce, Ce, Gg, Gg, Gg, Gg, Gg, Ce, Ce, Ce, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg
Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Gg
"
name="scenariotest1"
victory_when_enemies_defeated=yes
[time]
	blue=0
	green=-15
	id="dawn"
	image="misc/time-schedules/default/schedule-dawn.png"
	lawful_bonus=0
	name=_"Dawn"
	red=-25
	sound="ambient/morning.ogg"
[/time]
[time]
	blue=0
	green=0
	id="morning"
	image="misc/time-schedules/default/schedule-morning.png"
	lawful_bonus=25
	name=_"Morning"
	red=0
[/time]
[time]
	blue=0
	green=0
	id="afternoon"
	image="misc/time-schedules/default/schedule-afternoon.png"
	lawful_bonus=25
	name=_"Afternoon"
	red=0
[/time]
[time]
	blue=-35
	green=-20
	id="dusk"
	image="misc/time-schedules/default/schedule-dusk.png"
	lawful_bonus=0
	name=_"Dusk"
	red=10
	sound="ambient/night.ogg"
[/time]
[time]
	blue=-13
	green=-45
	id="first_watch"
	image="misc/time-schedules/default/schedule-firstwatch.png"
	lawful_bonus=-25
	name=_"First Watch"
	red=-75
[/time]
[time]
	blue=-13
	green=-45
	id="second_watch"
	image="misc/time-schedules/default/schedule-secondwatch.png"
	lawful_bonus=-25
	name=_"Second Watch"
	red=-75
[/time]
This scenario is working fine. Due to this, my first questions are:
Do I have to create an add-on for every scenario or is it just optional ?
If you answer that an add-on is a must-have, why is my sceanrio working without one ?



B.

Now I do the following:
I take the map string and put it into a new file named 'maptest.map' and save it at userdata/editor/maps. The map file can be loaded, changed and saved by the map editor so everything is fine.
I create another scenario, name it 'scenariotest2.cfg' and saved it at userdata/editor/scenarios. Here is the content.

Code: Select all

current_time=0
description=""
experience_modifier=70
id="scenariotest2"



#map_data="maptest.map"
#map_data="maps/maptest.map"
#map_data="editor/maps/maptest.map"
#map_data="{maptest.map}"
#map_data="{maps/maptest.map}"
#map_data="{editor/maps/maptest.map}"

#map_file="maptest.map"
#map_file="maps/maptest.map"
#map_file="editor/maps/maptest.map"
#map_file="{maptest.map}"
#map_file="{maps/maptest.map}"
#map_file="{editor/maps/maptest.map}"

#map_data="../maptest.map"
#map_data="../maps/maptest.map"
#map_data="../editor/maps/maptest.map"
#map_data="../{maptest.map}"
#map_data="../{maps/maptest.map}"
#map_data="../{editor/maps/maptest.map}"

#map_file="../maptest.map"
#map_file="../maps/maptest.map"
#map_file="../editor/maps/maptest.map"
#map_file="../{maptest.map}"
#map_file="../{maps/maptest.map}"
#map_file="../{editor/maps/maptest.map}"

#map_data="data/add-ons/maptest.map"
#map_data="{data/add-ons/maptest.map}"

#map_file="data/add-ons/maptest.map"
#map_file="{data/add-ons/maptest.map}"

#map_data="userdata/add-ons/maptest.map"
#map_data="{userdata/add-ons/maptest.map}"

#map_file="userdata/add-ons/maptest.map"
#map_file="{userdata/add-ons/maptest.map}"

#None of the above paths are working.



name="scenariotest2"
victory_when_enemies_defeated=yes
[time]
	blue=0
	green=-15
	id="dawn"
	image="misc/time-schedules/default/schedule-dawn.png"
	lawful_bonus=0
#textdomain wesnoth-help
	name=_"Dawn"
	red=-25
	sound="ambient/morning.ogg"
[/time]
[time]
	blue=0
	green=0
	id="morning"
	image="misc/time-schedules/default/schedule-morning.png"
	lawful_bonus=25
	name=_"Morning"
	red=0
[/time]
[time]
	blue=0
	green=0
	id="afternoon"
	image="misc/time-schedules/default/schedule-afternoon.png"
	lawful_bonus=25
	name=_"Afternoon"
	red=0
[/time]
[time]
	blue=-35
	green=-20
	id="dusk"
	image="misc/time-schedules/default/schedule-dusk.png"
	lawful_bonus=0
	name=_"Dusk"
	red=10
	sound="ambient/night.ogg"
[/time]
[time]
	blue=-13
	green=-45
	id="first_watch"
	image="misc/time-schedules/default/schedule-firstwatch.png"
	lawful_bonus=-25
	name=_"First Watch"
	red=-75
[/time]
[time]
	blue=-13
	green=-45
	id="second_watch"
	image="misc/time-schedules/default/schedule-secondwatch.png"
	lawful_bonus=-25
	name=_"Second Watch"
	red=-75
[/time]
I remove the # tag from the first line with a map_data tag and save it. Then I start Wesnoth, create a new local multiplayer game and check if it works. I close Wesnoth, put a # in front of the first line with a map_data tag and remove the # from the second line with a map_data tag. So in total I was checking 32 different map_data or map_file tags. None of them worked. Some of them threw another error message.
https://drive.google.com/file/d/1Y3T5ad ... sp=sharing


After being frustrated and exhausted to the fullest, I just read some others people scenario files. Then an idea came to my mind. Just break the rules and put my map directly to the game folder: 'data/campaigns/campaigntest'. I deleted all map_data and map_file tags from scenariotest2.cfg and added this line

Code: Select all

map_data="{campaigns/campaigntest/maptest.map}"
Bingo !!! The sceanrio works now !!!!!
Can someone please explain this behavior to me ?
Thx a lot.
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Correct string to user content

Post by Pentarctagon »

I suppose structuring your scenario like a proper add-on isn't technically required, but you don't have to follow any sort of guidelines if you don't upload it. Following a normal add-ons structure will also make it a lot easier to do pretty much everything else though, including answering questions about it.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
Shiki
Developer
Posts: 348
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: Correct string to user content

Post by Shiki »

For preprocessor calls (that's everything using curly braces):
{some/file.cfg} will look for files or directories located in the data folder of the main game.
{~some/file.cfg} will look for files in the data folder of the users stuff. This one is often used in add-ons, but it cannot reach the editor folder as it is no subdirectory.

{./some/file.cfg} starts looking in the same directory as the file is. It's the only way to read another file not being in an add-on or the main game via the preprocessor. Probably what you want. — But, also here you can only load a file in a subdirectory.

{../some/file.cfg} is not supported (just mentioning for completeness. .. is a way to reach the directory below in unix systems.)


The preprocessor is essentially reading what is written in a file and inserts it at the place it is called. It's used with map_data.
map_file is not using the preprocessor (no curly braces), thus the above rules don't have to be the same. But you can try out the 4 ways above without curly braces, it's likely that the rules are similar or the same.

According to the file you posted .. also doesn't work here, so you can only load subdirectories (probably to avoid add-ons reading you non-wesnoth files). What you can do though is to learn about symlinks (or hardlinks) – that way a file can exist in multiple directories. That's an OS level thing, and on Microsoft Windows it requires admin privileges.

Edit: The preprocessor is documented here, the above in section 2.4: https://wiki.wesnoth.org/PreprocessorRef
Try out the dark board theme.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Correct string to user content

Post by Celtic_Minstrel »

If you want to save your scenario in userdata/editor/scenarios, I suspect it must all be self-contained in a single file. So, if you copy-paste the contents of maptest.map into those quotes, I think that would work.

Preprocessor inclusion in a scenario in userdata/editor/scenarios might be able to pick up files in the same folder, so you could also try moving maptest.map to that folder and including it as map_data={./maptest.map}, You certainly won't be able to include anything from userdata/editor/maps though, since that lies outside the WML "virtual filesystem" (as does userdata/editor/scenarios).
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
zorroot
Posts: 5
Joined: August 23rd, 2019, 12:12 pm

Re: Correct string to user content

Post by zorroot »

Dear Shiki, dear Celtic, thx for your help. Your answers were exactly what I was looking for. I saved my map file to

Code: Select all

userdata/editor/scenarios/smaps/maptest.map
From the sceanrio file, I can refer to the map by using

Code: Select all

map_data="{./smaps/maptest.map}"
I will go on studying some of the built-in campaigns to become firm with the WML tags.
Post Reply