Units disappear when reloading; and enemy on same team

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
User avatar
GForce0
Posts: 63
Joined: May 17th, 2020, 5:58 pm

Units disappear when reloading; and enemy on same team

Post by GForce0 »

Hi all, I am GForce, I have played this game for 15 years or so and since a few months started making my own scenarios to play with friends. Looking at wiki and forums, it was going very well in fact. But now I am moving from 1.10 to 1.14 as it will be discontinued, and two problems showed up that I don't understand, I hope someone could help out.

1. Units disappear when reloading.
I spawn 4 units every turn for the AI and this goes without problems. But when I load an autosave from whatever turn again, all spawned units except for the first one are gone. Why would that be? I spawn the units using the code below:

Code: Select all


[event]
name=side 5 turn
first_time_only=no

[set_variable]
	name=counter
	value=8
[/set_variable]
[set_variable]
	name=limit
	value=$counter
	add=$portal_strength
[/set_variable]

[while]
	[variable]
		name = counter
		less_than = $limit
	[/variable]
	[do]
		[if]
			[not]
				[have_unit]
					x = 2
					y = $counter
					side = 4
				[/have_unit]
			[/not]
			[then]
				[unit]
					type=Yeti
					id=Yeti
					side = 4
					x = 2
					y = $counter
					max_experience = 555
				[/unit]
				[set_variable]
					name=counter
					add=1
				[/set_variable]
			[/then]
		[/if]
	[/do]
[/while]
[clear_variable]
	name=counter,limit
[/clear_variable]


[/event]


2. Enemy on the same team

For sides 1, 2, 3 and 5 I declared

Code: Select all

 team_name=1 
. At some point, I spawn allied Paladins. Omitting conditions and loop, as follows:

Code: Select all

...
[unit]
	type=Paladin
	side = 5
	id = lightrider
	x = 32
	y = $counter
	max_moves=80
	max_hitpoints=250
	vision=500
[/unit]
...
In the status table, side 5 indeed shows up as team 1. However, they are somehow not allied to sides 1, 2, 3 and will attack them.
If after spawning I add the following, it works as it should, they will be allied:

Code: Select all

[modify_side]
	side=5
	team_name = 1
[/modify_side]
But it is not nice, why would it not work immediately? And how could I do it?
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Units disappear when reloading; and enemy on same team

Post by beetlenaut »

The id tells the game which unit is which. Having the same id on two units will cause all sorts of trouble. (I'm surprised it's not crashing the game, actually.) You can make an id like "yeti_$counter", but you can't have them all be "yeti". Fixing the two cases of that should fix most if not all of your problems.

Another point, don't put "add" and "value" in the same [set_variable]. It might work some of the time, but I'm pretty sure they can happen in any order. Do them one at a time or use a formula.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
GForce0
Posts: 63
Joined: May 17th, 2020, 5:58 pm

Re: Units disappear when reloading; and enemy on same team

Post by GForce0 »

Ah, how stupid of me, thanks!
In fact I don't need id=Yeti anyway, so I removed it, and surprisingly it solved both problems.

For the paladins I used id to filter, but I suppose I should use role there. I assume that one can be used the same on multiple units.

And also thanks for the tip on using a formula!


EDIT: Just for the record to be correct, actually it was that removing id=Yeti solved the first problem, removing id=lightrider solved the second problem.
Last edited by GForce0 on May 31st, 2020, 11:57 am, edited 1 time in total.
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Units disappear when reloading; and enemy on same team

Post by beetlenaut »

GForce0 wrote: May 28th, 2020, 6:45 pm I suppose I should use role there. I assume that one can be used the same on multiple units.
I'm not sure it can. If you use the [role] tag, it only assigns the role to one unit. You might be able to hack the role with [modify_unit], but I wouldn't count on that never changing. If you want to go that way, just add a custom variable to the unit with [variables] instead. You can put anything you want in it. (You use [filter_wml] in your unit [filter] to check [variables].) It looks like you can filter on type and/or one of your other custom values though, which would be shorter.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
GForce0
Posts: 63
Joined: May 17th, 2020, 5:58 pm

Re: Units disappear when reloading; and enemy on same team

Post by GForce0 »

Hmm alright, so better to use multiple other variables to filter than trying to use a shortcut here. Thank you for the help!
Post Reply