Follow-up Comment #2, bug #19086 (project wesnoth): Thanks for the comments. As far as I understand it (and please let me know if I am missing something), the BCA id is not used by the engine at all (or at least its name can be set to anything arbitrarily), so I don't know how using unit.id would cause a problem here. However, I don't have any preference whatsoever for using id over underlying_id (if I were to use this for a BCA that I wanted to remove later, I would explicitly define the id, rather than using the implicit method anyway), so I changed the code to use the latter.
As for the diff, what's the standard way of showing that here? Here's the text diff, and a screengrab of a graphical diff is attached as a file 13d12 < local id = cfg.bca_id or ("bca-" .. unit.__cfg.underlying_id) 25a25 > local id = "bca-" .. ca_counter 27a28,29 > ca_counter = ca_counter + 1 > 30a33,34 > ["id"] = id, > ["name"] = id, 36a41 > ["side"] = side, I changed the code slightly to: 1. Make the switch to underlying_id 2. Minimize the difference w.r.t. the current version so that the diff is as short as possible. Here's the new version: function wml_actions.add_ai_behavior(cfg) local unit = wesnoth.get_units(helper.get_child(cfg, "filter"))[1] if not unit then helper.wml_error("[add_ai_behavior]: no unit specified") end local side = cfg.side local sticky = cfg.sticky or false local loop_id = cfg.loop_id or "main_loop" local eval = cfg.evaluation local exec = cfg.execution local id = cfg.bca_id or ("bca-" .. unit.__cfg.underlying_id) local ux = unit.x -- @note: did I get it right that coordinates in C++ differ by 1 from thos in-game(and in Lua)? local uy = unit.y if not side then helper.wml_error("[add_ai_behavior]: no side attribute given") end if not (eval and exec) then helper.wml_error("[add_ai_behavior]: invalid execution/evaluation handler(s)") end local path = "stage[" .. loop_id .. "].candidate_action[" .. id .. "]" -- bca: behavior candidate action local conf = { ["action"] = "add", ["engine"] = "lua", ["path"] = path, {"candidate_action", { ["id"] = id, ["name"] = id, ["engine"] = "lua", ["sticky"] = sticky, ["unit_x"] = ux, ["unit_y"] = uy, ["evaluation"] = eval, ["execution"] = exec }}, ["side"] = side } wesnoth.wml_actions.modify_ai(conf) --wesnoth.message("Adding a behavior") end (file #14645) _______________________________________________________ Additional Item Attachment: File name: xxdiff.add_ai_behavior.png Size:71 KB _______________________________________________________ Reply to this item at: <http://gna.org/bugs/?19086> _______________________________________________ Message sent via/by Gna! http://gna.org/ _______________________________________________ Wesnoth-bugs mailing list Wesnoth-bugs@gna.org https://mail.gna.org/listinfo/wesnoth-bugs