EarthCake's problems

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
EarthCake
Posts: 377
Joined: March 29th, 2019, 1:57 pm
Location: The Wall

Re: EarthCake's problems

Post by EarthCake »

Thanks!
User avatar
EarthCake
Posts: 377
Joined: March 29th, 2019, 1:57 pm
Location: The Wall

Re: EarthCake's problems

Post by EarthCake »

Unmounting units:
I have few loyal mounted units, and I want to make them "ground" units on same tile when they lose all hp. In example, if they are horsemen, I want to make them spearmans, but to make them keep xp. Same as knight -> Pikeman. Is that possible?
User avatar
Ravana
Forum Moderator
Posts: 3004
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: EarthCake's problems

Post by Ravana »

Yes.

Either die event and create new unit based on old one, or last breath and change old unit into new unit.
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: EarthCake's problems

Post by josteph »

Note that Knight max_xp > Pikeman max_xp, so it's possible for the dying Knight to have more experience than Pikeman's max_XP.
User avatar
EarthCake
Posts: 377
Joined: March 29th, 2019, 1:57 pm
Location: The Wall

Re: EarthCake's problems

Post by EarthCake »

How do I make them keep the same name, traits, and to appear at same tile?
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: EarthCake's problems

Post by josteph »

Use transform_unit.
User avatar
octalot
General Code Maintainer
Posts: 786
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: EarthCake's problems

Post by octalot »

Code: Select all

                [unit]
                    type=Pikeman
                    name=$unit.name
                    x,y=$x1,$y1
                    # The unit has almost been killed, so assume they start with no moves. Might also want attacks=0.
                    moves=0
                    side=$unit.side
                    experience=$unit.experience
                    # having animate=yes will make the unit appear as if it was recruited, see if it looks right
                    animate=yes
                [/unit]
Copying the traits can be done as in this code from SotA. The SotA code also has loads of other stuff which you probably won't want, but is a handy list of edge-cases.
User avatar
EarthCake
Posts: 377
Joined: March 29th, 2019, 1:57 pm
Location: The Wall

Re: EarthCake's problems

Post by EarthCake »

There us some problem with lua:

Code: Select all

<Lua error>
	game_error: creating unit with an empty type field
	stack traceback:
		[C]: in local 'cmd'
		lua/wml-utils.lua:145: in field 'handle_event_commands'
		lua/wml-flow.lua:6: in function <lua/wml-flow.lua:5>
Here is code for "Unmounting.cfg":

Code: Select all

[event]
	name=last breath
	first_time_only=no
	[set_variables]
		name=unmounting
		mode=replace
		to_variable=unit
	[/set_variables]
	[if]
		[variable]
			name=unmounting.id
			equals=Horseman
		[/variable]
		[then]
			[set_variable]
				name=horseman
				value=Spearman
			[/set_variable]
		[/then]
	[/if]
	[if]
		[variable]
			name=unmounting.id
			equals=Cavalryman
		[/variable]
		[then]
			[set_variable]
				name=cavalryman
				value=Swordsman
			[/set_variable]
		[/then]
	[/if]
	[unit]
		side=1
		type=$horseman
		x=$unmounting.x
		y=$unmounting.y
		id=$unmounting.id
		name=$unmounting.name
		facing=$unmounting.facing
		moves=2
		hitpoints=14
            	[modifications]
                	[insert_tag]
                    		name=trait
                    		variable=unmounting.modifications.trait[0]
                	[/insert_tag]
                	[insert_tag]
                    		name=trait
                    		variable=unmounting.modifications.trait[1]
                	[/insert_tag]
            	[/modifications]
	[/unit]
	[unit]
		side=1
		type=$cavalryman
		x=$unmounting.x
		y=$unmounting.y
		id=$unmounting.id
		name=$unmounting.name
		facing=$unmounting.facing
		moves=2
		hitpoints=14
            	[modifications]
                	[insert_tag]
                    		name=trait
                    		variable=unmounting.modifications.trait[0]
                	[/insert_tag]
                	[insert_tag]
                    		name=trait
                    		variable=unmounting.modifications.trait[1]
                	[/insert_tag]
            	[/modifications]
	[/unit]
[/event]
josteph wrote: May 10th, 2019, 1:10 pm Use transform_unit.
That only transforms horseman into next level and then kills him (but very probably I screwed something with the code).
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: EarthCake's problems

Post by Pentarctagon »

What are the values of $horseman and $cavalryman just before the [unit] tags start?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
EarthCake
Posts: 377
Joined: March 29th, 2019, 1:57 pm
Location: The Wall

Re: EarthCake's problems

Post by EarthCake »

Pentarctagon wrote: May 10th, 2019, 6:24 pm What are the values of $horseman and $cavalryman just before the [unit] tags start?
$horseman = Spearman
$cavalryman = Swordsman

Code: Select all

			[set_variable]
				name=cavalryman
				value=Swordsman
			[/set_variable]

Code: Select all

			[set_variable]
				name=horseman
				value=Spearman
			[/set_variable]
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: EarthCake's problems

Post by Pentarctagon »

EarthCake wrote: May 10th, 2019, 6:43 pm
Pentarctagon wrote: May 10th, 2019, 6:24 pm What are the values of $horseman and $cavalryman just before the [unit] tags start?
$horseman = Spearman
$cavalryman = Swordsman

Code: Select all

			[set_variable]
				name=cavalryman
				value=Swordsman
			[/set_variable]

Code: Select all

			[set_variable]
				name=horseman
				value=Spearman
			[/set_variable]
And it prints that if you add:

Code: Select all

[message]
	message=$cavalryman
[/message]
[message]
	message=$horseman
[/message]
?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Ravana
Forum Moderator
Posts: 3004
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: EarthCake's problems

Post by Ravana »

Those tags are not reached, so both variables are undefined.

Also, while this might work but it looks dodgy.

Code: Select all

[set_variables]
		name=unmounting
		mode=replace
		to_variable=unit
	[/set_variables]
User avatar
EarthCake
Posts: 377
Joined: March 29th, 2019, 1:57 pm
Location: The Wall

Re: EarthCake's problems

Post by EarthCake »

Ah, value needs to be Horseman and Cavalryman ?

About code mentioned up, I copied that from SotA (thanks octalot!) and it works there.
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: EarthCake's problems

Post by josteph »

You're comparing unmounting.id to "Horseman", that's never going to be equal. You meant to compare unmounting.type.
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: EarthCake's problems

Post by josteph »

EarthCake wrote: May 10th, 2019, 6:14 pm
josteph wrote: May 10th, 2019, 1:10 pm Use transform_unit.
That only transforms horseman into next level and then kills him (but very probably I screwed something with the code).
I assumed you had already solved the "prevent the unit from dying when it reaches 0HP" part and was asking only about the "change the unit's type preserving its other attributes" part.

In any case, a last breath event that does [modify_unit] hitpoints=... would prevent the unit from dying, after that you can do [transform_unit] to change its type.
Post Reply