Help coding 'ricochet' weapon special.

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
someone
Posts: 188
Joined: March 13th, 2009, 9:03 pm

Help coding 'ricochet' weapon special.

Post by someone »

I'm trying to code a special attack for personal use, but I've run into an unknown problem in my code while trying to test it.
The error details reads "Missing closing tag for tag unstore_unit" but as far I can tell that isn't the problem at all.
The attack has a weapon special called ricochet that is supposed to cause the attack to have a chance to damage more units if it hits initially. The problem is most likely in this area of code:
Spoiler:
Expanding Wesnoth

You are an Arch Mage - You're definitely intelligent, but some people would say you spend too much time inside. The power you have learned, however, is simply unmatched.
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: Help coding 'ricochet' weapon special.

Post by A Guy »

At a glance, I can't notice any errors with [unstore_unit] tags. Would you mind posting the stderr.txt?
I'm just... a guy...
I'm back for now, I might get started on some work again.
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Help coding 'ricochet' weapon special.

Post by Max »

a macro isn't a function call. the way (looks unnecessarily complicated anyway) you use CAP_SHIELD_RICOCHET_A and CAP_SHIELD_RICOCHET_B results in an infinite recursion...
User avatar
someone
Posts: 188
Joined: March 13th, 2009, 9:03 pm

Re: Help coding 'ricochet' weapon special.

Post by someone »

@Max: Do you think the loop is causing the error? I'm not sure how else to make it work.

@A Guy: How do I find the stderr.txt? I'm using a Mac btw.
Expanding Wesnoth

You are an Arch Mage - You're definitely intelligent, but some people would say you spend too much time inside. The power you have learned, however, is simply unmatched.
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: Help coding 'ricochet' weapon special.

Post by A Guy »

stderr.txt should be in the main folder for Wesnoth.
I'm just... a guy...
I'm back for now, I might get started on some work again.
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Help coding 'ricochet' weapon special.

Post by 8680 »

someone wrote:How do I find the stderr.txt? I'm using a Mac btw.
boru wrote:To see stderr messages on a Mac:
- Open Wesnoth by control clicking and choose "show package contents"
- Open the "Macintosh" folder. Inside are two terminal scripts, drag the one named Wesnoth to your dock and click it to launch the game every time
- Terminal will open and then launch Wesnoth
- stderr messages will be in Terminal.
Alarantalara wrote:Another way to view the stderr messages on a Mac is to use the Console application in /Applications/Utilities
All stderr messages that aren't displayed in Terminal using boru's method are logged in the Console Messages log (you may need to show the log list to find it). This will let you see messages even if you forget to start it boru's way.
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Help coding 'ricochet' weapon special.

Post by Max »

someone wrote:@Max: Do you think the loop is causing the error? I'm not sure how else to make it work
yes.
here's whats happening:

the preprocessor reads your event, comes to the place where you use CAP_SHIELD_RICOCHET_A. it get's replaced with the contents of that macro. inside that macro you use CAP_SHIELD_RICOCHET_B. this again is replaced with the contents, now there's CAP_SHIELD_RICOCHET_A inside CAP_SHIELD_RICOCHET_B and so on.
usually you run out of memory or there's a stack overflow. not sure why it's not crashing. maybe there's a hardcoded limit somewhere.

looking at your code (correct me if i'm wrong) i guess that's what your trying to do:
if a unit is hit there's a 50% chance that an adjacent unit of the same side might get hit.

- use a while loop (as long as there are units to process and your special didn't miss)
(to know we've processed a unit we can set a unit variable. see http://wiki.wesnoth.org/SingleUnitWML)
- store adjacent unit (range=1, x,y of last unit, side!=attacker, [filter_wml] for our unit variable, see above).
(remember that [store_unit] can store more than one unit, we'll use the first one only)
- set a unit variable so we know we've processed that unit
User avatar
someone
Posts: 188
Joined: March 13th, 2009, 9:03 pm

Re: Help coding 'ricochet' weapon special.

Post by someone »

Can an [while] tag include an else tag?
Expanding Wesnoth

You are an Arch Mage - You're definitely intelligent, but some people would say you spend too much time inside. The power you have learned, however, is simply unmatched.
User avatar
Crendgrim
Moderator Emeritus
Posts: 1328
Joined: October 15th, 2010, 10:39 am
Location: Germany

Re: Help coding 'ricochet' weapon special.

Post by Crendgrim »

ConditionalActionsWML#while
No.
Assuming the wiki is right, you'll have to use an independent [if] construct.


Crend
UMC Story Images — Story images for your campaign!
User avatar
someone
Posts: 188
Joined: March 13th, 2009, 9:03 pm

Re: Help coding 'ricochet' weapon special.

Post by someone »

So, I tried reworking it using the [while] tag, and here's what I came up with:
Spoiler:
But, when the attack tries to hit a third target, the game stops responding.
Expanding Wesnoth

You are an Arch Mage - You're definitely intelligent, but some people would say you spend too much time inside. The power you have learned, however, is simply unmatched.
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Help coding 'ricochet' weapon special.

Post by Max »

that's because you've create an infinite loop somehow (that's an improvement compared to infinite recursion^^)

use debug messages to see why this is happening.
Post Reply