wml.fire and wesnoth.wml_actions.
Moderator: Forum Moderators
- hermestrismi
- Posts: 634
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
wml.fire and wesnoth.wml_actions.
Hi,
I need to understand the difference between and
I have two functions here:
I get two arrays, one from [0] to [13], the other from [0] to [14] .
I will use wml.fire but I want to understand why gave different result?
also, any comment on the code itself is welcome ofc
I need to understand the difference between
Code: Select all
wml.fire
Code: Select all
wml_actions
Code: Select all
function print_results(results_table)
for i, entry in ipairs(results_table) do
local unit = entry.unit
local amount_of_bet = entry.amount_of_bet
local side = entry.side
local x_unit = 17
local y_unit = 14 + i
wesnoth.units.to_map({ type = unit, side = side }, x_unit, y_unit)
wml.fire("store_unit", { variable="my_unit", { "filter", { canrecruit="no" } } })
print("Unit:".. unit ..", Amount of Bet:".. amount_of_bet ..",Side:".. side)
wesnoth.map.add_label({x = 3, y = 24 + i, text = "Unit: " .. unit .. " | Amount of Bet: " .. amount_of_bet .. " | Side: " .. side})
end
end
function convert_to_wml_array(results_table)
local wml_array = {}
local target = {}
local T = wml.tag
for _, entry in ipairs(results_table) do
local unit_entry = {
unit = entry.unit,
amount = entry.amount_of_bet,
side = entry.side
}
local unit = entry.unit
local amount_of_bet = entry.amount_of_bet
local side = entry.side
wesnoth.wml_actions.set_variables {
name="targets",
mode="append",
T.value {
unit=unit,
amount=amount_of_bet,
side=side
}
}
table.insert(wml_array, unit_entry)
table.insert(target, unit_entry)
-- wml.array_access_set("target", unit_entry)
end
-- wml.variables["target"] = wml.tostring(target)
return wml_array
end
I will use wml.fire but I want to understand why
Code: Select all
wesnoth.wml_actions.set_variables
also, any comment on the code itself is welcome ofc
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- Celtic_Minstrel
- Developer
- Posts: 2290
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: wml.fire and wesnoth.wml_actions.
wesnoth.wml_actions
is the place to define new WML actions. Because of that, it is technically possible to also call a WML action via it, but doing so creates a problem – WML actions are intended to be run on substituted WML tables (ak vconfigs), but calling it manually typically ends up passing an unsubstituted, plain WML table.wml.fire
is intended for calling a WML action. Thus, when passed a plain WML table, it automatically converts it to a substituted one. By always using wml.fire
instead of wesnoth.wml_actions
to call WML actions, you can safely write your WML actions to assume the input is substituted.As a side note, there are two equivalent ways to call
wml.fire
:Code: Select all
wml.fire("store_unit", { variable="my_unit", { "filter", { canrecruit="no" } } })
wml.fire.store_unit{ variable="my_unit", { "filter", { canrecruit="no" } } }
wml.fire
on the basis of the syntactic difference, there's no need – it can be called in the same format as wesnoth.wml_actions
. Technically, the first form shown above is the older method and the second form was added later, but we don't have any plans to remove the first form.- hermestrismi
- Posts: 634
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: wml.fire and wesnoth.wml_actions.
thank you for the explanationCeltic_Minstrel wrote: ↑April 2nd, 2024, 3:50 amwesnoth.wml_actions
is the place to define new WML actions. Because of that, it is technically possible to also call a WML action via it, but doing so creates a problem – WML actions are intended to be run on substituted WML tables (ak vconfigs), but calling it manually typically ends up passing an unsubstituted, plain WML table.
wml.fire
is intended for calling a WML action. Thus, when passed a plain WML table, it automatically converts it to a substituted one. By always usingwml.fire
instead ofwesnoth.wml_actions
to call WML actions, you can safely write your WML actions to assume the input is substituted.
As a side note, there are two equivalent ways to callwml.fire
:
So if you dislikeCode: Select all
wml.fire("store_unit", { variable="my_unit", { "filter", { canrecruit="no" } } }) wml.fire.store_unit{ variable="my_unit", { "filter", { canrecruit="no" } } }
wml.fire
on the basis of the syntactic difference, there's no need – it can be called in the same format aswesnoth.wml_actions
. Technically, the first form shown above is the older method and the second form was added later, but we don't have any plans to remove the first form.
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin