array not arraying [SOLVED]

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.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

array not arraying [SOLVED]

Post by Helmet »

Edit: If you are reading this post to learn about arrays...
I suggest that you skip to page 4 and read my post at the top. It has the functional code and an explanation. All the earlier posts are related to debugging.
+++++++++++++++++++++++++++++++++++++++++++++++++++


There are gaps in my knowledge of wml big enough to drive a truck through. So I've been trying to address those gaps. One such gap is arrays, so I made an array.

This is what it's supposed to do:
When a unit is frozen (2-turn petrify), they get a new variable to track their frozen-ness called how_frozen. The value ranges from 0-2, where 0 means not frozen, 1 means halfway frozen (thawing), and 3 means frozen. Each turn the value drops by 1, so on the third turn after being frozen, a unit that had been frozen will have a how_frozen=0 and become unpetrified.

It took me a long time to get it how_frozen to work, but it does. I learned a lot about variables. The problem is the array doesn't recognize the variable, so the value of how_frozen doesn't decline and the unit can't thaw.

Do you know why this_item.id.how_frozen does not work in the [foreach]loop? Thanks for your help. There are a few messages in the code that I used to test values.
Spoiler:
Last edited by Helmet on November 22nd, 2022, 4:54 pm, edited 4 times in total.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
beetlenaut
Developer
Posts: 2812
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: array not arraying

Post by beetlenaut »

In the attacker_hits event, you store a unit into a variable, then manipulate that stored variable. You never convert the variable back into a unit with [unstore_unit]. You need to do that. Units are characters on the map, but stored units are only variables in the computer's memory. (Alternatively, you could remove the [store_unit] and put your [set_variable] inside a [modify_unit] tag, because that tag is a shortcut that does that storing and unstoring automatically.)

