dabber's questions: object on unit

The place to post your WML questions and answers.

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.
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: object on unit

Post by dabber »

Many leaders are created in the side definitions. How do I set a variable in the scenario file and then use that variable to modify the leader in the side definition? Even if I set the variable in a prestart event, I get errors trying to access it in the side definition.
Pilauli
Posts: 50
Joined: August 18th, 2020, 12:56 pm

Re: dabber's questions: object on unit

Post by Pilauli »

If you figure it out, I'd love to know that, too! I can share a couple of workarounds I thought of, though:

- When you create the side, DON'T put a leader in it. Instead, write no_leader=yes. Then, in the prestart event, set your variable, then create your leader unit (making sure to write "canrecruit=yes" in its definition.)

- Since variables persist from one scenario to the next, you might be able to create a dummy scenario for setting variables that will be used in later scenarios.
User avatar
WhiteWolf
Forum Moderator
Posts: 640
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: dabber's questions: object on unit

Post by WhiteWolf »

I'm not sure I understand the question entirely, but if you want to define a variable that is already accessed in a side definition, then I guess that's what a preload event is for, or equivalently, you could define it at the very end of the previous scenario.
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: object on unit

Post by dabber »

preload event doesn't work. A lua error shows up, and its definitely from using the variable. I am using 1.14.9 (which reminds me, I should upgrade to 14.14), so maybe that works in 1.15.x?
User avatar
Ravana
Forum Moderator
Posts: 2452
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: dabber's questions: object on unit

Post by Ravana »

Preload and variable should not be related. I doubt [side] supports variable evaluation.

So use case I would solve by setting objects during prestart.
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: object on unit

Post by dabber »

I solved the leader modification problem with a turn 1 event that does all the work. That is much easier long term, because now each scenario needs less editing. It also lets me work on any units spawned in the [side] definition automatically.
Post Reply