duel scenario endings

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
Gambrous
Posts: 26
Joined: July 3rd, 2012, 8:22 pm

duel scenario endings

Post by Gambrous »

I'm trying to make a scenario end in two possible ways. You can either defeat the one leader and when the turns run out you'll win with no bonus, or defeat both leaders and win with a bonus. Here's the coding I tried which doesn't seems to work:

Code: Select all

    [event]
      name=time over
      [if]
        [have_unit]
          side=3
          canrecruit=yes
        [/have_unit]
        [then]
          [message]
            speaker=Sir Gresdon
            message= _ "At last his control is gone and I am free! Thankyou elves"
          [/message]
          [message]
            speaker=Gambrous
            message= _ "Now the undead are defeated!"
          [/message]
          [message]
            speaker=Tristin
            message= _ "Thankyou prince Gambrous, please I welcome you to the Castle of the Arcane Arts"
          [/message]
          [endlevel]
            result=victory
            bonus=no
          [/endlevel]
        [/then]
        [else]
          [if]
            [have_unit]
              side=4
              canrecruit=yes
            [/have_unit]
            [then]
              [message]
                speaker=Gambrous
                message= _ "The undead horde is too numerous, we are doomed!"
              [/message]
              [endlevel]
                result=lose
              [/endlevel]
            [/then]
          [/if]
        [/else]
      [/if]
    [/event]
    [event]
      name=last breath
        [filter]
          id=Sir Gresdon
        [/filter]
        [message]
          speaker=Sir Gresdon
          message= _ "At last his control is gone and I am free! Thankyou elves"
        [/message]
    [/event]
    [event]
      name=enemies defeated
      [message]
        speaker=Gambrous
        message= _ "Now the undead are defeated!"
      [/message]
      [message]
        speaker=Tristin
        message= _ "Thankyou prince Gambrous, please I welcome you to the Castle of the Arcane Arts"
      [/message]
      [endlevel]
        result=victory
        bonus=yes
        {NEW_GOLD_CARRYOVER 40}
      [/endlevel]
    [/event]
Any ideas?

Gambrous
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: duel scenario endings

Post by JaMiT »

Here is what your WML is saying:

When time runs out, if side 3 is not defeated, then win (which happens to contradict your desire to require at least one side to be defeated; it could be that side 4 is also not defeated).

Else. when time runs out (and side 3 is defeated), then if side 4 is not defeated then lose. (The "if" part is superfluous unless you have more than these two sides as enemies of the player. Also, this should not be a loss since one leader was defeated.)

When Sir Gresdon is killed, have him say something. (On a related topic, "thank you" is two words.)

When all enemies are defeated, win with a bonus.
Gambrous
Posts: 26
Joined: July 3rd, 2012, 8:22 pm

Re: duel scenario endings

Post by Gambrous »

Yeh, I didn't make it clear. What I want is for the player to win if they defeat side4 but not side3 before time runs out. If they then defeat both sides 3 and 4 then they get a bonus. This is why it's ok for side 3 to still be standing at the end of the scenario. So I think from what you're saying I need to write in wml that if side 3 is still standing with side 4 defeated then win. The whole bit about side 3 not being defeated but side 4 is defeated should be ok because side 4 is the only enemy the player has to defeat to win.

Sir Gresdon is meant to say that (I also put this in):

Code: Select all

    [event]
      name=last breath
        [filter]
          id=Sir Gresdon
        [/filter]
        [message]
          speaker=Sir Gresdon
          message= _ "At last his control is gone and I am free! Thankyou elves"
        [/message]
    [/event]
So what alterations do I need to make?

Gambrous
Gambrous
Posts: 26
Joined: July 3rd, 2012, 8:22 pm

Re: duel scenario endings

Post by Gambrous »

ok, this is where my script is at the minute

Code: Select all

    [event]
      name=time over
      [if]
        [have_unit]
          side=3
          canrecruit=yes
        [/have_unit]

        [have_unit]
          side=4
          canrecruit=yes
        [/have_unit]
        [then]
          [endlevel]
            result=defeat
          [/endlevel]
        [/then]
        [else]
          [have_unit]
            side=3
            canrecruit=yes
          [/have_unit]
          [then]
          [message]
            speaker=Sir Gresdon
            message= _ "At last his control is gone and I am free! Thank you elves"
          [/message]
          [message]
            speaker=Gambrous
            message= _ "Now the undead are defeated!"
          [/message]
          [message]
            speaker=Tristin
            message= _ "Thankyou prince Gambrous, please I welcome you to the Castle of the Arcane Arts"
          [/message]
          [endlevel]
            result=victory
            bonus=no
          [/endlevel]
          [/then]
          [else]
            [have_unit]
              side=4
              canrecruit=yes
            [/have_unit]
              [then]
              [message]
                speaker=Gambrous
                message= _ "The undead horde is too numerous, we are doomed!"
              [/message]
                [endlevel]
                  result=lose
                [/endlevel]
                [/then]
          [/else]
        [/else]
      [/if]
    [/event]
    [event]
      name=last breath
        [filter]
          id=Sir Gresdon
        [/filter]
        [message]
          speaker=Sir Gresdon
          message= _ "At last his control is gone and I am free! Thank you elves"
        [/message]
    [/event]
    [event]
      name=enemies defeated
      [message]
        speaker=Gambrous
        message= _ "Now the undead are defeated!"
      [/message]
      [message]
        speaker=Tristin
        message= _ "Thankyou prince Gambrous, please I welcome you to the Castle of the Arcane Arts"
      [/message]
      [endlevel]
        result=victory
        bonus=yes
        {NEW_GOLD_CARRYOVER 40}
      [/endlevel]
    [/event]
