Force immediate [endlevel]

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
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Force immediate [endlevel]

Post by WhiteWolf »

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
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: Force immediate [endlevel]

Post by josteph »

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 Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Force immediate [endlevel]

Post by WhiteWolf »

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 :)
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: Force immediate [endlevel]

Post by josteph »

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