[engine] Show [chat] to observers
Moderator: Forum Moderators
Forum rules
Before posting a new idea, you must read the following:
Before posting a new idea, you must read the following:
[engine] Show [chat] to observers
Currently
I propose adding new optional key to [chat], to control if message should be visible to observers. I have implemented it as
function wml_actions.chat(cfg)
works by calling wesnoth.message
, if the client executing it is found in side-filtered sides. Since observer never controls sides, message is never displayed for observers.I propose adding new optional key to [chat], to control if message should be visible to observers. I have implemented it as
Code: Select all
function wml_actions.chat(cfg)
local side_list = wesnoth.get_sides(cfg)
local message = tostring(cfg.message) or
helper.wml_error "[chat] missing required message= attribute."
local speaker = cfg.speaker
if speaker then
speaker = tostring(speaker)
else
speaker = "WML"
end
for index, side in ipairs(side_list) do
if side.controller == "human" then
wesnoth.message(speaker, message)
break
end
end
local observable = cfg.observable or true
if observable then
local all_sides = wesnoth.get_sides()
local has_human_side = false
for index, side in ipairs(all_sides) do
if side.controller == "human" then
has_human_side = true
break
end
end
if not has_human_side then
wesnoth.message(speaker, message)
end
end
end
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [engine] Show [chat] to observers
The idea is good, but I don't understand how this code is expected to work. Won't the message be displayed twice in some cases? Also, your
cfg.observable or true
will mean that observable
is always true.Re: [engine] Show [chat] to observers
Oh yes, I need to figure out how to use cfg variable there still. I initially had it default to false, but with true it is much easier to test that I actually see messages.
Message will not be displayed twice. Original loop shows message only to clients, that have local human side. My addition shows message only to clients that have no local human side.
It gets new list of all sides, to avoid the case where local human side is intentionally side-filtered out from original loop, and checks that none of sides is local.
Message will not be displayed twice. Original loop shows message only to clients, that have local human side. My addition shows message only to clients that have no local human side.
It gets new list of all sides, to avoid the case where local human side is intentionally side-filtered out from original loop, and checks that none of sides is local.
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [engine] Show [chat] to observers
Ah, that makes sense. I'm guessing you've also confirmed that it actually works?
If you want it to default to false, then `cfg.observable or false` would work, though so would just plain `cfg.observable`. If you want it to default to true you need something like `cfg.observable ~= false`.
If you want it to default to false, then `cfg.observable or false` would work, though so would just plain `cfg.observable`. If you want it to default to true you need something like `cfg.observable ~= false`.
Re: [engine] Show [chat] to observers
I tested that I see messages. Clearly not yet that the key works.
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [engine] Show [chat] to observers
Yeah, that's what I meant – confirming that it lets you see the messages as an observer.
Re: [engine] Show [chat] to observers
With 1.13.8 it seems to show message to everyone, despite used side filter. Will be testing with vpn.
https://github.com/wesnoth/wesnoth/issues/1735
https://github.com/wesnoth/wesnoth/issues/1735
Re: [engine] Show [chat] to observers
Version with debug statements
Code: Select all
function wml_actions.chat(cfg)
local side_list = wesnoth.get_sides(cfg)
local speaker = tostring(cfg.speaker or "WML")
local message = tostring(cfg.message or
helper.wml_error "[chat] missing required message= attribute."
)
for index, side in ipairs(side_list) do
if side.controller == "human" and side.is_local then
wesnoth.message(speaker, message)
break
end
end
local observable
if cfg.observable ~= nil then
observable = cfg.observable
else
observable = true
end
if observable then
local all_sides = wesnoth.get_sides()
local has_human_side = false
for index, side in ipairs(all_sides) do
if side.controller == "human" and side.is_local then
has_human_side = true
break
end
end
if not has_human_side then
wesnoth.message(speaker, message)
end
end
end
This uses side.is_local, which I think should be on https://wiki.wesnoth.org/LuaWML/Sides#wesnoth.sides.
I tested 9 configurations
Re: [engine] Show [chat] to observers
I'd replace
with
Code: Select all
local observable
if cfg.observable ~= nil then
observable = cfg.observable
else
observable = true
end
local observable = cfg.observable~= false
. Othwewise the code looks good ot me, please file a pull request on https://github.com/wesnoth/wesnoth/pullsHmm ye woudl be nice it you'd add it tpo the wiki.This uses side.is_local, which I think should be on https://wiki.wesnoth.org/LuaWML/Sides#wesnoth.sides.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Re: [engine] Show [chat] to observers
Opened, https://github.com/wesnoth/wesnoth/pull/1739
I wrote what I could guess/find out about is_local. I dont have enough information to update controller entry though.
I wrote what I could guess/find out about is_local. I dont have enough information to update controller entry though.
is_local: boolean (read (Version 1.13.3 and later only)) whether the side is local
Re: [engine] Show [chat] to observers
thx, if noone objects in the next 24 hours i'll merge it.
i'd put the 'Version 1.13.3 and later only' before the 'read' but otherwiese it's fine.is_local: boolean (read (Version 1.13.3 and later only)) whether the side is local
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [engine] Show [chat] to observers
Pretty sure
Also note that using it carelessly will definitely cause out-of-sync errors. Maybe that's obvious from the name, but it wouldn't hurt to state it explicitly.
is_local
is new in 1.13.8 or maybe 1.13.7, not in 1.13.3.Also note that using it carelessly will definitely cause out-of-sync errors. Maybe that's obvious from the name, but it wouldn't hurt to state it explicitly.
Re: [engine] Show [chat] to observers
I found reference to is_local from https://github.com/wesnoth/wesnoth/comm ... 49d84784e4.
Updated
Updated
is_local (Version 1.13.3 and later only): boolean (read). Whether the side is local. Careless use will cause OOS errors.
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [engine] Show [chat] to observers
Yes, but it wasn't exposed to Lua until https://github.com/wesnoth/wesnoth/comm ... b84e0f3ad9