WFL formula error FIXED
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.
- Spannerbag
- Posts: 761
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
WFL formula error FIXED
Edit: Subject changed.
Hi,
I was changing working code (as you I do) and managed to generate a WFL error when the macro containing the WFL is called (i.e. the error appears on screen during gameplay).
The error is:
So I replaced the WFL with WML and it works fine.
Can WFL handle 2 variables?
I suspect it cannot because previously the WFL still had 3 terms but
I
Happy to use WML, just curious what I'm doing wrong?
Cheers!
-- Spannerbag
Hi,
I was changing working code (as you I do) and managed to generate a WFL error when the macro containing the WFL is called (i.e. the error appears on screen during gameplay).
The error is:
Code: Select all
error scripting/lua: Formula error in formula:1
In formula +
Error: Illegal unary operator: '+'
stack traceback:
[C]: in field 'compile_formula'
lua/wml/set_variable.lua:160: in local 'cmd'
lua/wml-utils.lua:145: in field 'handle_event_commands'
lua/wml-flow.lua:37: in local 'cmd'
lua/wml-utils.lua:145: in field 'handle_event_commands'
lua/wml-flow.lua:19: in local 'cmd'
lua/wml-utils.lua:145: in field 'handle_event_commands'
lua/wml-flow.lua:206: in local 'cmd'
lua/wml-utils.lua:145: in field 'handle_event_commands'
lua/wml-flow.lua:5: in function <lua/wml-flow.lua:4>
[C]: in ?
[C]: in field 'fire'
lua/wml-tags.lua:151: in local 'cmd'
lua/wml-utils.lua:145: in field 'handle_event_commands'
lua/wml-flow.lua:5: in function <lua/wml-flow.lua:4>
[C]: in ?
Code: Select all
{VARIABLE extra_fog_x $this_item.x}
{VARIABLE_OP extra_fog_x add $fog_range}
{VARIABLE_OP extra_fog_x add 2}
# [set_variable]
# name=extra_fog_x
# formula="$this_item.x + $fog_range + 2"
# [/set_variable]
I suspect it cannot because previously the WFL still had 3 terms but
$fog_range
was an integer constant: {FOG_RANGE}
and it worked OK then, adding the second $variable seemed to consufe it...I
:inspect
ed $fog_range
and it has the expected (correct) value - actually same as {FOG_RANGE}
.Happy to use WML, just curious what I'm doing wrong?
Cheers!
-- Spannerbag
Last edited by Spannerbag on July 15th, 2024, 7:38 pm, edited 1 time in total.
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: WFL formula error
"Unexpected unary operator +" means you've got a + sign without two arguments. Like " + 3" instead of "x + 3".
Probably because $fog_range is nil, and maybe $this_item is as well.
I suck at WFL, but don't you have to use $ for variable substitution? Looks to me like you're trying to use WML variables in a WFL.
value = $($this_item.x + $fog_range + 2) # MAYBE???
Probably because $fog_range is nil, and maybe $this_item is as well.
I suck at WFL, but don't you have to use $ for variable substitution? Looks to me like you're trying to use WML variables in a WFL.
value = $($this_item.x + $fog_range + 2) # MAYBE???
Speak softly, and carry Doombringer.
- Spannerbag
- Posts: 761
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: WFL formula error
Ok, will try that ...white_haired_uncle wrote: ↑July 15th, 2024, 7:25 pm ...
foo = $($this_item.x + $fog_range + 2) # MAYBE???
...
Yep, fixed!
Thanks!
(Should've thought of that myself

Cheers!
-- Spannerbag
Re: WFL formula error FIXED
In
For a key that is specifically documented to contain a formula you don't need any other syntax. The
formula="$this_item.x + $fog_range + 2"
there is no formula variable at all. There are two WML variables that get expanded into the formula. If that results in an invalid formula then you'll get an error.For a key that is specifically documented to contain a formula you don't need any other syntax. The
key=$(formula)
syntax should work for any key that is not documented to contain a formula but supports variables. (https://wiki.wesnoth.org/SyntaxWML#Spec ... ute_Values)"If gameplay requires it, they can be made to live on Venus." -- scott
- Spannerbag
- Posts: 761
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: WFL formula error FIXED
@Soliton thanks for taking the time to explain, much appreciated.
Cheers!
-- Spannerbag
Cheers!
-- Spannerbag
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: WFL formula error FIXED
This is weird. Both of the following should work exactly the same:
There's no actual advantage to using the first form in this scenario (at least in theory, its main advantage would be when the variable is a container variable, though I seem to recall it not working at all for that case). But in principal there is no significant difference in what's happening between the two cases:
Here the
Code: Select all
[set_variable]
name=extra_fog_x
formula="$this_item.x + $fog_range + 2"
[/set_variable]
[set_variable]
name=extra_fog_x
value = "$($this_item.x + $fog_range + 2)"
[/set_variable]
- First, substitute in the
$fog_range
variable. If the variable is not defined, that means deleting it to produce$this_item.x + + 2
. - Next, substitute in
$this_item.x
. If$this_item
is not defined, that means deleting it to produce+ + 2
. - Finally, evaluating the formula, which will give an error if it discovers invalid syntax.
Code: Select all
[set_variable]
name=extra_fog_x
value = $($this_item.x + $fog_range + 2)
[/set_variable]
+
means WML concatenation, so if it's working when you do it like that, that probably means that both $this_item
and fog_range
are undefined and the resulting value is always 2.- Spannerbag
- Posts: 761
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: WFL formula error FIXED
I agree.
Just tested the following code:
Code: Select all
# Test formula alternatives
[event]
name=side 1 turn 1
{VARIABLE v1 1}
{VARIABLE v2 2}
{DEBUG_MSG (_"v1=$v1 and v2=$v2, about to compare formulas for v1+v2+2")}
[set_variable]
name=fa
formula="$v1 + $v2 + 2"
[/set_variable]
{DEBUG_MSG (_"Formula ""v1+v2+2"" produced ""$fa""")}
[set_variable]
name=fb
formula="$($v1 + $v2 + 2)"
[/set_variable]
{DEBUG_MSG (_"Formula with dollarsign and brackets produced ""$fb""")}
[if]
{VARIABLE_CONDITIONAL fa equals $fb}
{VARIABLE_CONDITIONAL fa numerical_equals $fb}
[then]
{DEBUG_MSG (_"Match")}
[/then]
[else]
{DEBUG_MSG (_"Ooops")}
[/else]
[/if]
[/event]
The scenario code is inside a macro and executes several nested events deep.
It's also inside a foreach loop and $this_item is, I guess, a container variable?
I could try the old format again in the "live" code and see if I still get the same issue, but I can't do it right now as I'm busy making a mess of writing another scenario that uses the same logic and I'm not in a position to quickly playtest this right now. Will be much easier when this scenario is completed and thoroughly playtested (so hopefully before Christmas

Thanks for your post, much appreciated.
Cheers!
-- Spannerbag
Re: WFL formula error FIXED
Illegal unary operator means value you assume to be present is not present. Can be made null safe by
$empty -0
since - is valid both as unary and binary.- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: WFL formula error FIXED
Though that only works if you expect it to be a number.