[Formula Language] $($var1 - 1 + $var2) does not evaluate
Moderator: Forum Moderators
Forum rules
Before reporting issues in this section, you must read the following topic:
Before reporting issues in this section, you must read the following topic:
[Formula Language] $($var1 - 1 + $var2) does not evaluate
(it's possible this is just user error and either the - or + operator is overloaded, but if so it's still confusing)
$($var1 - 1 + $var2) does not evaluate, even when $($var1 - 1 - -$var2) does evalulate.
Reproduction steps:
Simply put this in your scenario.cfg and run the scenario
The first message will be blank, the second will not
OS: Windows 11
Build info:
$($var1 - 1 + $var2) does not evaluate, even when $($var1 - 1 - -$var2) does evalulate.
Reproduction steps:
Simply put this in your scenario.cfg and run the scenario
Code: Select all
[event]
name = prestart
id = test
[store_map_dimensions]
[/store_map_dimensions]
[message]
message = $($map_size[0].height - 1 + $map_size[0].height)
[/message]
[message]
message = $($map_size[0].height - 1 - -$map_size[0].height)
[/message]
[/event]
OS: Windows 11
Build info:
The Battle for Wesnoth version 1.16.1 x86_64
Running on Microsoft Windows 11 21H2 (10.0.22000) x86_64
Distribution channel: Steam
Game paths
==========
Data dir: C:\Program Files (x86)\Steam\steamapps\common\wesnoth
User config dir: C:\Users\USER\OneDrive\Documents\My Games\Wesnoth1.16
User data dir: C:\Users\USER\OneDrive\Documents\My Games\Wesnoth1.16
Saves dir: C:\Users\USER\OneDrive\Documents\My Games\Wesnoth1.16\saves
Add-ons dir: C:\Users\USER\OneDrive\Documents\My Games\Wesnoth1.16\data\add-ons
Cache dir: C:\Users\USER\OneDrive\Documents\My Games\Wesnoth1.16\cache
Libraries
=========
Boost: 1.74
Lua: 5.4.2
OpenSSL/libcrypto: 1.1.1i (runtime 1.1.1i)
Cairo: 1.17.4 (runtime 1.17.4)
Pango: 1.48.0 (runtime 1.48.0)
SDL: 2.0.12 (runtime 2.0.12)
SDL_image: 2.0.5 (runtime 2.0.5)
SDL_mixer: 2.0.4 (runtime 2.0.4)
Features
========
Lua console completion: yes
Win32 notifications back end: yes
Current video settings
======================
SDL video drivers: [windows] dummy
Window size: 1707x1067
Screen refresh rate: 165
Screen dots per inch: 96.000000x96.000000
Screen dpi scale factor: 1.000000x1.000000
Current audio settings
======================
SDL audio drivers: [wasapi] directsound
Number of channels: 2
Output rate: 44100 Hz
Sample format: signed 16 bit little-endian
Sample size: 4096 bytes
Installed add-ons
=================
1The_Great_Steppe_Era: 1.2.3c
1The_Great_Steppe_Music: 0.1.4
A_Random_RPG_Adventure: 1.16.220110e
Advance_Wesnoth_Wars: 1.14.15.3
BloodLust: 0.6.3
Dungeons_of_Wesnoth: 0.61.0 Beta
Era_of_Magic: 3.5.2a
Era_of_Magic_Resources: 1.2.3
Inky_Quest: 1.6.0
Legend_of_the_Invincibles: 3.2.7b
PSR_Wesmoba: 1.16.211027
TOPGUN_Addon: 0.1.16
To_Lands_Unknown: 3.5.4
To_Lands_Unknown_Resources_1: 1.7.0
To_Lands_Unknown_Resources_2: 1.6.0
Unto_Others: 1.0.1
WML_Guide: 1.0.0
desertwar_addon: 0.2.2
Re: [Formula Language] $($var1 - 1 + $var2) does not evaluate
I've seen this before, unfortunately I can't remember where. They had to do - - to get around it as well.
Putting quotes around the expression seems to fix it though.
message = "$($map_size[0].height - 1 + $map_size[0].height)"
Without the quotes this error is produced.
Code: Select all
error engine: Formula in WML string cannot be evaluated due to Could not parse expression
Re: [Formula Language] $($var1 - 1 + $var2) does not evaluate
I think the problem is that the
+
operator is used in WML for string concatenation.I think this is working as documented in the Wiki:
https://wiki.wesnoth.org/SyntaxWML#Special_Attribute_Values wrote: ...string concatenation is performed with the plus sign (+
). If a plus sign appears outside quotes in a value, it means that the string/value on its right will be appended to the string/value on its left. To have an actual plus sign in a value, the string containing the+
character must be surrounded by quotes...
Re: [Formula Language] $($var1 - 1 + $var2) does not evaluate
So + is always string + and not mathematical + unless it's inside quotes? In most languages with operator overloading, which method is performed depends on what types of parameters are given, not having quotes around it. Or is $map_size[0].height actually a string, not a number?
Re: [Formula Language] $($var1 - 1 + $var2) does not evaluate
If you come from common programming language background then consider using Lua instead of formulas.
Re: [Formula Language] $($var1 - 1 + $var2) does not evaluate
WML is not really like most programming languages, it is closer to a markup language like XML or HTML. To the WML parser, every attribute value is just a string. The WML parser may perform string concatenation (with theBobit wrote: ↑January 13th, 2022, 6:38 pm So + is always string + and not mathematical + unless it's inside quotes? In most languages with operator overloading, which method is performed depends on what types of parameters are given, not having quotes around it. Or is $map_size[0].height actually a string, not a number?
+
operator) and/or translation (with the _
operator) but it doesn't know anything about formulas - formula evaluation will take place later, after the WML parsing stage.