ghype's Problems:

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
ghype
Posts: 1056
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Problem: [side] + custom unit

Post by ghype »

Lord-Knightmare wrote: November 25th, 2020, 6:22 pm The problem is where I suspected. Your custom unit is in units/dunefolk but you are not including that subdirectory in your [+units][/units]. Thus, it will never be loaded in game. You have to include it with:
Thanks a lot ! it worked.
Do I have to include every subdirectory of untis there?
beetlenaut wrote: November 25th, 2020, 6:39 pm You also have to fix the end tags of the attacks in the unit file or it will still fail to load.
Thanks for noticing!
User avatar
beetlenaut
Developer
Posts: 2529
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: ghype's Problem: [side] + custom unit

Post by beetlenaut »

ghype wrote: November 25th, 2020, 8:13 pm Do I have to include every subdirectory of untis there?
Yes. The standard way of organizing the unit files (if you have a lot of them) is to use prefixes in the file names instead of using subdirectories. Take a look at the undead in core to see what I mean: All the filenames start with a prefix like Spirit or Skele.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
ghype
Posts: 1056
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Problem: [side] + custom unit

Post by ghype »

beetlenaut wrote: November 25th, 2020, 8:32 pm Yes. The standard way of organizing the unit files (if you have a lot of them) is to use prefixes in the file names instead of using subdirectories. Take a look at the undead in core to see what I mean: All the filenames start with a prefix like Spirit or Skele.
I'll keep that in mind. Probably won't have that many.
User avatar
ghype
Posts: 1056
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

ghype's Problems: adding custom ability

Post by ghype »

Last one for 2day. I seem to struggle at the most basic things ...

so now I tried to implement my first ever event based ability into a campaign. This is the error I get:

Code: Select all

    Macro/file 'PL_ABILITY_ENDLESS_MP' is missing
    at ~add-ons/Plagued/units/dunefolk/Khyret.cfg:20
        included from ~add-ons/Plagued/_main.cfg:67
the abilities.cfg lays in my utils subdirectory and as shown earlier the binary paths are included:
binary_path

Code: Select all

#ifdef Plagued

	[binary_path]
		path=data/add-ons/Plagued/
	[/binary_path]
	[+units]
		{~add-ons/Plagued/units}
        {~add-ons/Plagued/units/dunefolk}
	[/units]
	{~add-ons/Plagued/utils}
	{~add-ons/Plagued/maps}
	{~add-ons/Plagued/scenarios}
	{~add-ons/Plagued/images}
#endif
According to the error, the engine finds the ability on the unit I want it to be used on. The ability it self is not found in the ability.cfg where I defined it. Here is the structure of the ability and I wonder if something is wrong
with the structure or the ability itself.

Code: Select all

#textdomain wesnoth-Plagued


#define PL_ABILITY_ENDLESS_MP
    [dummy]
        id=PL_endless_mp
        name= _ " "
        description=_" "
    [/dummy] # wmlxgettext: [abilities]
[/abilities]
[event]
    name=no_mp
    first_time_only=no
    id=PL_endless_mp

    [set_variable]
        name=no_mp
        value=0
    [/set_variable]

    [store_unit]
        [filter]
            ability=PL_endless_mp
        [/filter]
        variable=endless_mp
    [/store_unit]
    [if]
        [variable]
            name=endless_mp.moves
            equals=no_mp
        [/variable]
    [/if]
    [then]
        {VARIABLE_OP furious.moves add 5}
    [/then]
    [unstore_unit]
        variable=endless_mp
    [/unstore_unit]
[/event]

[+abilities] # wmlxgettext: [/abilities]    
#enddef

The Ability intends to add 5 mp when ever the current mp of the unit becomes 0.
Since I cannot test due to the error above and it is the first time I use variables to that excess, I don't know if that even works as intended.
So if you have some thoughts on that, they would be appreciated. Thansk.
User avatar
beetlenaut
Developer
Posts: 2529
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: ghype's Problems

Post by beetlenaut »

You only define the macro after trying to use it in your unit file. You need to include the utils folder before [+units].
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
ghype
Posts: 1056
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

