Clone unit in WML
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: 1310
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Clone unit in WML
I have to be missing something here. Without using lua, how do I simply clone a unit? I want to make a copy of a leader, and then change a few things (like canrecruit).
I could make a new unit and copy all its attributes. I guess that's simple, but tedious.
I could store a unit and unstore it. I think if I unstore it on top of the original (probably with find_vacant=yes), I'll get a clone with a new id and x,y. This looks promising, but how then do I refer to it? It has a new id, x, y, but AFAIK unstore does not return anything like that to me. I guess I could manipulate the id while it's stored, but this is not truly deterministic and so I'd rather have wesnoth assign a new one that is guaranteed unique (at least I think it is), and it's venturing away from the simple option that I suspect exists but eludes me.
I could make a new unit and copy all its attributes. I guess that's simple, but tedious.
I could store a unit and unstore it. I think if I unstore it on top of the original (probably with find_vacant=yes), I'll get a clone with a new id and x,y. This looks promising, but how then do I refer to it? It has a new id, x, y, but AFAIK unstore does not return anything like that to me. I guess I could manipulate the id while it's stored, but this is not truly deterministic and so I'd rather have wesnoth assign a new one that is guaranteed unique (at least I think it is), and it's venturing away from the simple option that I suspect exists but eludes me.
Speak softly, and carry Doombringer.
Re: Clone unit in WML
Store, change id, unstore. If you do not trust yourself to avoid id conflicts then generate new [unit], save its id, kill it, and assign that id to copy.
-
- Posts: 1310
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Clone unit in WML
If I knew how to do that, couldn't I just unstore the original unit over itself (with find_vacant=yes) and let a new id be assigned?
Of course, I could just assign an id by randomly punching my keyboard a few times and almost certainly be good, this is basically an academic question.
Or I could create/id/kill a unit on an impassible tile so I knew the x,y, but that's a little ugly.
Speak softly, and carry Doombringer.
Re: Clone unit in WML
[unit]to_variable
It might happen that if you delete id completely then it is generated for copy too.
It might happen that if you delete id completely then it is generated for copy too.
- Celtic_Minstrel
- Developer
- Posts: 2290
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Clone unit in WML
If I understand correctly, you want to make a unit that's a copy of the leader unit while avoiding ID conflicts? In that case, all you need to do is store the unit, delete the ID from the stored unit, modify anything else you want, and then unstore the unit. A stored unit is already a copy of the unit, after all.
Re: Clone unit in WML
I'm doing so, when I spawn "shadows" uncle. You can use the code if you like.
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