[SOLVED] store music ?

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Adamant14
Posts: 809
Joined: April 24th, 2010, 1:14 pm
Contact:

[SOLVED] store music ?

Post by Adamant14 » October 22nd, 2018, 6:11 pm

Is there a way to check which song is currently played by the game ?
Maybe a way to store it into a variable to display it to the one who plays the game, or something like that ?
Last edited by Adamant14 on October 22nd, 2018, 8:21 pm, edited 1 time in total.
Author of Antar, Son of Rheor: SP Campaign


Please add your (or some other) campaign to this sites: Guide to UMC Campaigns | Players' Review(s) | Please leave a comment here: WML filtering , WML variables

User avatar
Pentarctagon
Forum Administrator
Posts: 3573
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: store music ?

Post by Pentarctagon » October 22nd, 2018, 6:15 pm

See: https://wiki.wesnoth.org/LuaWML/Display ... music_list

Specifically for your case, you'd want wesnoth.music_list.current.__cfg.name.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

User avatar
Adamant14
Posts: 809
Joined: April 24th, 2010, 1:14 pm
Contact:

Re: store music ?

Post by Adamant14 » October 22nd, 2018, 6:19 pm

Seems that is what I am looking for, sadly I have no idea how to use LUA.
I guess there is no way to do that with WML ?
Author of Antar, Son of Rheor: SP Campaign


Please add your (or some other) campaign to this sites: Guide to UMC Campaigns | Players' Review(s) | Please leave a comment here: WML filtering , WML variables

User avatar
Pentarctagon
Forum Administrator
Posts: 3573
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: store music ?

Post by Pentarctagon » October 22nd, 2018, 6:22 pm

The simplest way would probably be:

Code: Select all

[lua]
  code=<<
    wml.variables["my_wml_variable"] = wesnoth.music_list.current.__cfg.name
  >>
[/lua]
then just put that wherever you want to get the name of the current song, and you'll be able to access it from the WML variable my_wml_variable.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

User avatar
Adamant14
Posts: 809
Joined: April 24th, 2010, 1:14 pm
Contact:

Re: store music ?

Post by Adamant14 » October 22nd, 2018, 7:20 pm

The code works, thank you Pentarctagon.

Only issue is a strange error message:

Code: Select all

Invalid WML found: unknown conditional wml: [debug_status] (4)
Invalid WML found: unknown conditional wml: [debug_status] (4)
Invalid WML found: unknown conditional wml: [debug_status] (4)
Invalid WML found: unknown conditional wml: [debug_status] (4)
That is how I use the code:

Code: Select all

	[event]
		name=prestart
		{VARIABLE "check_music" 0}
	[/event]

	[event]
		name=start,side turn,new turn
		first_time_only=no
		[lua]
			code=<<
			wml.variables["check_music"] = wesnoth.music_list.current.__cfg.name
			>>
		[/lua]

		[set_menu_item]
			[filter]
				side=1
			[/filter]
			id=test_playlist
			description="Open Music Menu"
			[command]
				[message]
					[option]
						label="Currently playing track: $check_music"
					[/option]

					[option]
						label="Close menu"
					[/option]
				[/message]
			[/command]
		[/set_menu_item]
	[/event]
	

The error message appears every time I open the menu.
Author of Antar, Son of Rheor: SP Campaign


Please add your (or some other) campaign to this sites: Guide to UMC Campaigns | Players' Review(s) | Please leave a comment here: WML filtering , WML variables

User avatar
Pentarctagon
Forum Administrator
Posts: 3573
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: store music ?

Post by Pentarctagon » October 22nd, 2018, 7:36 pm

I am not sure then. When I paste that code as-is into a scenario it works as expected with no error messages.

edit-
Do you have any other add-ons installed? And do you still get the error without any of the music checking code:

Code: Select all

[event]
	name=start,side turn,new turn
	first_time_only=no
	[set_menu_item]
		[filter]
			side=1
		[/filter]
		id=test_playlist
		description="Open Music Menu"
		[command]
			[message]
				[option]
					label="Currently playing track: "
				[/option]

				[option]
					label="Close menu"
				[/option]
			[/message]
		[/command]
	[/set_menu_item]
[/event]
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

User avatar
Adamant14
Posts: 809
Joined: April 24th, 2010, 1:14 pm
Contact:

Re: store music ?

Post by Adamant14 » October 22nd, 2018, 8:18 pm

You are right, the code works .

When I start the campaign new from scenario 1, then the error messages are gone.
They only appear when I start from saveloads, though they shouldn't too.

Thank you for your help, and for the code, and for your time.


EDIT:
I found what caused the error message. It was indeed an other installed AddOn :augh:
Sorry for all circumstances.
Author of Antar, Son of Rheor: SP Campaign


Please add your (or some other) campaign to this sites: Guide to UMC Campaigns | Players' Review(s) | Please leave a comment here: WML filtering , WML variables

Post Reply