Samonella's questions: currently unsolved

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.
Tad_Carlucci
Inactive Developer
Posts: 503
Joined: April 24th, 2016, 4:18 pm

Re: Samonella's questions: currently solved

Post by Tad_Carlucci »

You're laboring under the false impression that the intention was to produce a return function similar to C/C++.

First off, that falsely presumes that an [event] is analogous to a function: it is not. That it can be abused to server as one in limited cases is a hack and not intentional.

As I said, the choice of the name [return] was unfortunate. If you insist on using C/C++ as your mental model, think of [return] as more akin to abort().
I forked real life and now I'm getting merge conflicts.
User avatar
Pentarctagon
Project Manager
Posts: 5527
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Samonella's questions: currently solved

Post by Pentarctagon »

I think the point is less what it's named and more that it's current functionality doesn't make it overly useful.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
Tad_Carlucci
Inactive Developer
Posts: 503
Joined: April 24th, 2016, 4:18 pm

Re: Samonella's questions: currently solved

Post by Tad_Carlucci »

I have never found a case where I could not re-arrange the code to use filters, if or loop controls to avoid the need for break, continue or return.

Since [break] outside a loop is 'like return', perhaps [break] can be redefined to break out of the current [event] block 'like return in most other languages'.
I forked real life and now I'm getting merge conflicts.
User avatar
Samonella
Posts: 381
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Samonella's questions: currently solved

Post by Samonella »

Tad_Carlucci wrote:I have never found a case where I could not re-arrange the code to use filters, if or loop controls to avoid the need for break, continue or return.
Sure, that's how everyone got by before 1.13 when these didn't exist at all, it's just inconvenient and messy. I don't mean to argue of course, since it's not like I've contributed to core wesnoth and I'm very grateful for what there is. It's just like Pentarctagon said, my humble opinion is that 'return' is much more useful than 'abort.'
Tad_Carlucci wrote:Since [break] outside a loop is 'like return', perhaps [break] can be redefined to break out of the current [event] block 'like return in most other languages'.
That would work for me. :) It would be a tad inconvenient that you couldn't 'return' from inside a loop, though.
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Samonella's questions: currently solved

Post by Ravana »

Tad_Carlucci wrote:If it were a new tag, I'd quibble over the name: [return] is unfortunate because it has semantics from other programming languages. It means if we ever do add a [function] tag so WML can have true functions, we will either overload the tag with another semantic meaning or we'll need to come up with another tag to do what a function return would do.
I think I will try implementing [function] in Lua soon.

Must include defining functions and calling functions, bonus would be querying functions and modifying functions.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Samonella's questions: currently solved

Post by gfgtdf »

Ravana wrote:I think I will try implementing [function] in Lua soon.

Must include defining functions and calling functions, bonus would be querying functions and modifying functions.
I once made a smilar thing, see https://github.com/wesnoth/wesnoth/pull/931
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: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Samonella's questions: currently solved

Post by Celtic_Minstrel »

I don't think this is the intended meaning of [return]. It's supposed to exit the current event. Why would it also exit an event that fired the current event? Perhaps this could be fixed by editing the implementation of [fire_event] to clear whatever flag tells the engine that return is happening?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Tad_Carlucci
Inactive Developer
Posts: 503
Joined: April 24th, 2016, 4:18 pm

Re: Samonella's questions: currently solved

Post by Tad_Carlucci »

I just looked at how break/return/continue are implemented.

The reason return bails all the way back to the WML engine is there is no way, at present, to mark the entry and exit from an [event] block. All we know is when the loop/switch/conditional (if/then/else) block ends. It should be possible to add a mark for [event] but it's not obvious.

[function] should be held for post-1.14. It, too, will probably need a "scope" pushed onto the stack. And it's probably the best solution, so I'll leave it to you.
I forked real life and now I'm getting merge conflicts.
User avatar
Samonella
Posts: 381
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Samonella's questions: currently solved

Post by Samonella »

Not meaning to interrupt the current discussion, I have another question. Unless I'm doing something wrong, it seems that [effect]apply_to=remove_attacks cannot leave a unit with 0 attacks? My code is like this:

Code: Select all

[modify_unit]
    [filter]
        < filter >
    [/filter]
    [effect]
        apply_to=remove_attacks
    [/effect]
[/modify_unit]
I know I'm filtering correctly, because if it targets a unit that originally had 2 attacks it will end up with 1, but I can't figure out how to remove all of them. Storing the unit, clearing its "attack" array and unstoring it has the same effect.
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Samonella's questions: currently solved

