Force immediate [endlevel]

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
WhiteWolf
Forum Regular
Posts: 494
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Force immediate [endlevel]

Post by WhiteWolf » June 13th, 2019, 9:12 pm

Hello,

Currently I have a weapon special which might trigger a <Lua> Repeated [endlevel] execution, ignoring warning.
The weapon special has area damage which can kill. If there are two hero units adjacent to this attacker, area damage might kill an adjacent hero (first [endlevel]) however, the game doesn't end immediately, the remaining strikes are still resolved for some reason*. Alas, the targeted hero might also die in resolving this fight, which leads to a second [endlevel].
The scenario ends in defeat all right, but said error message is displayed, which is not nice to leave around for the user to see.

*This is the part where I think it should be possible to intervene. Is there a way to make the [endlevel] immediatly end the level, and not resolve the rest of the strikes?

Thanks
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!

User avatar
josteph
Developer
Posts: 609
Joined: August 19th, 2017, 6:58 pm

Re: Force immediate [endlevel]

Post by josteph » June 14th, 2019, 7:04 am

WhiteWolf wrote:
June 13th, 2019, 9:12 pm
*This is the part where I think it should be possible to intervene. Is there a way to make the [endlevel] immediatly end the level, and not resolve the rest of the strikes?
I'm surprised to discover that's actually possible:

Code: Select all

diff --git a/data/scenario-test.cfg b/data/scenario-test.cfg
index 3ced99d9094..767350eb92a 100644
--- a/data/scenario-test.cfg
+++ b/data/scenario-test.cfg
@@ -710,6 +710,14 @@ Xu, Xu, Qxu, Qxu, Ql, Ql, Ql, Xu, Xu, Xu, Xu, Xu, Xu, Xu, Xu, Gg, Gg, Gg, Gg, Gg
         {MODIFY_UNIT (id=$second_unit.id) side 1}
     [/event]
     [event]
+        name=attacker hits
+        [cancel_action]
+        [/cancel_action]
+        [endlevel]
+            result=victory
+        [/endlevel]
+    [/event]
+    [event]
         name=prestart
         {VARIABLE teleports_on no}
     [/event]
Spoiler:

User avatar
WhiteWolf
Forum Regular
Posts: 494
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Force immediate [endlevel]

Post by WhiteWolf » June 14th, 2019, 4:11 pm

Thanks, this seems to solve it fine :) I've added [cancel_action] after the [endlevel]'s for each last breath event of the heroes.
On the other hand, can this theoretically cause any other kind of bugs anywhere else? I'm guessing not, after all, it's already an endlevel in defeat at the death of a unit, which is pretty much immediate in a 'regular' fight, so I guess an 'extra' [cancel_action] won't discard anything necessary... but I'd like to be reassured :)
Author of the Underness Series, consisting of V parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!

User avatar
josteph
Developer
Posts: 609
Joined: August 19th, 2017, 6:58 pm

Re: Force immediate [endlevel]

Post by josteph » June 14th, 2019, 4:39 pm

WhiteWolf wrote:
June 14th, 2019, 4:11 pm
On the other hand, can this theoretically cause any other kind of bugs anywhere else? I'm guessing not, after all, it's already an endlevel in defeat at the death of a unit, which is pretty much immediate in a 'regular' fight, so I guess an 'extra' [cancel_action] won't discard anything necessary... but I'd like to be reassured :)
Indeed, on the one hand, battles can end before all strikes have taken place if one of the units dies partway through, so most code should be ready for that situation. However, normally, when a battle ends prematurely, one of the two combatants dies. That's not true in your case, and furthermore, the wiki does not document that battles can be terminated prematurely by using [cancel_action]. So, I think it's possible if you use this, you'll discover that some other addon breaks when a battle ends prematurely with both combatants still living.

But the code explicitly tests a flag that can only be set by the [cancel_action] facility, so I assume this trick is actually an intentional feature, even if it's not documented.

Post Reply