Spawning a unit in 2 scenarios later based on a choice

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.
Post Reply
tribes55
Posts: 132
Joined: June 10th, 2012, 4:29 am

Spawning a unit in 2 scenarios later based on a choice

Post by tribes55 »

Didn't really know what to put in the subject line.

So, in one of my scenarios you can choose 4 units out of a total of eight units to accompany you in the following scenarios.
Two scenarios later, I spawn in the units that you didn't pick to help defend.

But it's not working; they are not spawning, and I don't know why.

Here is an example of what I have for one of the units:

Scenario 3 (Where you pick the units) I did not include the entire event as it is large.
Spoiler:
So that event makes it where the variable is set to 2 if you choose him. Otherwise, it is set to one. I also set the variable to one at the start of the scenario, so it's rather redundant, but it's there for the sake of testing.

Two scenarios later, I do a check and attempt to spawn in the unit.

Code: Select all

[event]
	name=harlarvar
[if]
	[variable]
		name=harlarvar
		equals=1
	[/variable]
	[then]
	{NAMED_UNIT 4 "Dwarvish Steelclad" 13 9 Harlar "Harlar the Quiet" hitpoints=38}
	[/then]
[/if]
[/event]
But he doesn't spawn, despite the variable's value being 1. Nothing happens.
So to recap: I want the units that aren't picked to spawn in two scenarios later. I do this by assigning variable's value to 1 if they're not picked, and 2 if they're picked. Two scenarios later, I check if the value is 1. If it's one, I attempt to create the unit, but it doesn't work.

Thanks!
Last edited by tribes55 on July 28th, 2018, 9:21 pm, edited 1 time in total.
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: Spawning a unit in 2 scenarios later based on a choice

Post by josteph »

Do you mean equals=1 instead of value=1?

https://wiki.wesnoth.org/ConditionalAct ... ition_Tags
tribes55
Posts: 132
Joined: June 10th, 2012, 4:29 am

Re: Spawning a unit in 2 scenarios later based on a choice

Post by tribes55 »

Oh yes, I did. I have made the adjustment to the second part, I think that's all that's necessary to make since the first part isn't conditional around the variable.
But it still doesn't work.
User avatar
octalot
General Code Maintainer
Posts: 786
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: Spawning a unit in 2 scenarios later based on a choice

Post by octalot »

Are you sure the event in the later scenario is triggering? It has name=harlarvar, but I'd expect name=start or name=turn 1.

BTW, you don't need conditional code, you can just store an array of units in a variable with [store_unit] and unstore them in a later scenario, which means you only need to put their stats in the first scenario.
tribes55
Posts: 132
Joined: June 10th, 2012, 4:29 am

Re: Spawning a unit in 2 scenarios later based on a choice

Post by tribes55 »

Yeah, I figured a work-around would be to switch their sides via [modify_unit], then store them. Then I suppose I could recall and then modify their side again, but that seems pretty duct-tapey. I don't want them to be owned by player one.

Edit:

I tried including it all in the start event (excluding the event tags of the original code, and their respective names) and it still did not work.
User avatar
octalot
General Code Maintainer
Posts: 786
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: Spawning a unit in 2 scenarios later based on a choice

Post by octalot »

Split the problem in to smaller ones - put a [message] in the event, and check that the event triggers. Then put some debugging in to the message, or use an [inspect] tag, to check the values of the variables just before it fails.

They don't need to be owned by side 1 to be stored in a variable (although you would still have to switch the side number if it was a different side in the second scenario).
Post Reply