Still not working.

Gambrous
Luther
Posts: 128
Joined: July 28th, 2007, 5:19 pm
Location: USA

Re: duel scenario endings

Post by Luther »

I don't see any obvious problems in your code. What actually happens when you try it?
Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: duel scenario endings

Post by Ceres »

Gambrous wrote:

Code: Select all

[else]
    [have_unit]
         side=3
         canrecruit=yes
    [/have_unit]
You can't do that - [else] is supposed to contain only ActionWML, no conditions. So you'd have to write this:

Code: Select all

[else]
  [if]
     [have_unit]
          side=3
          canrecruit=yes
     [/have_unit]
     [then]
        ...
     [/then]
  [/if]
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: duel scenario endings

Post by JaMiT »

Gambrous wrote:What I want is for the player to win if they defeat side4 but not side3 before time runs out. If they then defeat both sides 3 and 4 then they get a bonus.
This is something to work with, but let's try rearranging the logic a bit. You want the player to win if they defeat side 4. Also defeating side 3 causes the scenario to end early.

Or....

If all enemies are defeated, the player wins. This is the default, so no need to do anything special.

If turns run out, then not all enemies were defeated. The player still wins if side 4 was defeated.

Code: Select all

    [event]
        name=time over

        [if]
            # If side 4 has been defeated.
            [not]
                [have_unit]
                    side=4
                    canrecruit=yes
                [/have_unit]
            [/not]

            [then]
                [message]
                    speaker=Sir Gresdon
                    message= _ "At last his control is gone, and I am free! Thank you elves."
                [/message]
 
                [endlevel]
                    result=victory
                    bonus=no
                [/endlevel]
            [/then]

            [else]
                # Side 4 has not been defeated. The player loses.
                [message]
                    speaker=Gambrous
                    message= _ "The undead horde is too numerous. We are doomed!"
                [/message]

                # Not strictly necessary, but it makes the WML look complete:
                [endlevel]
                    result=defeat
                [/endlevel]
            [/else]
        [/if]
Now you want a bit of dialog upon victory. This part of the dialog is the same regardless of how the player won, so you can ease your scenario maintenance a bit by putting it in the victory event.

Code: Select all

    [event]
        name=victory

        [message]
            speaker=Gambrous
            message= _ "Now the undead are defeated!"
        [/message]
        [message]
            speaker=Tristin
            message= _ "Thank you Prince Gambrous. Please, I welcome you to the Castle of the Arcane Arts."
        [/message]
    [/event]
There really is no need to ever check side 3. If side 3 is defeated and side 4 is defeated, then all enemies have been defeated, so the victory event fires and the scenario ends; the time_over event will not fire. So if we get to the time_over event with side 4 defeated, we can assume side 3 was not defeated. On the other hand, if we get to the time_over event with side 4 not defeated, it does not matter whether or not side 3 has been defeated since the player loses either way.
Gambrous
Posts: 26
Joined: July 3rd, 2012, 8:22 pm

Re: duel scenario endings

Post by Gambrous »

I've tried everything suggested and all that happens is the game crashes when loading the scenario. I'm attaching the campaign so someone else can try it and see if it works for them. Alternatively if anyone wants to look through the code then they have the entire scenario in case the problem is somewhere else.

Gambrous
Attachments
Defense_of_Glenfire_Forest.7z
this is the campaign so far
(108.93 KiB) Downloaded 87 times
Luther
Posts: 128
Joined: July 28th, 2007, 5:19 pm
Location: USA

Re: duel scenario endings

Post by Luther »

The first problem (though I don't think it effects anything) is in _main.cfg. Remove the line that says '{~add-ons/Defense_of_Glenfire_Forest/maps}'. The scenario files should refer to the map files directly, so you don't need that in _main.cfg.

When I tried to run the campaign, Wesnoth hung while continuously accessing my hard drive. Thinking it was a recursive macro, I used the tool at data/tools/wesnoth/wmlparser.py and found a missing quote mark near the end of scenario 4, after Mal-Esprer.

With that fix, the campaign starts up fine, though I haven't actually played it.
Gambrous
Posts: 26
Joined: July 3rd, 2012, 8:22 pm

Re: duel scenario endings

Post by Gambrous »

Luther wrote:I used the tool at data/tools/wesnoth/wmlparser.py
How do I use this tool? It would be very beneficial.

Gambrous
User avatar
junoslord
Posts: 82
Joined: June 11th, 2012, 3:13 pm
Location: Enveloping your left flank.

Re: duel scenario endings

Post by junoslord »

Gambrous wrote:
Luther wrote:I used the tool at data/tools/wesnoth/wmlparser.py
How do I use this tool? It would be very beneficial.

Gambrous
Ditto...

Although I notice line errors when the game tries to load, which makes it easier to find mistakes.
America-- Land of the Free, home of the Brave! "And now that we've taken care of the Braves we're coming after the Free."

"BANNED!!! What the hell do you mean BANNED? All I did was call one narrow-minded, power-hungry Nazi moderator a narrow-minded, power-hungry Nazi!"
Post Reply