Samonella's questions: currently unsolved
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.
-
- Inactive Developer
- Posts: 503
- Joined: April 24th, 2016, 4:18 pm
Re: Samonella's questions: currently solved
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().
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.
- Pentarctagon
- Project Manager
- Posts: 5564
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: Samonella's questions: currently solved
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
take one down, patch it around
-2,147,483,648 little bugs in the code
-
- Inactive Developer
- Posts: 503
- Joined: April 24th, 2016, 4:18 pm
Re: Samonella's questions: currently solved
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'.
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.
Re: Samonella's questions: currently solved
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: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.
That would work for me. It would be a tad inconvenient that you couldn't 'return' from inside a loop, though.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'.
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
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
Re: Samonella's questions: currently solved
I think I will try implementing [function] in Lua soon.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.
Must include defining functions and calling functions, bonus would be querying functions and modifying functions.
Re: Samonella's questions: currently solved
I once made a smilar thing, see https://github.com/wesnoth/wesnoth/pull/931Ravana 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.
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.
- Celtic_Minstrel
- Developer
- Posts: 2211
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Samonella's questions: currently solved
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?-
- Inactive Developer
- Posts: 503
- Joined: April 24th, 2016, 4:18 pm
Re: Samonella's questions: currently solved
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.
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.
Re: Samonella's questions: currently solved
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: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.
Code: Select all
[modify_unit]
[filter]
< filter >
[/filter]
[effect]
apply_to=remove_attacks
[/effect]
[/modify_unit]
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
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
- Celtic_Minstrel
- Developer
- Posts: 2211
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Samonella's questions: currently solved
Yeah, at the moment there's no difference between
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...
[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]
?Re: Samonella's questions: currently solved
I just did some thorough testing: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]
?
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]
Trials and results
The code I used testing that:
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
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
Re: Samonella's questions: currently solved
Yes, that's surely what's happening there.Samonella wrote:Sooo... maybe there is some check for units with incomplete data, that fills in information from the unit_type?
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?
Re: Samonella's questions: currently solved
Just tried it, and was surprised to see it works!zookeeper wrote:Did you try to do it by passing the [effect] in an [object] instead?
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
Creator of Armory Mod, The Rising Underworld, and Voyage of a Drake: an RPG
- Celtic_Minstrel
- Developer
- Posts: 2211
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Samonella's questions: currently solved
Oh, I suddenly wonder whether this has something to do with that "don't write empty tags" change from awhile ago...
Re: Samonella's questions: currently solved
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.Celtic_Minstrel wrote:Oh, I suddenly wonder whether this has something to do with that "don't write empty tags" change from awhile ago...
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.