Also, I see that you did use [unstore_unit] above after [unpetrify] (which I don't understand), but it's not in the correct format: [unstore_unit] takes the name of a stored variable. You seem to be trying to use a unit filter instead.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: array not arraying

Post by Helmet »

beetlenaut wrote: November 21st, 2022, 4:24 am In the attacker_hits event, you store a unit into a variable, then manipulate that stored variable. You never convert the variable back into a unit with [unstore_unit]. You need to do that. Units are characters on the map, but stored units are only variables in the computer's memory. (Alternatively, you could remove the [store_unit] and put your [set_variable] inside a [modify_unit] tag, because that tag is a shortcut that does that storing and unstoring automatically.)

Also, I see that you did use [unstore_unit] above after [unpetrify] (which I don't understand), but it's not in the correct format: [unstore_unit] takes the name of a stored variable. You seem to be trying to use a unit filter instead.
Thanks for helping. I had written three events: new turn, new turn, and attacker hits. If I understood your notes, the first new turn event was correct. The second new turn event needed me to delete the improper unstore_unit above the petrify, which I did. And the attacker hits needed me to replace store_unit with modify_unit and set_variable, which I did.

Unfortunately, it's still not working. My "messages" show that the this_item.id.how_frozen variable isn't working in the new turn events.

Here is the revised attacker hits code. Did I misunderstand what I was supposed to do? Thanks.

Code: Select all

[event]
    name=attacker hits
    first_time_only=no
    [filter_attack]
        special=freezes
    [/filter_attack]

    [modify_unit]
        [filter]
            id=second_unit.id  # 		an id stores a specific unit in an array.
        [/filter]
        [set_variable]
            name=second_unit.id.how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
            value=2
        [/set_variable]
    [/modify_unit]

    [message]
        speaker=MyLeader
        message="second_unit.id.how_frozen : " $second_unit.id.how_frozen
    [/message]
    [message]
        speaker=MyLeader
        message="Petrified! Variable for second_unit.id.how_frozen : " $second_unit.id.how_frozen
    [/message]
[/event]
And here are the first two events. Same as last time, minus the unstore_unit.

Code: Select all

	[event] #                                                       T H A W I N G     E V E N T
		name=new turn
        first_time_only=no
        [store_unit]
            [filter]
                side=2  # This will store all of the side 2 units in an array.
                status=petrified
            [/filter]
            variable=target_units  # "unit" as a variable name is reserved for the unit that triggers an event, so try not to use it for other things.  It could get confusing.
        [/store_unit]
        [foreach]
            array=target_units
            [do]
                [if]
    #				instead of using x,y coordinates   x=$this_item.x| and   y=$this_item.y|  ,you could use   id=this_item.id
    # 				it's very important that (inside of a [foreach] loop) you always make sure that your filters can only apply to exactly one unit at a time.
                    [variable]
                        name=this_item.id.how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
                        equals=2
                    [/variable]
                    [then]
                        [message]
                            speaker=MyLeader
                            message="The value is 2"
                        [/message]
                        [set_variable]
                            name=this_item.id.how_frozen
                            value=1 #                               unit was frozen, but is now thawing. Unit will unpetrify next turn.
                        [/set_variable]
                    [/then]

                    [elseif]
                        [variable]
                            name=$this_item.id.how_frozen
                            equals=1
                        [/variable]
                        [then]
                            [message]
                                speaker=MyLeader
                                message="The value is 1"
                            [/message]
                            [set_variable]
                                name=this_item.id.how_frozen
                                value=0 #                           unit was thawing, but is now completely thawed. Unit is ready to be unpetrified
                            [/set_variable]
                        [/then]
                    [/elseif]
                    [else]
                        [message]
                            speaker=MyLeader
                            message="The value is ?"
                        [/message]
                    [/else]
                [/if]
            [/do]
        [/foreach]
    [/event]

    [event] #                                                       U N P E T R I F Y     E V E N T
        name=new turn
        first_time_only=no
        [set_variable]
            name=whatever
            value="Pogg" #                           unit was thawing, but is now completely thawed. Unit is ready to be unpetrified
        [/set_variable]
        [message]
            speaker=MyLeader
            message="New turn. Variable for second_unit.id.how_frozen: " $second_unit.id.how_frozen
        [/message]
        [store_unit]
            [filter]
                side=2  # This will store all of the side 1 units in an array.
            [/filter]
            variable=target_units2  # "unit" as a variable name is reserved for the unit that triggers an event, so try not to use it for other things.  It could get confusing.
        [/store_unit]
        [foreach]
            array=target_units2
            [do]
                [if]
                    [variable]
                        name=$this_item.id.how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
                        equals=0
                    [/variable]
                    [then]
                        [unpetrify] #                               any unit that is not frozen or thawing will be unpetrified
                            id=this_item.id
                        [/unpetrify]
                    [/then]
                [/if]
            [/do]
        [/foreach]
    [/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
beetlenaut
Developer
Posts: 2812
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: array not arraying

Post by beetlenaut »

Your main problem seems to be using $ pretty much at random. The $ pulls out the value stored in a variable, and substitutes that for the variable name you typed. For example, at one point you have name=$this_item.id.how_frozen. Because of the $, this statement pulls out the number stored in that variable and substitutes it into your statement, meaning that this line will be converted to name=2 (or whatever number). That is definitely not what you wanted! You have several mistakes of this kind, so check all the lines with a variable in them. Make sure you understand what the tag is asking for and what you have given it.

You also have a problem with your [set_variable] in the first part. If you use [modify_unit], you are already "inside" the unit container variable, so don't specify it again in the name= line. That should just be name=how_frozen.

There may be more problems, but fix the above problems first.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: array not arraying

Post by Helmet »

beetlenaut wrote: November 21st, 2022, 5:53 am...If you use [modify_unit], you are already "inside" the unit container variable, so don't specify it again in the name= line. That should just be name=how_frozen.
Oh, that makes perfect sense. I like it when the rules make perfect sense.

I used to use $ at random, but I think I know the correct time to use $ nowadays, so I'm surprised a couple mistakes were in my code. I think I introduced them when I was copy/pasting variable names.

I fixed those mistakes but nothing changed when play-testing.

I wonder if something is wrong with unpetrify.

Thanks.

Code: Select all

	[event] #                                                       T H A W I N G     E V E N T
		name=new turn
        first_time_only=no
        [store_unit]
            [filter]
                side=2  # This will store all of the side 2 units in an array.
                status=petrified
            [/filter]
            variable=target_units  # "unit" as a variable name is reserved for the unit that triggers an event, so try not to use it for other things.  It could get confusing.
        [/store_unit]
        [foreach]
            array=target_units
            [do]
                [if]
    #				instead of using x,y coordinates   x=$this_item.x| and   y=$this_item.y|  ,you could use   id=this_item.id
    # 				it's very important that (inside of a [foreach] loop) you always make sure that your filters can only apply to exactly one unit at a time.
                    [variable]
                        name=this_item.id.how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
                        equals=2
                    [/variable]
                    [then]
                        [message]
                            speaker=MyLeader
                            message="The value is 2"
                        [/message]
                        [set_variable]
                            name=this_item.id.how_frozen
                            value=1 #                               unit was frozen, but is now thawing. Unit will unpetrify next turn.
                        [/set_variable]
                    [/then]

                    [elseif]
                        [variable]
                            name=this_item.id.how_frozen
                            equals=1
                        [/variable]
                        [then]
                            [message]
                                speaker=MyLeader
                                message="The value is 1"
                            [/message]
                            [set_variable]
                                name=this_item.id.how_frozen
                                value=0 #                           unit was thawing, but is now completely thawed. Unit is ready to be unpetrified
                            [/set_variable]
                        [/then]
                    [/elseif]
                    [else]
                        [message]
                            speaker=MyLeader
                            message="The value is ?"
                        [/message]
                    [/else]
                [/if]
            [/do]
        [/foreach]
    [/event]

    [event] #                                                       U N P E T R I F Y     E V E N T
        name=new turn
        first_time_only=no
        [set_variable]
            name=whatever
            value="Pogg" #                           unit was thawing, but is now completely thawed. Unit is ready to be unpetrified
        [/set_variable]
        [message]
            speaker=MyLeader
            message="New turn. Variable for second_unit.id.how_frozen: " $second_unit.id.how_frozen
        [/message]
        [store_unit]
            [filter]
                side=2  # This will store all of the side 1 units in an array.
            [/filter]
            variable=target_units2  # "unit" as a variable name is reserved for the unit that triggers an event, so try not to use it for other things.  It could get confusing.
        [/store_unit]
        [foreach]
            array=target_units2
            [do]
                [if]
                    [variable]
                        name=this_item.id.how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
                        equals=0
                    [/variable]
                    [then]
                        [unpetrify] #                               any unit that is not frozen or thawing will be unpetrified
                            id=this_item.id
                        [/unpetrify]
                    [/then]
                [/if]
            [/do]
        [/foreach]
    [/event]

[event]
    name=attacker hits
    first_time_only=no
    [filter_attack]
        special=freezes
    [/filter_attack]

    [modify_unit]
        [filter]
            id=second_unit.id  # 		an id stores a specific unit in an array.
        [/filter]
        [set_variable]
            name=how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
            value=2
        [/set_variable]
    [/modify_unit]

    [message]
        speaker=MyLeader
        message="second_unit.id.how_frozen : " $second_unit.id.how_frozen
    [/message]
    [message]
        speaker=MyLeader
        message="Petrified! Variable for second_unit.id.how_frozen : " $second_unit.id.how_frozen
    [/message]
[/event]
Just in case, here's the weapon special.

Code: Select all

#define WEAPON_SPECIAL_FREEZE
    [petrifies] # 							based on PETRIFY
        id=freezes
        name= _ "freezes"
        description= _ "This attack freezes the target in a layer of ice. Frozen units are petrified for 2 turns."
        # special_note={INTERNAL:SPECIAL_NOTES_PETRIFY}
    [/petrifies]
#enddef
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
beetlenaut
Developer
Posts: 2812
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: array not arraying

Post by beetlenaut »

Helmet wrote: November 21st, 2022, 6:10 am I fixed those mistakes
You still have a couple filter lines that need a $. I don't think you actually have a unit on the screen with an id of "second_unit.id" or "this_item.id" !

BTW, if you are not using a syntax highlighter, that would probably help to spot these things.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: array not arraying

Post by Helmet »

beetlenaut wrote: November 21st, 2022, 6:26 am You still have a couple filter lines that need a $. I don't think you actually have a unit on the screen with an id of "second_unit.id" or "this_item.id" !
I have no idea what you're talking about. The filters seem fine to me, except maybe the one in modify_unit, which has weird rules.
Wiki: The unit which is currently modified is accessible via $this_unit, e.g. hitpoints = "$($this_unit.hitpoints / 2)" to set the hitpoints of all units to half of their particular maxima. This this_unit variable is independent from the this_unit variable available in the SUF used to determine which units to modify (first all matching units are gathered, and then all those are modified).
I added a $ to that filter and nothing happened. I'm not seeing what you're seeing. Maybe you're looking at the debugging messages? I deleted most of them to make the code simpler.

Look at the very bottom of the code, at the message. When play-testing, it produces nothing after the text, not even a zero.

Code: Select all

	[event] #                                                       T H A W I N G     E V E N T
		name=new turn
        first_time_only=no
        [store_unit]
            [filter]
                side=2  # This will store all of the side 2 units in an array.
                status=petrified
            [/filter]
            variable=target_units  # "unit" as a variable name is reserved for the unit that triggers an event, so try not to use it for other things.  It could get confusing.
        [/store_unit]
        [foreach]
            array=target_units
            [do]
                [if]
    #				instead of using x,y coordinates   x=$this_item.x| and   y=$this_item.y|  ,you could use   id=this_item.id
    # 				it's very important that (inside of a [foreach] loop) you always make sure that your filters can only apply to exactly one unit at a time.
                    [variable]
                        name=this_item.id.how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
                        equals=2
                    [/variable]
                    [then]
                        [message]
                            speaker=MyLeader
                            message="The value is 2"
                        [/message]
                        [set_variable]
                            name=this_item.id.how_frozen
                            value=1 #                               unit was frozen, but is now thawing. Unit will unpetrify next turn.
                        [/set_variable]
                    [/then]

                    [elseif]
                        [variable]
                            name=this_item.id.how_frozen
                            equals=1
                        [/variable]
                        [then]
                            [message]
                                speaker=MyLeader
                                message="The value is 1"
                            [/message]
                            [set_variable]
                                name=this_item.id.how_frozen
                                value=0 #                           unit was thawing, but is now completely thawed. Unit is ready to be unpetrified
                            [/set_variable]
                        [/then]
                    [/elseif]
                [/if]
            [/do]
        [/foreach]
    [/event]

    [event] #                                                       U N P E T R I F Y     E V E N T
        name=new turn
        first_time_only=no
        [store_unit]
            [filter]
                side=2  # This will store all of the side 1 units in an array.
            [/filter]
            variable=target_units2  # "unit" as a variable name is reserved for the unit that triggers an event, so try not to use it for other things.  It could get confusing.
        [/store_unit]
        [foreach]
            array=target_units2
            [do]
                [if]
                    [variable]
                        name=this_item.id.how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
                        equals=0
                    [/variable]
                    [then]
                        [unpetrify] #                               any unit that is not frozen or thawing will be unpetrified
                            id=this_item.id
                        [/unpetrify]
                    [/then]
                [/if]
            [/do]
        [/foreach]
    [/event]

[event]
    name=attacker hits
    first_time_only=no
    [filter_attack]
        special=freezes
    [/filter_attack]

    [modify_unit]
        [filter]
            id=$second_unit.id  # 		an id stores a specific unit in an array.   
        [/filter]
        [set_variable]
            name=how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
            value=2
        [/set_variable]
    [/modify_unit]
    [message]
        speaker=MyLeader
        message="Modify unit just changed a variable to : " $second_unit.id.how_frozen
    [/message]
[/event]

Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
beetlenaut
Developer
Posts: 2812
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: array not arraying

Post by beetlenaut »

Helmet wrote: November 21st, 2022, 7:05 am The filters seem fine to me, except maybe the one in modify_unit, which has weird rules.
It has perfectly normal rules except that you don't use [filter] around it. Is that what you meant by "weird"? It looks correct now in any case. But, you still need to fix [unpetrify]. You don't have any unit with the id of literally "this_item.id"! You want to match what is stored in a variable called this_item.id. That requires a $. Read the $ as "contents of". That might help.
Helmet wrote: November 21st, 2022, 7:05 am Look at the very bottom of the code, at the message. When play-testing, it produces nothing after the text, not even a zero.
The expression $second_unit.id.how_frozen means the variable "how_frozen" inside the container "id", which is inside the container "second_unit". There is no container variable called "id" in a unit. Variables in a unit are in a container called "variables", so $second_init.variables.how_frozen should work. You have similar statements in several other places. (If a message statement isn't showing anything, you should use :inspect to make sure your variable showed up in the place you thought it did.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Straff
Posts: 83
Joined: September 27th, 2020, 2:53 pm

Re: array not arraying

Post by Straff »

I guess second_init.variables.how_frozen is a typo, you surely mean second_unit.variables.how_frozen
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: array not arraying

Post by Helmet »

beetlenaut wrote: November 21st, 2022, 7:41 am ...you still need to fix [unpetrify]. You don't have any unit with the id of literally "this_item.id"! You want to match what is stored in a variable called this_item.id. That requires a $. Read the $ as "contents of". That might help.
Thanks. I fixed it. The petrified unit never unpetrifies, though, so there's another problem somewhere.
beetlenaut wrote: November 21st, 2022, 7:41 am...Variables in a unit are in a container called "variables", so $second_init.variables.how_frozen should work.
I changed it to this: message="Modify unit just changed a variable to : " $second_unit.variables.how_frozen, but it still doesn't work. No value appears on the screen at the end of the text. I think this problem is a clue. The reason this doesn't work may be the same reason the unit doesn't thaw.
beetlenaut wrote: November 21st, 2022, 7:41 amYou have similar statements in several other places. (If a message statement isn't showing anything, you should use :inspect to make sure your variable showed up in the place you thought it did.)
I went through the code and changed id to variables and the code still doesn't work. So I changed it back.
What's wrong with the variables? I did what you said.

In the new turn event, text should appear on the screen saying, "The value is 2" or "The value is 1", but the text never appears.

I used :inspect like you said and checked the value of how_frozen and the value is 2. And yet, the unit never thaws and unpetrifies. Is there another mistake I'm not seeing?

This is the latest version with your fixes implemented.

Code: Select all

	[event] #                                                       T H A W I N G     E V E N T
		name=new turn
        first_time_only=no
        [store_unit]
            [filter]
                side=2  # This will store all of the side 2 units in an array.
                status=petrified
            [/filter]
            variable=target_units  # "unit" as a variable name is reserved for the unit that triggers an event, so try not to use it for other things.  It could get confusing.
        [/store_unit]
        [foreach]
            array=target_units
            [do]
                [if]
                    [variable]
                        name=this_item.id.how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
                        equals=2
                    [/variable]
                    [then]
                        [message]
                            speaker=MyLeader
                            message="The value is 2"
                        [/message]
                        [set_variable]
                            name=this_item.id.how_frozen
                            value=1 #                               unit was frozen, but is now thawing. Unit will unpetrify next turn.
                        [/set_variable]
                    [/then]

                    [elseif]
                        [variable]
                            name=this_item.id.how_frozen
                            equals=1
                        [/variable]
                        [then]
                            [message]
                                speaker=MyLeader
                                message="The value is 1"
                            [/message]
                            [set_variable]
                                name=this_item.id.how_frozen
                                value=0 #                           unit was thawing, but is now completely thawed. Unit is ready to be unpetrified
                            [/set_variable]
                        [/then]
                    [/elseif]
                [/if]
            [/do]
        [/foreach]
    [/event]

    [event] #                                                       U N P E T R I F Y     E V E N T
        name=new turn
        first_time_only=no
        [store_unit]
            [filter]
                side=2  # This will store all of the side 2 units in an array.
                status=petrified
            [/filter]
            variable=unfreeze_units  # "unit" as a variable name is reserved for the unit that triggers an event, so try not to use it for other things.  It could get confusing.
        [/store_unit]
        [foreach]
            array=unfreeze_units
            [do]
                [if]
                    [variable]
                        name=this_item.id.how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
                        equals=0
                    [/variable]
                    [then]
                        [unpetrify] #                               any unit that is not frozen or thawing will be unpetrified
                            id=$this_item.id
                        [/unpetrify]
                    [/then]
                [/if]
            [/do]
        [/foreach]
    [/event]

[event]
    name=attacker hits
    first_time_only=no
    [filter_attack]
        special=freezes
    [/filter_attack]

    [modify_unit]
        [filter]
            id=$second_unit.id  # 		an id stores a specific unit in an array.   
        [/filter]
        [set_variable]
            name=how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
            value=2
        [/set_variable]
    [/modify_unit]

    [message]
        speaker=MyLeader
        message="Modify unit just changed a variable to : " $second_unit.variables.how_frozen
    [/message]
[/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: array not arraying

Post by Helmet »

Update! In the attacker hits event, the value of how_frozen now appears on the screen following the text message.
The solution was using store_unit to update the old value of $second_unit, which was affected by modify_unit. Thank you, Celtic_Minstrel.

The poor frozen Giant Rat in my play-test scenario still refuses to thaw, though.

Code: Select all

[event]
    name=attacker hits
    first_time_only=no
    [filter_attack]
        special=freezes
    [/filter_attack]

    [modify_unit]
        [filter]
            id=$second_unit.id  # 		an id stores a specific unit in an array.   
        [/filter]
        [set_variable]
            name=how_frozen #              how frozen is the unit on a scale of 0-2       0=not frozen    1=thawing     2=frozen
            value=2
        [/set_variable]
    [/modify_unit]

    # $second_unit is just a copy of the unit, not the actual unit itself. However, when you use [modify_unit] you update the actual unit, 
    # not the copy, so the copy is now out-of-date. If you want to keep $second_unit accurate you'll need to re-store the unit after modifying it:
    [store_unit]
        [filter]
            id=$second_unit.id
        [/filter]
        variable=second_unit
        id=$second_unit.id
    [/store_unit]

    [message]
        speaker=MyLeader
        message="Modify unit just changed a variable to : " $second_unit.variables.how_frozen
    [/message]
[/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Ravana
Forum Moderator
Posts: 2933
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: array not arraying

Post by Ravana »

While it might work, I would change
message="Modify unit just changed a variable to : " $second_unit.variables.how_frozen
to
message="Modify unit just changed a variable to : $second_unit.variables.how_frozen "
or
message="Modify unit just changed a variable to : " + $second_unit.variables.how_frozen
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: array not arraying

Post by Helmet »

Ravana wrote: November 21st, 2022, 4:02 pm While it might work, I would change...
Thanks, Ravana. I like your second solution the best, because the + made it easy to add a period to the sentence after the number.

message="Modify unit just changed a variable to: " + $second_unit.variables.how_frozen + "."
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Ravana
Forum Moderator
Posts: 2933
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: array not arraying

Post by Ravana »

You already received answer that this_item.id.anything is useless. In your use case this_item is unit, therefore its id is string, and string does not have child attributes.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: array not arraying

Post by Helmet »

Ravana wrote: November 21st, 2022, 4:48 pm You already received answer that this_item.id.anything is useless. In your use case this_item is unit, therefore its id is string, and string does not have child attributes.
With all due respect, I tried what beetlenaut said and it didn't work, and it didn't work when you repeated it.

Would you post the variable for me to copy/paste and tell me where to paste it, because I'm clearly not understanding you.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Post Reply