ghype's Problems: [ability] adding mp

Post by ghype »

beetlenaut wrote: November 26th, 2020, 1:46 am You only define the macro after trying to use it in your unit file. You need to include the utils folder before [+units].
seems legit. it found it now and had some syntax errors meaning that it found the ability.

however, i realised that the initial draft for the ability, which should add 5mp once all mp are consumed, was not doing that. (mostly because if forgot the [fire_event] tag). So I rewrote it and I am think I got the structure right.

Sadly it still doesn't do anything, but it also does not give me any errors.
Any one can tell me what I have to change in order for it to do something?

Code: Select all

#define PL_ABILITY_ENDLESS_MP
    [dummy]
        id=PL_endless_mp
        name= _ "   "
        description=_"    "
    [/dummy] # wmlxgettext: [abilities]
[abilities]
[event]
    name=no_mp  
    first_time_only=no    

    [store_unit]
    
        [filter]
            ability=PL_endless_mp
        [/filter]
        variable=endless_mp
    [/store_unit]
    {VARIABLE_OP endless_mp.moves add 5}
    [unstore_unit]
        variable=endless_mp
    [/unstore_unit]
[/event]
[fire_event]
    name=no_mp
    [filter_condition]
        [variable]
            name=endless_mp
            euqals=0
        [/variable]
    [/filter_condition]
[/fire_event]

[/abilities] # wmlxgettext: [/abilities]    
#enddef

User avatar
beetlenaut
Developer
Posts: 2529
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: ghype's Problems: [ability] adding mp

Post by beetlenaut »

All tags are only allowed in specific places. You can't use [event] or [fire_event] inside [abilities]. They are only allowed under [scenario], [unit_type], and [era]. If you use them anywhere else, they are ignored. You are probably using this inside an [abilities] tag already, so you have to drop out of it temporarily (with [/abilities]) to define the events inside [unit_type]. Then use [+abilities] at the end to go back to the original tag.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
ghype
Posts: 1056
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Problems: [ability] adding mp

Post by ghype »

beetlenaut wrote: November 26th, 2020, 7:29 pm You are probably using this inside an [abilities] tag already, so you have to drop out of it temporarily (with [/abilities]) to define the events inside [unit_type]. Then use [+abilities] at the end to go back to the original tag.
yeah, i had that initially that way as every event based ability seems to be that way. I however was confused by the [/ability] in the start of the code as I didn't knew what # wmlxgettext: [abilities] was for. But now I understood that is for exactly that: temporarily jumping out of the ability tag. So thanks for clearing that up.

Nonetheless, it still doesn't do anything. The [event] I coded seems straight forward. Is the [fire_event] wrong?

Code: Select all

#define PL_ABILITY_ENDLESS_MP
    # wmlxgettext: [abilities]
    [dummy]
        id=PL_endless_mp
        name= _ "   "
        description=_"    "
    [/dummy] 
    [/ability]
    
[event]
    name=no_mp  
    first_time_only=no    

    [store_unit]
        [filter]
            ability=PL_endless_mp
        [/filter]
        variable=endless_mp
    [/store_unit]

    {VARIABLE_OP endless_mp.moves add 5}

    [unstore_unit]
        variable=endless_mp
    [/unstore_unit]
[/event]

[fire_event]
    name=no_mp
    [filter_condition]
        [variable]
            name=endless_mp
            euqals=0
        [/variable]
    [/filter_condition]
[/fire_event]

[+abilities]
    # wmlxgettext: [/abilities]
#enddef
User avatar
beetlenaut
Developer
Posts: 2529
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: ghype's Problems: [ability] adding mp

Post by beetlenaut »

You used [/ability] instead of [/abilities] in the end tag. You also spelled "equals" wrong.

I didn't notice before, but [fire_event] won't work here either. That filter should just be part of the event.

The wmlgettext comments are ignored by the game and don't do anything in your code. They are only read by the wmlgettext program, which is used by translators. It can't process tags correctly when they are broken up, so fake beginning and ending tags are put in to keep it happy.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
ghype
Posts: 1056
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Problems: [ability] adding mp

