ForestDragon's WML questions

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
ForestDragon
Forum Regular
Posts: 1488
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » November 25th, 2017, 6:44 pm

(sorry for double-posting) unfortunately, I couldn't find anything relevant in the thread.

EDIT: btw, how can I make units exist when a mod is turned on, but not when it's turned off (I mean with #ifdef and stuff)
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned),The Golden Age (1.12/1.13, abandoned),XP Bank (1.14),Alliances Mod(1.14), with a large add-on in development
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1832
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana » November 25th, 2017, 6:57 pm

#ifdef is only used at loading time. Turning mod on/off happens after that, so can not be used.

User avatar
ForestDragon
Forum Regular
Posts: 1488
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » November 25th, 2017, 6:59 pm

Ravana wrote:#ifdef is only used at loading time. Turning mod on/off happens after that, so can not be used.
I see. so, what about the previous issue? (XP Bank variables in 1.13)
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned),The Golden Age (1.12/1.13, abandoned),XP Bank (1.14),Alliances Mod(1.14), with a large add-on in development
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1832
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana » November 25th, 2017, 7:04 pm

1.13 requires variables have name.

User avatar
ForestDragon
Forum Regular
Posts: 1488
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » November 25th, 2017, 7:05 pm

Ravana wrote:1.13 requires variables have name.
could you explain a bit more in-detail?
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned),The Golden Age (1.12/1.13, abandoned),XP Bank (1.14),Alliances Mod(1.14), with a large add-on in development
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1832
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana » November 25th, 2017, 7:11 pm

It was explained here few pages ago.

User avatar
ForestDragon
Forum Regular
Posts: 1488
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » November 25th, 2017, 7:16 pm

Ravana wrote:It was explained here few pages ago.
could you please quote the post? (sorry for being a lazy piece of [censored])
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned),The Golden Age (1.12/1.13, abandoned),XP Bank (1.14),Alliances Mod(1.14), with a large add-on in development
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Ravana
Moderator
Posts: 1832
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana » November 25th, 2017, 7:26 pm

I will give you more time to look then.

User avatar
ForestDragon
Forum Regular
Posts: 1488
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » November 25th, 2017, 7:30 pm

Ravana wrote:I will give you more time to look then.
do you mean the following post, or an older/newer one?:
Think of it this way. Imagine a customer walks into a store and asks, "how much does this shelf cost?" Then the owner says, "that shelf's just a part of the store sir. Maybe you mean to ask me the price of one of these items on the shelf?"

So when you attempting to store a numeric value to a WML container, e.g. "foo[1]", that makes about as much sense as asking the price of the shelf, which is not for sale. Instead you should store a numeric value to "foo[1].value" or something similar.

The reason this may appear to work sometimes is because (depending on version of wesnoth) it will create a special temporary variable (such as "foo[1].__value"), just so there is somewhere to store your number. However it can still lead to errors, so you should never do it.
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned),The Golden Age (1.12/1.13, abandoned),XP Bank (1.14),Alliances Mod(1.14), with a large add-on in development
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Pentarctagon
Forum Administrator
Posts: 3517
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: ForestDragon's WML questions

Post by Pentarctagon » November 25th, 2017, 7:51 pm

Container variables need to have an attribute. So var[0] is not correct, while var[0].value would be(I would assume this would be written to your error log).

Also, didn't you already ask this same question before?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

User avatar
Ravana
Moderator
Posts: 1832
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: ForestDragon's WML questions

Post by Ravana » November 25th, 2017, 7:52 pm

Yes, that one explains it.

User avatar
ForestDragon
Forum Regular
Posts: 1488
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » November 26th, 2017, 7:16 am

Pentarctagon wrote:Container variables need to have an attribute. So var[0] is not correct, while var[0].value would be(I would assume this would be written to your error log).
so, do you mean I should replace $exp_stored_[$side_number]| with $exp_stored_[$side_number].value| or add the ".value" part to $XP_Bank_start?
well, I did, but I forgot about it.
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned),The Golden Age (1.12/1.13, abandoned),XP Bank (1.14),Alliances Mod(1.14), with a large add-on in development
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Pentarctagon
Forum Administrator
Posts: 3517
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: ForestDragon's WML questions

Post by Pentarctagon » November 26th, 2017, 7:48 am

