[SOLVED] WML prestart event misbehaviour in on-line games

The place to post your WML questions and answers.

Moderator: Forum Moderators

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
Sventimir
Posts: 8
Joined: November 11th, 2020, 9:01 am

[SOLVED] WML prestart event misbehaviour in on-line games

Post by Sventimir »

I'm building a multiplayer scenario, intended to be played by 1-4 players. Each side has a predefined leader, so if there is less than 4 players I need to remove non-playing leaders in a prestart event. I wrote the following code to accomplish this:

Code: Select all

[event]
    name=prestart
    [kill]
        [filter_side]
            side=1,2,3,4
            controller=null
        [/filter_side]
    [/kill]
[/event]
Strangely, it works as intended in local multiplayer games, but in on-line games it seems to remove all the leaders regardless of whether a player is playing with that side or not, resulting in the scenario ending immediately. I wonder, what might be the reason for this difference in behaviour. There are no OOS errors to be seen…
Last edited by Sventimir on August 14th, 2023, 7:13 am, edited 1 time in total.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: WML prestart event misbehaviour in on-line games

Post by gfgtdf »

The reason is this line ,https://github.com/wesnoth/wesnoth/blob ... r.cpp#L221 , idk what the best way to ya does is though, chacking whether controller is null should be safe thing to do, but we cannot remove that line during stable
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.
User avatar
Celtic_Minstrel
Developer
Posts: 2241
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML prestart event misbehaviour in on-line games

Post by Celtic_Minstrel »

Workaround:

Code: Select all

[store_unit]
	[filter_side]
		side=1,2,3,4
	[/filter_side]
	variable=all_leaders
[/store_unit]
[foreach]
	array=all_leaders
	[do]
		[if]
			{VARIABLE_CONDITIONAL this_item.controller equals null}
			[then]
				[kill]
					id=$this_item.id
				[/kill]
			[/then]
		[/if]
	[/do]
[/foreach]
{CLEAR_VARIABLE all_leaders}
Untested, so I might've gotten some little detail wrong somewhere in there.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Sventimir
Posts: 8
Joined: November 11th, 2020, 9:01 am

Re: WML prestart event misbehaviour in on-line games

Post by Sventimir »

Thanks a lot for the explanation and the workaround. I'll try to make it work!

BTW, macros don't seem to work for me for some reason. I verified they're where they're supposed to be in /usr/share/wesnoth, but whenever I try to use one, I get file-not-found error mentioning the macro name. I place my scenarios in ~/.local/share/wesnoth/1.16/editor/scenarios – maybe I should move them to data/ for macros to work? So far I work around it by simply copying macro's content to the scenario, but that's a little annoying.
User avatar
Celtic_Minstrel
Developer
Posts: 2241
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML prestart event misbehaviour in on-line games

Post by Celtic_Minstrel »

Normally your files should be in data/add-ons/Your_Addon_Name, where Your_Addon_Name can be anything you choose. If you really want to leave them in editor/scenarios though, you should be able to make macros work just by adding the line {data/core/macros} at the top of your file.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Sventimir
Posts: 8
Joined: November 11th, 2020, 9:01 am

Re: WML prestart event misbehaviour in on-line games

Post by Sventimir »

I thought to leave it there for the moment, while I'm still developing the scenario. Otherwise, what is the editor/scenarios directory good for if files in there don't load macros by default? In any case, this doesn't seem to work. When I enter any multiplayer game setup, I get Error: Macro/file 'data/core/macros' is missing... followed by my scenario file.
Sventimir
Posts: 8
Joined: November 11th, 2020, 9:01 am

Re: WML prestart event misbehaviour in on-line games

Post by Sventimir »

I managed to solve it using formula condition instead of controller within filter_side like this:

Code: Select all

[event]
    name=prestart
    [kill]
        [filter_side]
            side=1,2,3,4
            formula="not (is_human or is_network or is_ai)"
        [/filter_side]
    [/kill]
[/event]
User avatar
Celtic_Minstrel
Developer
Posts: 2241
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML prestart event misbehaviour in on-line games

Post by Celtic_Minstrel »

Sventimir wrote: August 14th, 2023, 6:20 am Otherwise, what is the editor/scenarios directory good for if files in there don't load macros by default?
Its original purpose was for scenarios created with the map editor, which don't contain macros. It's no longer used in 1.17, however.
Sventimir wrote: August 14th, 2023, 6:20 am In any case, this doesn't seem to work. When I enter any multiplayer game setup, I get Error: Macro/file 'data/core/macros' is missing... followed by my scenario file.
I… what? I don't understand. How can it fail to find a file in the core mainline directory? Especially when it can find that file just fine when it loads core?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply