ForestDragon's WML questions
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.
Re: ForestDragon's WML questions
Please think of the problem yourself first. There's 15 minutes between our posts, which means you can't have spent any meaningful time trying to understand it yourself.ForestDragon wrote:well, sorry for not understanding, but what exactly should i fix?zookeeper wrote:Oh, yeah, this is definitely a case where you're trying to treat a container as a variable:
Code: Select all
[set_variable] name=exp_stored_[$side_number] add="$exp_drained_unit[$i].experience" [/set_variable]
Look at the variables in the inspect dialog. Then look at what the above code does. Then look at what any normal code incrementing a variable does, and how its results are reflected in the inspect dialog. It's really simple, there's no black magic, you can just check exactly what happens on each variable manipulation. And then you can see why the above code doesn't make sense.
- ForestDragon
- Posts: 1771
- Joined: March 6th, 2014, 1:32 pm
- Location: Ukraine
Re: ForestDragon's WML questions
well, it works for me (not counting it not working with the updated filter). Btw, don't expect much patience and attention from a teenager like me.
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
- ForestDragon
- Posts: 1771
- Joined: March 6th, 2014, 1:32 pm
- Location: Ukraine
Re: ForestDragon's WML questions
hi, i am having trouble making this bit work. (what i want to do is make all units under a certain criteria use their animation. so far without the bit i posted it only animates one unit. the issue is: i don't know how to make it, so that the [store_unit]/{FOREACH} thing works (i may have said that a bit incorrectly though)):
Code: Select all
[store_unit]
[filter]
type=EoMa_Chosen_of_Marsh
side=$side_number
[/filter]
variable=units
kill=no
[/store_unit]
{FOREACH units i}
[animate_unit]
flag=poisonaura
[filter]
id=units[$i].id
side=$side_number
ability=eoma_poisonousaura
[/filter]
[/animate_unit]
{NEXT i}
{CLEAR_VARIABLE units}
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Re: ForestDragon's WML questions
Evaluate the variable containing unit id.
Re: ForestDragon's WML questions
Indeed, I doubt you have units whose id's are "units[0].id", "units[1].id" and so on.
Re: ForestDragon's WML questions
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?"ForestDragon wrote:well, it works for me (not counting it not working with the updated filter). Btw, don't expect much patience and attention from a teenager like me.
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.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
- Pentarctagon
- Project Manager
- Posts: 5564
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: ForestDragon's WML questions
If it can cause unexpected errors and shouldn't ever be done, maybe Wesnoth should log an error and not actually do it?
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
Re: ForestDragon's WML questions
It may have changed since I worked on it (so much of that code has been changed now I hardly recognize it). I just tested it in 1.12.6 and got this: "warning engine: variable_info: using explicitly indexed container as wrong WML type, foo[1]"Pentarctagon wrote:If it can cause unexpected errors and shouldn't ever be done, maybe Wesnoth should log an error and not actually do it?
As for your second point, WML has some training wheels and doesn't run in a strict mode. You could make an argument that it would be better to fail fast and force the author to always write things correctly. And a lot of people would agree with you, especially experienced coders who know that it's best to catch potential errors early. Glossing over incorrect syntax can definitely make errors harder to find later. But despite all of that, and knowing all of that, I would disagree. The main goal for WML should be that little kids can get their big ideas up and working. If they want to ignore that warning message because it seems to be working, then who are we to stop them? That's my opinion anyways.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
- Pentarctagon
- Project Manager
- Posts: 5564
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: ForestDragon's WML questions
I suppose I can see that. Though I would say that it's more important to not allow this sort of behavior, since if it does cause problems, it will be that much harder to figure out because it seems to be working everywhere else. It's sort of similar to this situation that I ran into a little bit ago.
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
- ForestDragon
- Posts: 1771
- Joined: March 6th, 2014, 1:32 pm
- Location: Ukraine
Re: ForestDragon's WML questions
well, the issue has been dealt with now, but thanks.
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Re: ForestDragon's WML questions
Pentarctagon wrote:It's sort of similar to this situation that I ran into a little bit ago.
The reason we have that situation is because some developers thought it would be good to shoehorn WML booleans into unadorned C++ and/or Lua booleans. So you might say it was a violation of the WML philosophy, not a result of it. To me it certainly feels like a bug that you can store one string and then it transforms into another one under the hood, but I'm not very involved with development anymore so it's not for me to decide.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
- ForestDragon
- Posts: 1771
- Joined: March 6th, 2014, 1:32 pm
- Location: Ukraine
Re: ForestDragon's WML questions
I am back with another (obviously) not properly working mp mod. here are the current known issues so far:
-activating the 'imprison' menu somehow revives a unit what was previously imprisoned, but then killed
-my attempt of filtering by the amount of adjacent units doesn't work
-'free unit' menu doesn't work, it worked without the attempt to give the unit old movement/zoc, but now it doesn't (it only activates the [store_unit]/[unstore_uni]t)
-activating the 'imprison' menu somehow revives a unit what was previously imprisoned, but then killed
-my attempt of filtering by the amount of adjacent units doesn't work
-'free unit' menu doesn't work, it worked without the attempt to give the unit old movement/zoc, but now it doesn't (it only activates the [store_unit]/[unstore_uni]t)
Code: Select all
[modification]
id=Imprisonment_Mod
name="Imprisonment/Capture Mod"
description="allows players to imprison/capture enemy units if there are at least 2 units next to the enemy (the amount is customizable)
there are multiple ways to imprison units (all but spirit bind also remove the unit's ZoC, and make villages not claimable by the unit):
cage: doesn't allow movement/attacking, but allows retaliation. costs <4 multiplied by unit level> gold
shackles: disallows attacking and allows the unit to be dragged, but allows retaliation/movement. costs <2 multiplied by unit level> gold
spirit bind (compatible with shackles): unit can move/attack/etc. freely, but is unable to move farther than a certain range from a unit it's bound to.
made by ForestDragon."
require_modification=no
[event]
# is used to show icon in status bar
name=preload
first_time_only=no
id=show_imprisoned
[lua]
code=<<
local _ = wesnoth.textdomain "wesnoth-imprisoned"
local old_unit_status = wesnoth.theme_items.unit_status
function wesnoth.theme_items.unit_status()
local u = wesnoth.get_displayed_unit()
if not u then return {} end
local s = old_unit_status()
if u.status.imprisoned then
table.insert(s, { "element", {
image = "items/cage.png~SCALE(20,20)",
tooltip = _"imprisoned: This unit is imprisoned. It cannot move, or attack, but can still retaliate"
} })
end
return s
end
>>
[/lua]
[/event]
[event]
name=prestart
[set_menu_item]
id=imprison
description="Imprison unit"
# image=".png"
# [default_hotkey]
# key="~"
# [/default_hotkey]
[show_if]
[have_unit]
# [filter_adjacent]
# side=$side_number
# amount=2-6
# [/filter_adjacent]
[filter_wml]
[not]
[status]
imprisoned=yes
[/status]
[/not]
[/filter_wml]
[filter_side]
[enemy_of]
side=$side_number
[/enemy_of]
[/filter_side]
x=$x1
y=$y1
[/have_unit]
[have_unit]
[filter_location]
x=$x1
y=$y1
radius=1
[/filter_location]
side=$side_number
amount=2-6
[/have_unit]
[/show_if]
[command]
[message]
speaker=narrator
image=portraits/tomb-guardian.png
caption="Imprisonment"
message="How do you want to imprison this enemy?"
[option]
message= {MENU_IMG_TXT "misc/red-x.png" "Return To Game"}
[command]
# {EXP_UNSTORE}
[/command]
[/option]
[option]
message= {MENU_IMG_TXT "items/cage.png" "Cage"}
[command]
[unit_overlay]
x,y=$x1,$y1
image=items/cage.png
[/unit_overlay]
[store_unit]
[filter]
x=$x1
y=$y1
[/filter]
kill=no
variable=unit
[/store_unit]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[status]
imprisoned=yes
[/status]
[/modify_unit]
[set_variable]
name=[$unit.id]_max_moves
value=$unit.max_moves
[/set_variable]
[set_variable]
name=[$unit.id]_zoc
value=$unit.zoc
[/set_variable]
[object]
silent=yes
# duration=turn
[filter]
find_in=unit
[/filter]
[effect]
apply_to=attack
attack_weight=0.0
[/effect]
[effect]
apply_to=movement
set=0
[/effect]
[effect]
apply_to=zoc
value=no
[/effect]
[/object]
[unstore_unit]
variable=impunit
text="captured"
{COLOR_HARM}
find_vacant=no
[/unstore_unit]
[/command]
[/option]
[/message]
[/command]
[/set_menu_item]
[set_menu_item]
id=free
description="free unit"
# image=".png"
# [default_hotkey]
# key="~"
# [/default_hotkey]
[show_if]
[have_unit]
[filter_adjacent]
side=$side_number
[/filter_adjacent]
[filter_wml]
[status]
imprisoned=yes
[/status]
[/filter_wml]
x=$x1
y=$y1
[/have_unit]
[/show_if]
[command]
[store_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=impunit
kill=no
[/store_unit]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[status]
imprisoned=no
[/status]
[/modify_unit]
[object]
silent=yes
sort=potion-like
[filter]
find_in=unit
[/filter]
[effect]
apply_to=attack
attack_weight=1
[/effect]
[effect]
apply_to=movement
set=$[$impunit.id]_max_moves|
[/effect]
[effect]
apply_to=zoc
value=$[$impunit.id]_zoc|
[/effect]
[/object]
[remove_unit_overlay]
x,y=$x1,$y1
image=items/cage.png
[/remove_unit_overlay]
[unstore_unit]
variable=unit
text="free"
{COLOR_HEAL}
find_vacant=no
[/unstore_unit]
{CLEAR_VARIABLE [$unit.id]_max_moves}
[/command]
[/set_menu_item]
[/event]
[/modification]
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Re: ForestDragon's WML questions
No, just no. Really, no.ForestDragon wrote: name=[$unit.id]_max_moves
name=[$unit.id]_zoc
set=$[$impunit.id]_max_moves|
value=$[$impunit.id]_zoc|
{CLEAR_VARIABLE [$unit.id]_max_moves}
- ForestDragon
- Posts: 1771
- Joined: March 6th, 2014, 1:32 pm
- Location: Ukraine
Re: ForestDragon's WML questions
any alternative ideas?zookeeper wrote:No, just no. Really, no.ForestDragon wrote: name=[$unit.id]_max_moves
name=[$unit.id]_zoc
set=$[$impunit.id]_max_moves|
value=$[$impunit.id]_zoc|
{CLEAR_VARIABLE [$unit.id]_max_moves}
My active add-ons: The Great Steppe Era,XP Bank,Alliances Mod,Pestilence,GSE+EoMa,Ogre Crusaders,Battle Royale,EoMaifier,Steppeifier,Hardcoreifier
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
My inactive add-ons (1.12): Tale of Alan, The Golden Age
Co-creator of Era of Magic
Re: ForestDragon's WML questions
Do not modify unit before unstoring it.