ForestDragon wrote:
Pentarctagon wrote:Container variables need to have an attribute. So var[0] is not correct, while var[0].value would be(I would assume this would be written to your error log).
so, do you mean I should replace $exp_stored_[$side_number]| with $exp_stored_[$side_number].value| or add the ".value" part to $XP_Bank_start?
Everywhere you currently use exp_stored_[$side_number]|, you should instead use exp_stored_[$side_number].value|. That also includes all instances where you use some other value other than $side_number.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

User avatar
ForestDragon
Forum Regular
Posts: 1488
Joined: March 6th, 2014, 1:32 pm

Re: ForestDragon's WML questions

Post by ForestDragon » November 26th, 2017, 7:56 am

Pentarctagon wrote:Everywhere you currently use exp_stored_[$side_number]|, you should instead use exp_stored_[$side_number].value|. That also includes all instances where you use some other value other than $side_number.
done. still doesn't work, though. here's the code again:

Code: Select all

[modification]
    id=XP_Bank_Mod
    name="XP Bank Mod"
    description="allows players to deposit xp from units, storing it into thier XP bank, and give it to other units, it is useful for quickly leveling up units, take back the experience wasted by high-level units, and when an experienced unit is about to die.

made by ForestDragon."
    require_modification=no
    type=hybrid
    [options]
#        [checkbox]
#            id=XP_bank_loot_enabled
#            default=no
#            name="XP bank looting enabled"
#            description="When killing an enemy , the killer's side get a percentage of the defeated unit's exp as stored exp for themselves."
#        [/checkbox]
#        [checkbox]
#            id=XP_bank_loot_enabled
#            default=no
#            name="XP bank prevent almost defeated side to defy"
#            description="players cannot deposit/withdraw exp while there is an enemy unit next to their leader, mostly to prevent players that are about to lose from being able to give it all to their units, thus having the victorious side gain nothing"
#        [/checkbox]
#        [slider]
#            id=XP_bank_loot
#            default=50
#            min=0
#            max=100
#            step=25
#            name="XP bank looting"
#            description="The percentage of XP stolen."
#        [/slider]
        [checkbox]
            id=XP_bank_advance_filter
            default=no
            name="XP bank: is advancement filter enabled by default?"
            description="whether the option of choosing between advancing a unit and storing all of his experience is turned on by default."
        [/checkbox]
        [slider]
            id=XP_bank_start
            default=0
            min=0
            max=100
            step=10
            name="XP bank head-start"
            description="you get some exp in your bank at the beginning."
        [/slider]
    [/options]
[event]
#  id=bankstart
  name=start
	[if]
	    [variable]
                name=exp_assigned
                not_equals=yes
            [/variable]
            [then]
        {VARIABLE exp_stored_[1].value $XP_bank_start.value}
        {VARIABLE exp_stored_[2].value $XP_bank_start.value}
        {VARIABLE exp_stored_[3].value $XP_bank_start.value}
        {VARIABLE exp_stored_[4].value $XP_bank_start.value}
        {VARIABLE exp_stored_[5].value $XP_bank_start.value}
        {VARIABLE exp_stored_[6].value $XP_bank_start.value}
        {VARIABLE exp_stored_[7].value $XP_bank_start.value}
        {VARIABLE exp_stored_[8].value $XP_bank_start.value}
        {VARIABLE exp_stored_[9].value $XP_bank_start.value}
	
        {VARIABLE advance_filter_[1] $XP_bank_advance_filter}
        {VARIABLE advance_filter_[2] $XP_bank_advance_filter}
        {VARIABLE advance_filter_[3] $XP_bank_advance_filter}
        {VARIABLE advance_filter_[4] $XP_bank_advance_filter}
        {VARIABLE advance_filter_[5] $XP_bank_advance_filter}
        {VARIABLE advance_filter_[6] $XP_bank_advance_filter}
        {VARIABLE advance_filter_[7] $XP_bank_advance_filter}
        {VARIABLE advance_filter_[8] $XP_bank_advance_filter}
        {VARIABLE advance_filter_[9] $XP_bank_advance_filter}
[set_variable]
 name=exp_assigned
 value=yes
[/set_variable]
            [/then]
            [else]
            [/else]
         [/if]
