help for add-ons

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

help for add-ons

Post by zijing »

can any one help me to find where's the error of the code?thanks:)

Code: Select all

local all_sides = wesnoth.get_sides({ {"has_unit", { canrecruit = true }} })
wesnoth.set_variable("dm_message.caption","Droid Menu") 
wesnoth.set_variable("dm_message.speaker","narrator")
wesnoth.set_variable("dm_message.scroll","no")
wesnoth.set_variable("dm_message.side_for",tostring(wesnoth.current.side))
wesnoth.set_variable("dm_message.message","Select a side to droid from the list:")
wesnoth.fire("set_variables", { name="dm_message.option[0]" , {"value", { message="Cancel", image="lobby/status-lobby-s.png~FL()~CS(200,-200,0)~SCALE(30,30)", {"command",{}}}}})
for i,v in ipairs(all_sides) do
	local spancolor1 = "<span color='"..tostring(wesnoth.get_variable("DROID_MENU_SYSTEM.player["..tostring(v.side).."].colorname")).."'>"
	local spancolor1_end = "</span>"
	if v.side == wesnoth.current.side then
		wesnoth.fire("set_variables", { name="dm_message.option["..tostring(i).."]" , {"value", { message=tostring(spancolor1).."Droid "..tostring(v.side_name).." side "..tostring(v.side).." and END TURN"..tostring(spancolor1_end), {"command",{{"modify_side",{ side=tostring(v.side), controller="ai"}},{"chat",{ speaker="Droid Menu" , message=tostring(v.side_name).." Side "..tostring(v.side).." was properly droided by owner side "..tostring(wesnoth.current.side)}},{"end_turn",{}}}}}}})
						wesnoth.set_variable("dm_temp_current_side_name",tostring(v.side_name))
	else
		wesnoth.fire("set_variables", { name="dm_message.option["..tostring(i).."]" , {"value", { message=tostring(spancolor1).."Droid "..tostring(v.side_name).." side "..tostring(v.side)..tostring(spancolor1_end), {"command",{{"modify_side",{ side=tostring(v.side), controller="ai"}},{"chat",{ speaker="Droid Menu" , message=tostring(v.side_name).." Side "..tostring(v.side).." was properly droided by owner side "..tostring(wesnoth.current.side)}}}}}}})
	end
end
User avatar
Ravana
Forum Moderator
Posts: 2950
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: help for add-ons

Post by Ravana »

It feels like goal of your code is quite close to what I wrote some years ago

Code: Select all

                [option]
                    message=_"change controller"
                    [command]
						[lua]
							code=<<
-- human, network, ai, network_ai, null, idle.
local count = 0
wesnoth.set_variable("Rav_DBG_control["..tostring(count).."].message", "Return")
for i, side in ipairs(wesnoth.sides) do
	if i == wesnoth.current.side then
		goto continue
	end
	
	count = count + 1
	if side.controller == "human" then
		wesnoth.set_variable("Rav_DBG_control["..tostring(count).."].message", "Change side "..tostring(i).." to ai")
		wesnoth.set_variable("Rav_DBG_control[" .. tostring(count) .. "].command.modify_side[0].side", i)
		wesnoth.set_variable("Rav_DBG_control[" .. tostring(count) .. "].command.modify_side[0].controller", "ai")
	else
		wesnoth.set_variable("Rav_DBG_control["..tostring(count).."].message", "Change side "..tostring(i).." to human")
		wesnoth.set_variable("Rav_DBG_control[" .. tostring(count) .. "].command.modify_side[0].side", i)
		wesnoth.set_variable("Rav_DBG_control[" .. tostring(count) .. "].command.modify_side[0].controller", "human")
	end
	::continue::
end
>>
						[/lua]
						[message]
							speaker=narrator
							[insert_tag]
								name=option
								variable=Rav_DBG_control
							[/insert_tag]
						[/message]
						{CLEAR_VARIABLE Rav_DBG_control}
                    [/command]
                [/option]
User avatar
zijing
Posts: 21
Joined: January 18th, 2020, 11:23 am

Re: help for add-ons

Post by zijing »

Ravana wrote: March 10th, 2020, 4:27 pm It feels like goal of your code is quite close to what I wrote some years ago

Code: Select all

                [option]
                    message=_"change controller"
                    [command]
						[lua]
							code=<<
-- human, network, ai, network_ai, null, idle.
local count = 0
wesnoth.set_variable("Rav_DBG_control["..tostring(count).."].message", "Return")
for i, side in ipairs(wesnoth.sides) do
	if i == wesnoth.current.side then
		goto continue
	end
	
	count = count + 1
	if side.controller == "human" then
		wesnoth.set_variable("Rav_DBG_control["..tostring(count).."].message", "Change side "..tostring(i).." to ai")
		wesnoth.set_variable("Rav_DBG_control[" .. tostring(count) .. "].command.modify_side[0].side", i)
		wesnoth.set_variable("Rav_DBG_control[" .. tostring(count) .. "].command.modify_side[0].controller", "ai")
	else
		wesnoth.set_variable("Rav_DBG_control["..tostring(count).."].message", "Change side "..tostring(i).." to human")
		wesnoth.set_variable("Rav_DBG_control[" .. tostring(count) .. "].command.modify_side[0].side", i)
		wesnoth.set_variable("Rav_DBG_control[" .. tostring(count) .. "].command.modify_side[0].controller", "human")
	end
	::continue::
end
>>
						[/lua]
						[message]
							speaker=narrator
							[insert_tag]
								name=option
								variable=Rav_DBG_control
							[/insert_tag]
						[/message]
						{CLEAR_VARIABLE Rav_DBG_control}
                    [/command]
                [/option]
Yeah,it's enclave's droid menu's code.but it shows me a nil color value...
Post Reply