reference of last unit created

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
vghetto
Posts: 166
Joined: November 2nd, 2019, 5:12 pm

reference of last unit created

Post by vghetto »

Hi,

I'm wondering how can I get the reference .id of the last unit created with [unit]?
I want that unit to say something without giving it an explicit ID or role, because there could be more of them later on.
The location of the created unit is not always guaranteed, so can't use $x1,$y1 for that.
The way I'm currently doing it is by creating it into a variable with to_variable= then unstoring with [unstore_unit] and grabbing the .id from the variable.

Is there a shortcut for doing that?

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

Re: reference of last unit created

Post by Ravana »

I would proxy wesnoth.wml_actions.unit to save flag of unit creation, and in unit placed event collect the id if flag is set. That is if the [unit] calls are not from your own code.

Post Reply