#        [if]
#            [variable]
#                name=XP_bank_loot_enabled
#                equals=yes
#            [/variable]
#            [then]
#                                    [set_variable]
#                                        name=lootable
#                                        add=1
#                                    [/set_variable]
#
#            [/then]
#        [/if]  
  [set_menu_item]
    id=xpbank
    description="XP bank"
#    image=".png"
#    [default_hotkey]
#      key="~"
#    [/default_hotkey]
	[show_if]
		[have_unit]
                        x=$x1
                        y=$y1
			side=$side_number
		[/have_unit]
           [and]
             [not]
            [have_unit]	
                [filter_side]
                    [enemy_of]
                        side=$side_number
                    [/enemy_of]
                [/filter_side]
                [filter_location]
                x="$x1"
                y="$y1"
                radius=1
                [/filter_location]
                count=2-6
            [/have_unit]
             [/not]
           [/and]
        [/show_if]		    
    [command]
		[store_unit]
			[filter]
                            x,y=$x1,$y1
			[/filter]
			variable=exp_unit
		[/store_unit]
#    {EXP_STORE}
#[set_variable]
#  name=exp_stored_[$side_number]
# value=$exp_stored_$side_number
# value=exp_stored_$side_number
#[/set_variable]
	[message]
		speaker=narrator
		image=portraits/tomb-guardian.png
		caption="XP bank"
                message="you have currently $exp_stored_[$side_number].value| exp stored in the bank."
                [option]
                        
			message=  {MENU_IMG_TXT "misc/red-x.png" "Return To Game"}
			[command]
#    {EXP_UNSTORE}
                         [/command]
		[/option]
                [option]
                        
			message=  {MENU_IMG_TXT "items/holy-water.png~BLIT(halo/elven/shaman-heal-halo-4.png)" "Deposit from this unit"}
			[command]
          [message]
            speaker=narrator
            image=portraits/tomb-guardian.png
            caption="XP bank"
#            image="items/holy-water.png~BLIT(halo/elven/shaman-heal-halo-4.png)"
            message="Type in the amount of exp to deposit, type 0 if you dont want to deposit any exp from this unit. there is currently $exp_stored_[$side_number].value| exp in the bank. this unit currently has $exp_unit.experience| experience. (note: if you type in more xp than the unit has, nothing will happen)"
            
            [text_input]
              variable=exp_deposit
            [/text_input]
          [/message]                         
	[if]
	    [variable]
                name=exp_deposit
                greater_than=0
            [/variable]
            [and]
	    [variable]
                name=exp_deposit
                less_than_equal_to=$exp_unit.experience
            [/variable]
            [/and]
            [then]
                     [sound]
			name=magic-faeriefire-miss.ogg
		       [/sound]
[set_variable]
 name=exp_stored_[$side_number]
 add=$exp_deposit
[/set_variable]
                [modify_unit]
                      [filter]
			x,y=$x1,$y1
                      [/filter]
                      experience="$($exp_unit.experience - $exp_deposit)"
                [/modify_unit]
#    {EXP_UNSTORE}
            [/then]
	[else]
#	    [variable]
#                name=exp_deposit
#                greater_than=$exp_unit.experience
#            [/variable]
#            [then]
#	[message]            
#            speaker=narrator
#            image=portraits/tomb-guardian.png
#            caption="XP bank"
#            message="sorry, but this unit doesn't have this much exp."
#	[/message]            
#    {EXP_UNSTORE}
#            [/then]
	[/else]                                            
