add error reporting when [if] is evaluated with no actions
I frequently make the mistake of using {IF_VAR} but forgetting to use [then] with it. One solution is to use my own macro, but the better solution is to add proper error reporting to if. If the engine parses an [if] tag with no [then], [else], or [elseif], it should flag an error... otherwise these mistakes are generally silent and very difficult to find.
This commit is contained in:
parent
2af8c75e92
commit
df71897d2f
1 changed files with 17 additions and 0 deletions
|
@ -335,11 +335,21 @@ wml_actions.command = handle_event_commands
|
|||
|
||||
wml_actions["if"] = function( cfg )
|
||||
if wesnoth.eval_conditional( cfg ) then -- evalutate [if] tag
|
||||
local found_something = 0
|
||||
for then_child in helper.child_range ( cfg, "then" ) do
|
||||
handle_event_commands( then_child )
|
||||
found_something = 1
|
||||
end
|
||||
if found_something == 0 then
|
||||
if not helper.get_child( cfg, "else", nil ) then
|
||||
if not helper.get_child( cfg, "elseif", nil ) then
|
||||
wesnoth.message("WML warning","[if] didn't find any [then], [elseif], or [else] children. Check your {IF_VAR}!")
|
||||
end
|
||||
end
|
||||
end
|
||||
return -- stop after executing [then] tags
|
||||
else
|
||||
local found_something = 0
|
||||
for elseif_child in helper.child_range ( cfg, "elseif" ) do
|
||||
if wesnoth.eval_conditional( elseif_child ) then -- we'll evalutate the [elseif] tags one by one
|
||||
for then_tag in helper.child_range( elseif_child, "then" ) do
|
||||
|
@ -347,10 +357,17 @@ wml_actions["if"] = function( cfg )
|
|||
end
|
||||
return -- stop on first matched condition
|
||||
end
|
||||
found_something = 1
|
||||
end
|
||||
-- no matched condition, try the [else] tags
|
||||
for else_child in helper.child_range ( cfg, "else" ) do
|
||||
handle_event_commands( else_child )
|
||||
found_something = 1
|
||||
end
|
||||
if found_something == 0 then
|
||||
if not helper.get_child( cfg, "then", nil ) then
|
||||
wesnoth.message("WML warning","[if] didn't find any [then], [elseif], or [else] children. Check your {IF_VAR}!")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue