Heindals WML Questions

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.
User avatar
Heindal
Posts: 883
Joined: August 11th, 2011, 9:25 pm
Location: Germany

Re: Heindals WML Questions

Post by Heindal » January 25th, 2013, 9:11 pm

I know that I can't just replace the for each with a while loop. I have to rethink the whole process and as I said make a workaround, which so far worked for a single object. Still having problems with manipulating a comma seperated list. I will post the solution when I'm done.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses

User avatar
pyrophorus
Posts: 513
Joined: December 1st, 2010, 12:54 pm

Re: Heindals WML Questions

Post by pyrophorus » January 29th, 2013, 6:36 am

Hi !
I have recently designed something rather close to your need (AFAICS). The main macro builds a message tag listing the modification objects of an unit which can be used in a set_menu_item. Maybe this can help you. The code is here:

Code: Select all

# This is the 'command' tag of each option.
#define LSB_CLEAR_UNITOBJECT
	{LSB_DROP_OBJECT $unit.modifications.object[$nc].uid $x1 $y1}
	{CLEAR_VARIABLE unit.modifications.object[$nc]}
#enddef
		
# list 'unit' objects
#define LSB_LIST_UNIT_THINGS
	{VARIABLE t_done non}
	[while]
		[variable]
			name=t_done
			equals=non
		[/variable]
		[do]
			{CLEAR_VARIABLE t_menu}
			{VARIABLE t_menu.message "Drop items:"}
			{VARIABLE t_menu.speaker narrator}

			{FOREACH unit.modifications.object nc}
				[set_variables]
					name=t_action
					mode=replace
					[value]
						{LSB_CLEAR_UNITOBJECT}
					[/value]
				[/set_variables]
				[set_variables]
					name=t_menu.option
					mode=append
					[value]
						message=$unit.modifications.object[$nc].name
						[insert_tag]
							name=command
							variable=t_action
						[/insert_tag]
					[/value]		
				[/set_variables]
			{NEXT nc}
			
			{VARIABLE nc $t_menu.option.length}
			[set_variables]
				name=t_menu.option
				mode=append
				[value]
					message="Exit."
				[/value]		
			[/set_variables]
			[set_variables]
				name=t_stop
				[value]
					name=t_done
					value=oui
				[/value]
			[/set_variables]
			[set_variables]
				name=t_menu.option[$nc].command
				[value]
					[insert_tag]
						name=set_variable
						variable=t_stop
					[/insert_tag]
				[/value]
			[/set_variables]
	
			[insert_tag]
				name=message
				variable=t_menu
			[/insert_tag]
		[/do]
	[/while]
	{CLEAR_VARIABLE t_menu,t_stop,nc,t_action}
#enddef

# --- can be used in a menu:
	[set_menu_item]
		id=LSB_drop
		description="Drop items."
		  [show_if]
			[variable]
				name=unit.side
				equals=1
			[/variable]
		  [/show_if]
		[command]
			{LSB_LIST_UNIT_THINGS}
		[/command]
	[/set_menu_item]	
It's not really important in this example, but the 'objects' used here are all stored in a array built in this way:

Code: Select all


	[set_variables]
		name=Objets
		mode=replace
	[value]
		{LSB_DEXTERITY_OBJ}
	[/value]
# ... and much more
	[/set_variables]
Where OBJs have this definition:

Code: Select all

#define LSB_DEXTERITY_EFF
	[effect]
		apply_to=attack
		remove_specials=nomiss
		increase_damage=25%
		[set_specials]
			mode=append
			{LSB_NOMISS 90}
		[/set_specials]
	[/effect]
#enddef

#define LSB_DEXTERITY_OBJ
	name= _ "Dexterity circlet"
	image=items/circlet.png
	description= _ "Add dexterity to all your weapons."
	category=rings
	level=2
	{LSB_DEXTERITY_EFF}
#enddef
HTH,
Campaign Return to Noelren *** HowTos: WML filtering, WML variables
Please help to to update the Guide to UMC Campaigns

User avatar
Heindal
Posts: 883
Joined: August 11th, 2011, 9:25 pm
Location: Germany

Re: Heindals WML Questions

Post by Heindal » January 29th, 2013, 6:17 pm

Thanks for this, I will check this out when I have time - which should be sometimes next week :P.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses

User avatar
Heindal
Posts: 883
Joined: August 11th, 2011, 9:25 pm
Location: Germany

Re: Heindals WML Questions

Post by Heindal » January 1st, 2014, 10:46 pm

Hi again,

so far I've been creating a very promising random map generator using puzzle tiles of terrain and placing them on the map.
I'm using the following code:

Code: Select all

           [terrain_mask]
                x,y={STARTX},{STARTY}
                mask="border_size=1
usage=map

Qxe         , Qxe         , Qxe         , Uue         , Qxe         , Qxe         , Qxe         
Uue         , Qxe         , Qxe         , Uue         , Qxe         , Qxe         , Qxe         
Uue         , Uue         , Uue         , Uue         , Uue         , Qxe         , Uue         
Uue         , Qxe         , Qxe         , Uue         , Qxe         , Uue         , Uue         
Qxe         , Qxe         , Qxe         , Uue         , Qxe         , Qxe         , Qxe         
Qxe         , Qxe         , Qxe         , Uue         , Qxe         , Qxe         , Qxe" 
            [/terrain_mask]
The code however works fine, even so I've got to make it leaner. The dungeon is placed.
However I receive following bug report:

data/lua/wml/items.lua:8: bad argument #1 add_tile_overlay (number expected got string)

This somehow messes with the placement of images and items. Its seems impossible to place images on random locations within such a random map, even so the events will be fired. Any ideas and experience with that matter? What causes the problem?


Edit: :oops: Blast it, even so I tried hours before to solve it I now found a solution and found the reason for the bug.
I needed to place the images within the start event tag, however I still can't place images outside of the start event :/.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses

User avatar
Heindal
Posts: 883
Joined: August 11th, 2011, 9:25 pm
Location: Germany

Re: Heindals WML Questions

Post by Heindal » May 24th, 2018, 6:56 pm

It'se me again, Mario err Heindalo. Currently I'm cleaning out the bugs in my 1.14 campaigns. Five Fates is almost done, even so there where some troublesome news about my random dungeon generator, but I found a workaround. But I keep getting this message and can't get rid of it. Any ideas where to look?

"lua/wml/object:lua:23 bad argument #1 to 'get_unit' (expected string or location)
stack traceback: ..."
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses

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

Re: Heindals WML Questions

Post by Ravana » May 24th, 2018, 7:35 pm

I looked "lua/wml/object:lua:23 which leads to line 9 which suggests you called [object] without event and filter.

User avatar
Heindal
Posts: 883
Joined: August 11th, 2011, 9:25 pm
Location: Germany

Re: Heindals WML Questions

Post by Heindal » May 25th, 2018, 11:43 pm

Thanks Ravana, now I could solve the problem. So the error messages is referencing to a file, where I could look up the reason. :hmm:
I added a statue of Ravana the Keeper to the add-on. Will have to test the add-on however before its finished.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses

Post Reply