Post by ghype »

beetlenaut wrote: November 26th, 2020, 10:05 pm You used [/ability] instead of [/abilities] in the end tag. You also spelled "equals" wrong.
If I revert to the fake tags, i get this error. It finds the [/abilities] as closing tag for the [unit_type]. Seems like my fake tags won't work. The code remained the same as before, I just fixed the "equals" as well.

Code: Select all

Found invalid closing tag [/abilities] for tag [unit_type]
    opened at ~add-ons/Plagued/units/dunefolk/Khyret.cfg:3
        included from ~add-ons/Plagued/_main.cfg:68
    closed at ~add-ons/Plagued/utils/abilities.cfg:10
        included from ~add-ons/Plagued/_main.cfg:65
        included from ~add-ons/Plagued/units/dunefolk/Khyret.cfg:20
        included from ~add-ons/Plagued/_main.cfg:68
beetlenaut wrote: November 26th, 2020, 10:05 pm I didn't notice before, but [fire_event] won't work here either. That filter should just be part of the event.

I initially had that filter in the [even] tag as well. Then I read / remembered that custom events need an [fire_event] in order to be triggered. If I remove that, how else is it gonna be triggered?


UPDATE:
Hejnewar showed me an easier way to code it with event enter/exit hex, so i wont need the [fire_event] no longer. But I still need to make the dummy work. I won't get around that error.
User avatar
beetlenaut
Developer
Posts: 2529
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: ghype's Problems: [ability] adding mp

Post by beetlenaut »

ghype wrote: November 27th, 2020, 9:01 am If I revert to the fake tags, i get this error. Seems like my fake tags won't work.
Just take out the wmlgettext lines for the time being. They aren't doing anything, and they can't cause or fix any errors, but they are confusing the issue. You don't need them until your campaign is getting translated.
ghype wrote: November 27th, 2020, 9:01 am It finds the [/abilities] as closing tag for the [unit_type].
You must have another error where this code is included. You may have misspelled the [abilities] opening tag in the unit file.
ghype wrote: November 27th, 2020, 9:01 am how else is it gonna be triggered?
That's what the name key is for: it describes when the event is triggered. That's how all events are triggered. You probably do want name=enter_hex. [fire_event] is rarely needed. It's for more complex code than this.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Shiki
Developer
Posts: 318
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: ghype's Problems: [ability] adding mp

Post by Shiki »

The problem is that you wrote ability in singular, but the tag is called abilities nevertheless.

Let me throw in a variant with [heal_unit] instead of storing & unstoring:

Code: Select all

#define PL_ABILITY_ENDLESS_MP
    # wmlxgettext: [abilities]
        [dummy]
            id=PL_endless_mp
            name= _ "…"
            description= _ "…"
        [/dummy] 
    [/abilities]

    [event]
        name=moveto
        # ID is needed here, so that if two units with the ability exist
        # the event will only be inserted once
        id=no_mp
        first_time_only=no
        [filter]
            ability=PL_endless_mp # so it's not triggering for say a Spearman
            x,y=$x1,$y2           # so it's only for that one unit, not every with the ability
        [/filter]

        [heal_unit]
            [filter]
                id=$unit.id
            [/filter]
            amount=0
            restore_statuses=no
            moves=full
        [/heal_unit]
        {CLEAR_VARIABLE heal_amount} # [heal_unit] always sets this variable
    [/event]

    [+abilities]
    # wmlxgettext: [/abilities]
#enddef
The part with the [+abilities] tag is just trickery, the event's could also be inserted separately somewhere else without that.

For the [fire_unit] part, maybe below code makes clear the usage. moveto / enter_hex (with space as well as underscore) is one of the few events fired by the engine, all others are only fired by us:

Code: Select all

    [event]
        name=moveto
        id=no_mp
        first_time_only=no
        [filter]
            ability=PL_endless_mp
            x,y=$x1,$y2
        [/filter]

        [fire_event]
            name=another event
            [primary_unit]
                id=$unit.id
            [/primary_unit]
        [/fire_event]
    [/event]

    [event]
        name=another event
        first_time_only=no

        [heal_unit]
            [filter]
                id=$unit.id
            [/filter]
            amount=0
            restore_statuses=no
            moves=full
        [/heal_unit]
        {CLEAR_VARIABLE heal_amount} # [heal_unit] always sets this variable
    [/event]
