variable expansion
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.
-
- Posts: 1280
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
variable expansion
Consider the following, taken out of context:
As you can see, the whole modify_unit block is pretty redundant, which bothers me (there are a more [case]s, just showing two as an example). I'd like to do something like this (code is wrong, hopefully my intent will be clear):
I've seen a [literal] used and literal= I think, which I always thought would be for cases like that, but when ever I look into it I'm not clear what it does but it doesn't seem quite right.
Code: Select all
[foreach]
array=guards
[do]
{VARIABLE_OP index rand (0..4)}
[switch]
variable=index
[case]
value=0
[modify_unit]
[filter]
id=$this_item.id
[/filter]
[object]
id=temp_obj
[effect]
apply_to=attack
range=melee
[set_specials]
mode=append
{WEAPON_SPECIAL_UNHOLYBANE}
{WEAPON_SPECIAL_MAGICAL}
[/set_specials]
[/effect]
[/object]
[/modify_unit]
[/case]
[case]
value=1
[modify_unit]
[filter]
id=$this_item.id
[/filter]
[object]
id=temp_obj
[effect]
apply_to=attack
range=melee
[set_specials]
mode=append
{WEAPON_SPECIAL_LESSER_BERSERK 5}
{WEAPON_SPECIAL_LEECH}
{WEAPON_SPECIAL_MAGICAL}
[/set_specials]
[/effect]
[/object]
[/modify_unit]
[/case]
[case]
value=2
...
Code: Select all
[foreach]
array=guards
[do]
{VARIABLE_OP index rand (0..4)}
[switch]
variable=index
[case]
value=0
[set_variable]
name=specials
value={WEAPON_SPECIAL_UNHOLYBANE} + {WEAPON_SPECIAL_MAGICAL}
[/set_variable]
[/case]
[case]
value=1
[set_variable]
name=specials
value= {WEAPON_SPECIAL_LESSER_BERSERK 5} + {WEAPON_SPECIAL_LEECH} + {WEAPON_SPECIAL_MAGICAL}
[/set_variable]
[/case]
[/switch]
[modify_unit]
[filter]
id=$this_item.id
[/filter]
[object]
id=temp_obj
[effect]
apply_to=attack
range=melee
[set_specials]
mode=append
$specials
[/set_specials]
[/effect]
[/object]
[/modify_unit]
Speak softly, and carry Doombringer.
- Spannerbag
- Posts: 553
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: variable expansion
As you're dealing with one unit, I think you can maybe dispense with
It would save a bit of space - but it's nothing like what you want to do so maybe something to consider if no-one else suggests anything better?
Cheers!
-- Spannerbag
[modify_unit]
and put the [filter]
in [object]
?It would save a bit of space - but it's nothing like what you want to do so maybe something to consider if no-one else suggests anything better?
[insert_tag]
might be able to do what you want but I've never used it so don't know for sure...Cheers!
-- Spannerbag
Re: variable expansion
It is possible to make it shorter but I think it is not worth the effort yet. Your first example looks similar to orocia upgrades before I rewrote them in Lua.
If you want to try then yes, [insert_tag] will solve your use case.
If you want to try then yes, [insert_tag] will solve your use case.
Re: variable expansion
Maybe I'm wrong, but as far I remember you can't use numbers as value in strings but strings only? It could be that this info is deprecated already, but in older versions I couldn't use numeric values for whatever reason.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
- Celtic_Minstrel
- Developer
- Posts: 2273
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: variable expansion
You can't use
[set_variable]
for container variables. It just won't work. There's no way to make your false example work in a similar way. You could maybe work something out with [set_variables]
(note the extra S), but I have a feeling it wouldn't be that much less verbose than your first example. You could also maybe work something out with [insert_tag]
that'll make your code verbose; I'm not entirely sure what that would end up looking like.