Add custom variable to unit
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.
Add custom variable to unit
I want that each recruited unit has it's own copy of a custom variable. I have added a variable to [unit_type], everything was OK until i've tryed to modify it and invoke [unstore_unit].
Is it possible to make such a thing?
Code: Select all
[unit_type]
...
[myera]
myvar=no
[/myera]
...
[/unit_type]
Code: Select all
[era]
...
[event]
name=defender_hits, defender_misses
first_time_only=no
[filter]
[filter_wml]
[myera]
myvar=no # i'm able to filter against it
[/myera]
[/filter_wml]
[/filter]
{DEBUG_MSG $second_unit.myera.myvar} # prints "no", i'm able to read it
{VARIABLE_OP second_unit.myera.myvar value yes}
{DEBUG_MSG $second_unit.myera.myvar} # prints "yes", i'm able to change it
[unstore_unit]
variable=second_unit
[/unstore_unit]
[store_unit]
[filter]
x=$x2
y=$y2
[/filter]
variable=sec
[/store_unit]
{DEBUG_MSG $sec.myera.myvar} # prints "no", i'm not able to keep it (
[/event]
...
[/era]
Re: Add custom variable to unit
Try to put the variable as unit.variables.myvar (or unit.variables.myera.myvar, whichever) instead of unit.myera.myvar. Although defining a [variables] in your [unit_type] might not work, so you might need to instead use some recruit events and such to give those variables to units.
- Ken_Oh
- Moderator Emeritus
- Posts: 2178
- Joined: February 6th, 2006, 4:03 am
- Location: Baltimore, Maryland, USA
Re: Add custom variable to unit
I can confirm defining [variables] in your [unit_type] will not work, as I tried this week.
I'm interested to see what happens in this thread, because I can't see anything wrong with the above code.
I'm interested to see what happens in this thread, because I can't see anything wrong with the above code.
Re: Add custom variable to unit
Thanks for your answers.
Works fine with [set_variable] in recruit event, no matter under [variables] or not.
Still works after savegame/loadgame.
If saved after all the recruiting, result WML in savegame file near identical to that without recruit event (WML in [unit_type]). But loading from one savegame works, and another does not.
Looks like kind of magic )
Works fine with [set_variable] in recruit event, no matter under [variables] or not.
Still works after savegame/loadgame.
If saved after all the recruiting, result WML in savegame file near identical to that without recruit event (WML in [unit_type]). But loading from one savegame works, and another does not.
Looks like kind of magic )
Re: Add custom variable to unit
However, when the variables are not inside [variables], they might get destroyed when the unit levels up, so it's still a good idea to use [variables].pancho wrote:Works fine with [set_variable] in recruit event, no matter under [variables] or not.
Re: Add custom variable to unit
Sorry, it works properly only in the [variables] scope.
Re: Add custom variable to unit
They don't. I tested all this in WesPets.zookeeper wrote:However, when the variables are not inside [variables], they might get destroyed when the unit levels up, so it's still a good idea to use [variables].pancho wrote:Works fine with [set_variable] in recruit event, no matter under [variables] or not.
Spoiler:
-
- Posts: 462
- Joined: June 8th, 2006, 3:25 am
Re: Add custom variable to unit
Those (IIRC) were AMLAs, though. Actually changing unit type is different from getting an AMLA (I ran into some of those differences working on levelup code for NPCs in Wesband). If the unit changes to a new type it's more destructive than if they just AMLA.
Re: Add custom variable to unit
So then I guess you'd need a pre leveup even and a post one to transfer the variable.
But before we get ahead of ourselves has anyone tested this specific scenario?
But before we get ahead of ourselves has anyone tested this specific scenario?
Re: Add custom variable to unit
Modern Combat uses unit.range to define artillery range. It survives leveling.Gambit wrote:So then I guess you'd need a pre leveup even and a post one to transfer the variable.
But before we get ahead of ourselves has anyone tested this specific scenario?
Moving it to unit.variables.range is no big deal. But there's no reason to do so. At least not yet.
"m" is the key used most in Wesnoth.
Re: Add custom variable to unit
If you want to modify your variable and then store it with [store_unit], you should declare it explicitly with [set_variable] in event of some kind and keep it in the [variables] scope. Otherwise you will lose write access to it after savegame/loadgame.