Try out the dark board theme.
User avatar
ghype
Posts: 1056
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

ghype's Problems: endless mp

Post by ghype »

Thank you guys for your efforts. I really cannot tell why this ain't work. When I developed and implemented my era into Ageless_Era for example, I had no problem with the dummy events. Now for some reason It won't work any more just as easy.
Shiki wrote: November 28th, 2020, 10:01 am The problem is that you wrote ability in singular, but the tag is called abilities nevertheless.
This I already fixed in the previous version of my code.
Shiki wrote: November 28th, 2020, 10:01 am Let me throw in a variant with [heal_unit] instead of storing & unstoring:
I used your suggestions and I cannot check if they work as I still get the same error as before.
beetlenaut wrote: November 27th, 2020, 6:21 pm You must have another error where this code is included. You may have misspelled the [abilities] opening tag in the unit file.
I don't use the [abilities] tag at all in my unit file. I use the macro {PL_ABILITY_ENDLESS_MP} for example.
Does that might be the reason?

-------------------------

Anyhow, as mentioned in my last post, Hejnewar showed me a very simple way to make this "ability" work.

Code: Select all

        ## making endless movepoints
        
        [event]
                    name = moveto
                    first_time_only = no

                    [modify_unit]
                        [filter]
                            side = 1
                        [/filter]

                        moves = 5
                    [/modify_unit]
                [/event]
And it works! Placed in the prestart event.
Then I was thinking, OK how do I turn it on and off. Purpose of the ability is able to explore a vast map without having to end turns all the time. Certainly it should not work once you get in combat.

So I was thinking to set a variable and as long that variable has a certain value (0 or 1) it does that event. That way I can set it to 0 right before a combat. So this is what I came up with. This is placed in the prestart event:

Code: Select all

 ## making endless movepoints
        [set_variable]
            name=exploration
            value=1
        [/set_variable]
        
        [while]   
            [variable]
                name=exploration
                equals=1
            [/variable]
            [do]
                [event]
                    name = moveto
                    first_time_only = no

                    [modify_unit]
                        [filter]
                            side = 1
                        [/filter]

                        moves = 5
                    [/modify_unit]
                [/event]
            [/do]
        [/while] 

It sadly does it now fails to load the entire scenario. I was thinking that I could do it also with an [if] but the [while] seemed better suiting for the purpose. As simple as it seems, what did I not take in account?
vghetto
Posts: 307
Joined: November 2nd, 2019, 5:12 pm

Re: ghype's Problems: endless mp

Post by vghetto »

You could use [filter_condition] on the moveto event to turn it on and off.
Maybe, you could also add unit.id in the filter instead of modifying all of side 1 in every movement.

The while loop seems to go into an infinite loop. And I think it will create many many moveto event and all of them will trigger on any movement!
User avatar
ghype
Posts: 1056
Joined: December 13th, 2016, 4:43 pm
Location: Berlin, Germany

Re: ghype's Problems: endless mp

Post by ghype »

vghetto wrote: November 28th, 2020, 1:35 pm You could use [filter_condition] on the moveto event to turn it on and off.
I changed according to your suggestion and keeps on working:

Code: Select all

## making endless movepoints
        [event]
            [set_variable]
                name=exploration
                value=1
            [/set_variable]

            name=moveto
            first_time_only=no

            [modify_unit]
                [filter]
                    side=1 
                    [filter_condition]
                        name=exploration
                        equals=1
                    [/filter_condition]
                [/filter]

                moves=5
            [/modify_unit]
        [/event]
But when I modify the variable in a different event in order to turn it off, it won't recognize it and will go on.

Code: Select all

# this somehwere later in another event
[set_variable]
            name=exploration
            value=0
        [/set_variable]
Are you sure that it that event will keep on rolling in the background and everytime I set the variable either to 0 or 1 it will turn on and off ?
Post Reply