WML/LUA turn bell

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderators: Forum Moderators, Developers

Forum rules
Before posting a new idea, you must read the following:
Post Reply
enclave
Posts: 885
Joined: December 15th, 2007, 8:52 am

WML/LUA turn bell

Post by enclave » May 9th, 2018, 6:15 pm

Problem solved. The [message] side_for= now (in 1.14) works for sounds too! unlike in 1.12
In the bottom you can find working samples of codes that play sound only to specific side. Save your time and don't read all these below, its irrelevant.


Ok... There was always million of problems with people not hearing turn bell when there is a message displayed on turn refresh or any other event on start of their turn...

a) Could in some future there be a tag that would transfer or add turn bell to the message? ( (b) and/or tag that would show message in popup icon of Windows where time, language and sounds icons are displayed)
c) There could also be event that is fired after turn bell and after turn refresh so we could move new side turn messages there and they would get displayed AFTER turn bell (I was thinking to use time stamp to create this artificially, but I don't want to risk potential OOS and spend lot of time for nothing)

I have tried to add normal sound for message but ALL players in game hear it too, so it would remove the affect of turn bell as it would sound for each player and would become annoying too.

I asked many times about how to add sound that would be heard only for a specific side, but the replies I received were wrong and non-helpful (Please specify the full code including the event if you want to help, not some potentially working part of context).

Thank you very much for everyone who might help with this neverending problem.
Last edited by enclave on May 9th, 2018, 11:02 pm, edited 2 times in total.

User avatar
Ravana
Moderator
Posts: 1868
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: WML/LUA turn bell

Post by Ravana » May 9th, 2018, 6:25 pm

> I have tried to add normal sound for message but ALL players in game hear it too
If you do it in Lua, you can have it only for clients you want - in described use case checking that current side is local should be enough.

enclave
Posts: 885
Joined: December 15th, 2007, 8:52 am

Re: WML/LUA turn bell

Post by enclave » May 9th, 2018, 6:47 pm

Ravana wrote:
May 9th, 2018, 6:25 pm
> I have tried to add normal sound for message but ALL players in game hear it too
If you do it in Lua, you can have it only for clients you want - in described use case checking that current side is local should be enough.
That's exactly what I mean.. I completely don't understand your attempt to help..
How will it work in lua? What current side local? How the check if side local can help at all?
Which lua function will play sound?
wesnoth.play_sound(sound, [repeat_count]) there is no side variable here
wesnoth.set_music(music_entry) no side variable either
wesnoth.music_list no side variable, no current side local variables
wesnoth.sound_volume no side for variable
wesnoth.show_menu(items [, initial] [, markup]) no even sound variable here, not even talking about side variable
wesnoth.show_message_dialog no sound here too
I completely have no clue what you are trying to say. It rather be unanswered than now somebody will confuse your reply with solved problem.. sorry.

User avatar
Ravana
Moderator
Posts: 1868
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: WML/LUA turn bell

Post by Ravana » May 9th, 2018, 6:51 pm

It doesnt matter what function you use to play sound. If you check is_local, and only run the function if that side is local, then noone else will run the function, so noone else will hear anything.

Code: Select all

if wesnoth.sides[wesnoth.current.side].is_local then
	wesnoth.play_sound()
end
Last edited by Ravana on May 9th, 2018, 11:00 pm, edited 1 time in total.
Reason: Replaced play_sound() with wesnoth.play_sound()

User avatar
Sapient
Inactive Developer
Posts: 4452
Joined: November 26th, 2005, 7:41 am
Contact:

Re: WML/LUA turn bell

Post by Sapient » May 9th, 2018, 8:00 pm

Can you post the code you tried, which isn't working?

It looks like message already supports sound and side_for. If those aren't working then it should be reported as a bug.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."

enclave
Posts: 885
Joined: December 15th, 2007, 8:52 am

Re: WML/LUA turn bell

Post by enclave » May 9th, 2018, 10:11 pm

Sapient wrote:
May 9th, 2018, 8:00 pm
Can you post the code you tried, which isn't working?

It looks like message already supports sound and side_for. If those aren't working then it should be reported as a bug.
I haven't tried it in 1.14, but this what was making sound for all sides in 1.12:

Code: Select all

[message]
caption="Research Complete"
side_for=$side_number
speaker="narrator"
sound="horn-signals/horn-3.ogg"
image="$qc_system.humans.techs[$qc_system.humans.shortcuts.techs.$player[$side_number].research_project].image~SCALE(300,300)"
message="<b>$qc_system.humans.techs[$qc_system.humans.shortcuts.techs.$player[$side_number].research_project].name</b>
 
<small>
$qc_system.humans.techs[$qc_system.humans.shortcuts.techs.$player[$side_number].research_project].description1
$qc_system.humans.techs[$qc_system.humans.shortcuts.techs.$player[$side_number].research_project].description2
$qc_system.humans.techs[$qc_system.humans.shortcuts.techs.$player[$side_number].research_project].description3</small>
 
<span color='#cccc33'>$gc_temp_gold.spare_science_gold Gold</span> Was left over from research and returned to you.
<b>What would you like to do next?</b>"
[option]
message="&"+lobby/status-lobby-s.png~FL()~CS(200,-200,0)~SCALE(30,30)+"="+_ "Exit"
	[command]
		##
		{VARIABLE player[$side_number].research_project none}
		{VARIABLE player[$side_number].highlight_research true}
	[/command]
[/option]
[option]
message="&"+icons/jewelry_ring_prismatic.png~FL()~SCALE(30,30)+"="+_ "<b>Adjust Science Speed</b> = Amount of income to spend on science."
	[command]
		{VARIABLE player[$side_number].research_project none}
		{VARIABLE player[$side_number].highlight_research true}
		{HC_FIRE_EVENT qc_research_adjust}
	[/command]
[/option]
[option]
message="&"+icons/potion_green_medium.png~FL()~SCALE(30,30)+"="+_ "<b>Select a Research Project</b> = Research a new stronger warrior unit?"
	[command]
		{VARIABLE player[$side_number].research_project none}
		{VARIABLE player[$side_number].highlight_research true}
		{HC_FIRE_EVENT qc_research_select}
	[/command]
[/option]
[/message]
I guess experiment-wise I could add it to 1.14 and see if it is working now.
Although I would prefer a working version straight away...
Ravana wrote:
May 9th, 2018, 6:51 pm
It doesnt matter what function you use to play sound. If you check is_local, and only run the function if that side is local, then noone else will run the function, so noone else will hear anything.

Code: Select all

if wesnoth.sides[wesnoth.current.side].is_local then
	play_sound()
end
Thank you Ravana, this looks very clear to me now, so I guess I can put this [lua] code just before message in turn refresh event and only 1 side will hear this sound right before WML [message]?

I will test both ways now and report what the result is..

User avatar
Ravana
Moderator
Posts: 1868
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: WML/LUA turn bell

Post by Ravana » May 9th, 2018, 10:21 pm

Not before, you replace play_sound() with the code that shows message. Only the part inside conditional is used as unsynced code, everything after and before happens for everyone. It can be wesnoth.wml_actions.fire_event to call WML event containing [message] as well so you dont need to encode complex WML tables manually.

Message with options might still need to be fired on everyone and be synced, but is_local allows you go into unsynced context to make interface changes.

Note that is_local is 1.13 feature. You need to explicitly say you are looking for oldstable solution if you need it work on versions other than current stable.

enclave
Posts: 885
Joined: December 15th, 2007, 8:52 am

Re: WML/LUA turn bell

Post by enclave » May 9th, 2018, 10:56 pm

Ok I can happily say that 1.14 fixed the sound_for sound problem! Now only the side that receives the message with side_for can hear the sound..
I have tested exactly same code on 1.12 and 1.14 in both multiplayer and single player and result was sound for all sides on 1.12 and sound only for the side_for side on 1.14
As a bonus in offline games I don't hear the computer player sound and I dont get computer player messages too. The code follows:

Code: Select all

[event]
name=turn refresh
first_time_only=no
[message]
caption="Research Complete"
side_for=$side_number
speaker="narrator"
sound="horn-signals/horn-3.ogg"
image="portraits/monsters/ogre.png"
message="Ugly ogres make a sounds make a sound make a sound"
 [/message]
 [/event]
Then I also tested Ravana method, and it's really great to know that it works on 1.14 too (no idea about 1.12), in addition there is a nice difference between the message and sound code when you play offline.. Ravana method will give sound for all sides for offline game, while it will only give sound to specific side in online multiplayer. This is great because there is a choice for add-on makers of how they want sound to behave... Code follows:

Code: Select all

[event]
name=turn refresh
first_time_only=no
[lua]
code = <<
if wesnoth.sides[wesnoth.current.side].is_local then
	wesnoth.play_sound("horn-signals/horn-3.ogg")
end
>>
[/lua]
[message]
caption="Research Complete"
side_for=$side_number
speaker="narrator"
image="portraits/monsters/ogre.png"
message="Ugly ogres make a sounds make a sound make a sound"
 [/message]
 [/event]
Thank you very much both of you for your help! This will be helpful for many other people. I'm very sorry for confusing you that it doesn't work, it was not working in 1.12 and now it works perfectly fine in 1.14 (Ravana, please could you edit your post and fix play_sound() into wesnoth.play_sound() to avoid confusions)
Not before, you replace play_sound() with the code that shows message. Only the part inside conditional is used as unsynced code, everything after and before happens for everyone. It can be wesnoth.wml_actions.fire_event to call WML event containing [message] as well so you dont need to encode complex WML tables manually.

Message with options might still need to be fired on everyone and be synced, but is_local allows you go into unsynced context to make interface changes.

Note that is_local is 1.13 feature. You need to explicitly say you are looking for oldstable solution if you need it work on versions other than current stable.
Thank you very much for additional information ;)

Post Reply