Using relative paths in quotes

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
Yutmeal2
Posts: 13
Joined: October 14th, 2017, 3:02 am

Using relative paths in quotes

Post by Yutmeal2 »

Hi. I try to make a template for a multiplayer campaign for testing scripts.

I want to make renaming the campaign as easy as possible.

So, I try to use macros. But I can't quite figure out if it is ok to use macro within quotes.

If I can use relative paths for everything instead of using macros, it would be even better. But I don't know if that is possible.

_main.cfg:

Code: Select all

#textdomain wesnoth-Blank_MP_Scenario

#define SCENARIO_NAME 
Blank_MP_Scenario#enddef

#define LD __PATH__ 
{~add-ons/{SCENARIO_NAME}/{__PATH__}}#enddef

[textdomain]
    name="wesnoth-{SCENARIO_NAME}"
    path="{LD translations}"
[/textdomain]

#ifdef MULTIPLAYER
[binary_path]
    path="data/add-ons2/{SCENARIO_NAME}"
[/binary_path]

[lua]
    code = << wesnoth.message '>>+"wesnoth-{SCENARIO_NAME}"+<<>>'
[/lua]

{LD scenarios/main.cfg}
#endif

Last edited by Yutmeal2 on October 16th, 2017, 2:26 am, edited 1 time in total.
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Quoted path containing macros

Post by Ravana »

There is support for relative paths https://wiki.wesnoth.org/PreprocessorRe ... inclusions.
Yutmeal2
Posts: 13
Joined: October 14th, 2017, 3:02 am

Re: Quoted path containing macros

Post by Yutmeal2 »

Thanks, Ravana. I changed all includes to:

Code: Select all

{./<relative Path>}
It seems that something like this in "scenario/main.cfg" works:

Code: Select all

map_data="{LD maps/map0.map}"
Setting variable doesn't work:

in main.cfg:

Code: Select all

[set_variable]
    name=scenario_name
    value="Blank_MP_Scenario"
[/set_variable]
[set_variable]
    name=homedir
    value="~add-ons/"+$scenario_name+"/"
[/set_variable]
in scenario/main.cfg:

Code: Select all

[multiplayer]
  id=multiplayer_Blank_Scenario
  name= _ "2p — Blank Scenario"
  map_data=$homedir+"map/map0.map"
...
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Using relative paths in quotes

Post by zookeeper »

That's because variables aren't substituted in places like [multiplayer] map_data=, or probably any other top-level scenario keys like that.

But if your only goal is to make it easier to rename the campaign, then just get a tool that can perform text-based search-and-replace in a whole directory; there's no real need to complicate your code to allow a change like that to happen in one place. For example, I use a program called grepWin for exactly those kinds of tasks, and I rarely require anything more.
Post Reply