#	[else]
#	[/else]                                            
	[/if]                                            
                         [/command]
		[/option]
                  [option]
               message=  {MENU_IMG_TXT "items/holy-water.png~BLIT(halo/elven/shaman-heal-halo-4.png)" "Deposit All"}
               [command]
                     [sound]
			name=magic-faeriefire-miss.ogg
		       [/sound]
                       [delay]
                         time=75
                       [/delay]
                     [sound]
			name=magic-faeriefire-miss.ogg
		       [/sound]
                       [delay]
                         time=75
                       [/delay]
                     [sound]
			name=magic-faeriefire-miss.ogg
		       [/sound]
                       [delay]
                         time=75
                       [/delay]
                     [sound]
			name=magic-faeriefire-miss.ogg
		       [/sound]
                       [delay]
                         time=75
                       [/delay]
                     [sound]
			name=magic-faeriefire-miss.ogg
		       [/sound]
                       [delay]
                         time=75
                       [/delay]
                  [store_unit]
                     [filter]
                        side=$side_number
             [not]
             [filter_adjacent]	
                [filter_side]
                    [enemy_of]
                        side=$side_number
                    [/enemy_of]
                [/filter_side]
                count=2-6
             [/filter_adjacent]
             [/not]
                     [/filter]
                     variable=exp_drained_unit
                  [/store_unit]
                  {FOREACH exp_drained_unit i}
                  [set_variable]
                      name=exp_stored_[$side_number]
                      add="$exp_drained_unit[$i].experience"
                  [/set_variable]
                  {VARIABLE exp_drained_unit[$i].experience 0}
                  [unstore_unit]
                     variable=exp_drained_unit[$i]
                     find_vacant=no
                  [/unstore_unit]
                  {NEXT i}
                  {CLEAR_VARIABLE exp_drained_unit}
               [/command]
            [/option]
	                [option]                        
			message=  {MENU_IMG_TXT "items/holy-water.png~BLIT(halo/elven/shaman-heal-halo-4.png)" "Withdraw"}
			[command]
          [message]
            speaker=narrator
            image=portraits/tomb-guardian.png
            caption="XP bank"
#            image="items/holy-water.png~BLIT(halo/elven/shaman-heal-halo-4.png)"
            message="Type in the amount of exp to withdraw, type 0 if you dont want to withdraw exp to this unit. there is currently $exp_stored_[$side_number].value| exp in the bank (note: if you type in more xp than there is in the bank, nothing will happen)"
            
            [text_input]
              variable=exp_withdraw
            [/text_input]
            
          [/message]
          
	[if]
	    [variable]
                name=exp_withdraw
                greater_than=0
            [/variable]
            [and]
            [not]
	    [variable]
                name=exp_withdraw
                greater_than=$exp_stored_[$side_number].value
            [/variable]
            [/not]
            [/and]
            [then]
                     [sound]
			name=magic-holy-1.ogg
		       [/sound]
                [modify_unit]
                      [filter]
			x,y=$x1,$y1
                      [/filter]
                      experience="$($exp_unit.experience + $exp_withdraw)"
                [/modify_unit]
#    {EXP_UNSTORE}
[set_variable]
 name=exp_stored_[$side_number]
 sub=$exp_withdraw
[/set_variable]
            [/then]
	[else]
#	    [variable]
#                name=exp_withdraw
#                greater_than=$exp_stored_[$side_number].value
#            [/variable]
#            [then]
#	[message]            
#            speaker=narrator
#            image=portraits/tomb-guardian.png
#            caption="XP bank"
#            message="sorry, but you only have $exp_stored_[$side_number].value| exp in your bank."
#	[/message]            
#    {EXP_UNSTORE}
#            [/then]
	[/else]                                            
	[/if]                                            
#	[/message]            
                         [/command]
		[/option]
                [option]
                        
			message=  {MENU_IMG_TXT "items/holy-water.png~BLIT(halo/elven/shaman-heal-halo-4.png)" "(currently set to <span color='#cccc33'>$advance_filter_[$side_number]|</span> for your side) Toggle advancement filtering (whether you want to see the option to either level up a unit, or deposit it's exp before leveling up)"}
			[command]
	[if]
	    [variable]
                name=advance_filter_[$side_number]
                equals=yes
            [/variable]
            [then]
[set_variable]
 name=advance_filter_[$side_number]
 value=no
[/set_variable]
            [/then]
            [else]
[set_variable]
 name=advance_filter_[$side_number]
 value=yes
[/set_variable]
            [/else]
	[/if]
                         [/command]
		[/option]
	[/message]            
    [/command]    
  [/set_menu_item]  
[set_menu_item]
        description=_ "Send some xp to this side"
        id="send_xp"
#        image="misc/cross-white.png"
        [show_if]
            [have_unit]	
                [filter_side]
                    [allied_with]
                        side=$side_number
                    [/allied_with]
                [/filter_side]
                canrecruit="yes"
                x="$x1"
                y="$y1"
            [/have_unit]
            [and]
              [not]
                [have_unit]	
                   x="$x1"
                   y="$y1"
                   side=$side_number
                 [/have_unit]
              [/not]
            [/and]
        [/show_if]
		  [command]