Post by Celtic_Minstrel »

Yeah, at the moment there's no difference between [event] and [command]; only the former should "catch" a return. (Or a [set_menu_item].)

Samonella: Can we see your filter, just in case it is that after all? Another possibility I can think of is maybe an empty weapon filter matches nothing rather than everything, so try something like... [or]range=melee[/or][or]range=ranged[/or]?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Samonella
Posts: 381
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Samonella's questions: currently solved

Post by Samonella »

Celtic_Minstrel wrote:Samonella: Can we see your filter, just in case it is that after all? Another possibility I can think of is maybe an empty weapon filter matches nothing rather than everything, so try something like... [or]range=melee[/or][or]range=ranged[/or]?
I just did some thorough testing:

Each trial used this code:

Code: Select all

[modify_unit]
    [filter]
    [/filter]
    [effect]
        apply_to=remove_attacks
        < a filter >
    [/effect]
    [effect]
        apply_to=hitpoints
        increase_total=200
    [/effect]
[/modify_unit]
I am sure that [modify_unit] affected every unit on the map because they all had the hitpoint change, so the only change from trial to trail was how I filtered in the remove_attacks effect.
Trials and results

Code: Select all

range=ranged
Units with only melee attacks unaffected, units with both melee and ranged lost ranged attacks, and (here's the sticker) no change to units with only ranged attacks (even if they had more than one).

Code: Select all

[or]
    range=melee
[/or]
[or]
    range=ranged
[/or]
No change to any unit's attacks. Huh.

I thought it might be trouble with the [or] so I tried:

Code: Select all

accuracy=0
No change to any unit's attacks, even though I verified in the inspect window that all units' attacks had accuracy=0.

Code: Select all

# no filter
Still no change to any unit. I've been very careful to refresh (f5) from the main menu between each trial, btw.

The wiki says not to use [filter] blocks, but I tried these anyway:

Code: Select all

[filter]
    range=ranged
[/filter]
No change to any unit.

Code: Select all

[filter_weapon]
    range=ranged
[/filter_weapon]
No change to any unit.
Like I said before, I've also tried storing the unit, clearing its attacks, and unstoring it. By putting an [inspect] tag just before unstoring, I'm certain that the unit being unstored had no record of it's previous attacks, but it ended up with all attacks defined in the unit_type. I should mention that I've been successful clearing only 1 attack in this way (when the unit originally had multiple).
The code I used testing that:
Sooo... maybe there is some check for units with incomplete data, that fills in information from the unit_type? I suppose that would be a good thing in most cases, say if there was no movement= key. There are unit_types with no attacks... well, idk what to think.

Just for kicks, I tried adding the line {VARIABLE temp_unit.type "This type does not exist"} to the storing-unstoring trial, but not surprisingly I just got a lua error for the unknown unit_type.
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Samonella's questions: currently solved

Post by zookeeper »

Samonella wrote:Sooo... maybe there is some check for units with incomplete data, that fills in information from the unit_type?
Yes, that's surely what's happening there.

As for the [effect] thing, that definitely seems like a bug, but it's unclear whether it's a bug with apply_to=remove_attacks in general or a bug with [modify_unit] [effect]. Did you try to do it by passing the [effect] in an [object] instead?
User avatar
Samonella
Posts: 381
Joined: January 8th, 2016, 5:41 pm
Location: USA

Re: Samonella's questions: currently solved

Post by Samonella »

zookeeper wrote:Did you try to do it by passing the [effect] in an [object] instead?
Just tried it, and was surprised to see it works!
The last few months have been nothing but one big, painful reminder that TIMTLTW.

Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Samonella's questions: currently solved

Post by Celtic_Minstrel »

Oh, I suddenly wonder whether this has something to do with that "don't write empty tags" change from awhile ago...
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Samonella's questions: currently solved

Post by gfgtdf »

Celtic_Minstrel wrote:Oh, I suddenly wonder whether this has something to do with that "don't write empty tags" change from awhile ago...
It's probably a similar probloem but not caused by that patch, unlike abiltites which go into a container tag ([abilities]) the [attack]s are directly written into the [unit] which means there is no way to the engine to make a difference between an 'empty list of of attacks' and 'no list of attacks' whihc causes the same issue that we had with abilitites in 1.13+dev at some point.
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.
Post Reply