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

Re: array not arraying

Post by Helmet »

For anyone visiting this thread looking for insight into arrays, here is the functional code to study. Gratitude is extended toward beetlenaut, Ravana and Celtic_Minstrel for their help.

Code: Select all

[event] #                                   T H A W I N G     E V E N T
	name=side 2 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  
        [/store_unit]
        [foreach]
            array=target_units
            [do]
                # [inspect][/inspect]
                [if]
                    [variable]
                        name=this_item.variables.how_frozen #  how frozen is the unit on a scale of 0-2   0=not frozen , 1=thawing, 2=frozen
                        greater_than=0
                    [/variable]
                    [then]
                        [modify_unit]
                            [filter]
                                id=$this_item.id
                            [/filter]
                            [set_variable]
                                name=how_frozen
                                sub=1
                            [/set_variable]
                        [/modify_unit]
                    [/then]
                    [else]
                        [unpetrify]
                            id=$this_item.id
                        [/unpetrify]
                    [/else]
                [/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]
    [store_unit]
        [filter]
            id=$second_unit.id
        [/filter]
        variable=second_unit
        id=$second_unit.id
    [/store_unit]
[/event]
This is what the code does:

The "frozen" unit is actually a petrified unit. After being petrified, the unit "thaws" for 2 turns and unpetrifies during the turn of side 2, allowing it to move and attack.

For example: if a side 2 Giant Rat was frozen on turn 1 by a side 1 unit attacking during its turn, the unit will remain petrified until turn 3, the side 2 turn. Said another way: It loses its attack during turn 1, loses its attack during turn 2, but it may attack during turn 3, after side 1 has already had their turn.

Note: if a unit has been petrified in some other way (for example, by a Medusa), the code does not differentiate between types of petrification. All petrified units on the map will "thaw" and lose their petrified status.
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
Toranks
Translator
Posts: 168
Joined: October 21st, 2022, 8:59 pm
Location: Sevilla
Contact:

Re: array not arraying [SOLVED]

Post by Toranks »

Change the else to a elseif as this to prevent a unit with another type of petrification being unpetrified. This must works, test and say to me.

Code: Select all

                                sub=1
                            [/set_variable]
                        [/modify_unit]
                    [/then]
                    [elseif]
                    [variable]
                        name=this_item.variables.how_frozen
                        equals=0
                    [/variable]
                    [then]
                        [unpetrify]
                            id=$this_item.id
                        [/unpetrify]
		    [/then]
                  [/elseif]
                [/if]
            [/do]
        [/foreach]
    [/event]                    
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: array not arraying [SOLVED]

Post by Helmet »

Toranks wrote: November 28th, 2022, 3:49 am Change the else to a elseif as this to prevent a unit with another type of petrification being unpetrified. This must works, test and say to me.
Tested. It worked. Thanks.

But the truly petrified unit continued to take damage every turn, as if it were frozen. However, since it was not actually frozen, it never "thawed."

I don't plan on making truly petrified units.

When I make a frozen unit in the start event, I use [variables] to make sure it will thaw:

Code: Select all

[unit]
# ... type, id, etc.
            [status]
                petrified=yes
            [/status]
            [variables]
                how_frozen=2 # unit can be frozen for any number of turns
            [/variables]
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