[store_unit]
[filter]
   x=$x1
   y=$y1
[/filter]
variable=thisleader
kill=no
[/store_unit]
            [message]
                caption=_ "XP Bank"
                image=portraits/tomb-guardian.png
                speaker="narrator"
                message="Type in the amount of exp to send to side $this_leader.side|, type 0 if you dont want to send any exp to this side. there is currently $exp_stored_[$side_number].value| exp in your the bank, and there is currently $exp_stored_[$thisleader.side]| exp in your ally's bank. (note: if you type in more xp than there is in your bank, nothing will happen)"
            
            [text_input]
              variable=exp_send
            [/text_input]
            [/message]
	[if]
	    [variable]
                name=exp_send
                greater_than=0
            [/variable]
            [and]
	    [variable]
                name=exp_send
                less_than_equal_to=$exp_stored_[$side_number].value
            [/variable]
            [/and]
            [then]
                     [sound]
			name=magic-faeriefire-miss.ogg
		       [/sound]
[set_variable]
 name=exp_stored_[$side_number]
 sub=$exp_send
[/set_variable]
[set_variable]
 name=exp_stored_[$thisleader.side]
 add=$exp_send
[/set_variable]
#					[message]
#					speaker=narrator
#                                        side_for=!,$side_number|,$thisleader.side|
#					message=_" Player $side_number| has sent player $exp_stored[$thisleader.side]| $exp_send| xp."
#					[/message]
					[message]
     					speaker=narrator
                                        caption=_ "XP Bank"
                                        image=portraits/tomb-guardian.png
                                        side_for=$side_number
					message=_"You have sent player $exp_stored[$thisleader.side]| $exp_send| xp."
					[/message]
					[message]
					speaker=narrator
                                        caption=_ "XP Bank"
                                        image=portraits/tomb-guardian.png
                                        side_for=$thisleader.side
                                        message=_" Player $side_number| has sent you $exp_send| xp."
					[/message]
            [/then]
	[else]
	[/else]                                            
	[/if]                                            
     [/command]
[/set_menu_item]
[/event]
[event]
  name=advance
  first_time_only=no
  [filter]
   [filter_side]
       controller=human
   [/filter_side]
  [/filter]
        [if]
	    [variable]
                name=advance_filter_[$side_number]
                equals=yes
            [/variable]
            [then]
					[message]
     					speaker=narrator
                                        caption=_ "XP Bank"
                                        image=portraits/tomb-guardian.png
                                        side_for=$unit.side
					message=_"Do you want $unit.name| the $unit.type| to level up as usual, or deposit all his/her exp to prevent him/her from doing so to save the exp for something else?"
                [option]
                        
			message=  {MENU_IMG_TXT "misc/red-x.png" "Level up"}
			[command]
                         [/command]
		[/option]
                [option]
                        
			message=  {MENU_IMG_TXT "items/holy-water.png~BLIT(halo/elven/shaman-heal-halo-4.png)" "Deposit all of the unit's exp"}
			[command]
                     [sound]
			name=magic-faeriefire-miss.ogg
		      [/sound]
                  [store_unit]
                     [filter]
                         id=$unit.id
                     [/filter]
                     variable=exp_drained_unit
                  [/store_unit]
                  [set_variable]
                      name=exp_stored_[$side_number]
                      add="$exp_drained_unit.experience"
                  [/set_variable]
                  {VARIABLE exp_drained_unit.experience 0}
                  [unstore_unit]
                     variable=exp_drained_unit
                     find_vacant=no
                  [/unstore_unit]
                  {CLEAR_VARIABLE exp_drained_unit}
                         [/command]
		[/option]
					[/message]
            [/then]
	[/if]
[/event]
[/modification]
Co-creator of Era of Magic
Creator of Tale of Alan (1.12 abandoned),The Golden Age (1.12/1.13, abandoned),XP Bank (1.14),Alliances Mod(1.14), with a large add-on in development
"Real life is like a hyper-realistic VR game, but with permadeath and boring gameplay"

User avatar
Pentarctagon
Forum Administrator
Posts: 3517
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: ForestDragon's WML questions

Post by Pentarctagon » November 26th, 2017, 8:10 am

You didn't need to add .value it to XP_bank_start.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

Post Reply