add [unsynced] actionwml
This can be used like in the following example (note that without the [unsynced] it would cause OOS becasue rand= might or might not be called.): [unsynced] [store_side] variable = "side" side = "$side_number" [/store_side] [if] [variable] name = "side.controller" equals = "human" [/variable] [then] [set_variable] name = "num" rand = _ "two,four,seven" [/set_variable] [message] message = _ "I want $num stones" [/message] [/then] [/if] [unsynced]
This commit is contained in:
parent
757cde164b
commit
f01252a42c
2 changed files with 20 additions and 0 deletions
|
@ -1505,3 +1505,9 @@ function wml_actions.role(cfg)
|
|||
|
||||
-- no matching unit found, fail silently
|
||||
end
|
||||
|
||||
function wml_actions.unsynced(cfg)
|
||||
wesnoth.unsynced(function ()
|
||||
wml_actions.command(cfg)
|
||||
end)
|
||||
end
|
|
@ -2937,6 +2937,19 @@ int game_lua_kernel::intf_synchronize_choice(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a function in an unsynced context (this specially means that all random calls used by that function will be unsynced).
|
||||
* This is usualy used together with an unsynced if like 'if controller != network'
|
||||
* - Arg 1: function that will be called during the unsynced context.
|
||||
*/
|
||||
static int intf_do_unsynced(lua_State *L)
|
||||
{
|
||||
set_scontext_unsynced sync;
|
||||
lua_pushvalue(L, 1);
|
||||
luaW_pcall(L, 0, 0, false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the locations matching a given filter.
|
||||
* - Arg 1: WML table.
|
||||
|
@ -4075,6 +4088,7 @@ game_lua_kernel::game_lua_kernel(CVideo * video, game_state & gs, play_controlle
|
|||
{ "unit_defense", &intf_unit_defense },
|
||||
{ "unit_movement_cost", &intf_unit_movement_cost },
|
||||
{ "unit_resistance", &intf_unit_resistance },
|
||||
{ "unsynced", &intf_do_unsynced },
|
||||
{ "add_event_handler", &dispatch<&game_lua_kernel::intf_add_event > },
|
||||
{ "add_tile_overlay", &dispatch<&game_lua_kernel::intf_add_tile_overlay > },
|
||||
{ "add_time_area", &dispatch<&game_lua_kernel::intf_add_time_area > },
|
||||
|
|
Loading…
Add table
Reference in a new issue