Problem with switch

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
EnergiaX
Posts: 19
Joined: May 12th, 2018, 10:59 am

Problem with switch

Post by EnergiaX »

Hi,
I have problem witch [switch] [case] Wiki example https://wiki.wesnoth.org/ConditionalAct ... Bswitch.5D
I don't understand why don't work, no error is displayed. It just does not enter [switch], i try more times and debug witch message.

Code: Select all

#define Armor X Y
{VARIABLE ArmorName A}
	[item]
		x={X}
		y={Y}
		image=items/armor.png
    [/item]
	[event]
		name=moveto
		[filter]
			x={X}
			y={Y}
		[/filter]
		{VARIABLE_OP temp_rand_value rand (1,2)}
		[object]
			image=items/armor.png
			silent=yes
			[filter]
				x={X}
				y={Y}
			[/filter]
			[then]
				[unit_overlay]
					x={X}
					y={Y}
					image=overlays/arcane-icon.png
				[/unit_overlay]
				[remove_item]
					x,y={X},{Y}
				[/remove_item]
			[/then]
			[effect]
				apply_to=hitpoints
				increase=15
				increase_total=15
			[/effect]		
				[switch]
				variable=$temp_rand_value
					[case]
						value=1
						#ArmorName= _ "Arcane Armor"
						[effect]
							apply_to=resistance
							replace=false
							[resistance]
							arcane=-5
							[/resistance]
						[/effect]
					[/case]	
					[case]
						value=2
						#ArmorName= _ "Pierce Armor"
						[effect]
							apply_to=resistance
							replace=false
							[resistance]
							pierce=-5
							[/resistance]
						[/effect]
					[/case]	
					[/switch]
					#name=$ArmorName
		[/object]
	[/event]
#enddef
Armor is it, +15 hp it work. When I use message =$temp_rand_value, i see 1 or 2. When i delate switch and case, I give resistance bonuses. Can anyone help?
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Problem with switch

Post by Ravana »

[switch] is not subtag of [object].
User avatar
Pentarctagon
Project Manager
Posts: 5526
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Problem with switch

Post by Pentarctagon »

I'd assume you'd need to put the [switch] inside of the [then].
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
EnergiaX
Posts: 19
Joined: May 12th, 2018, 10:59 am

Re: Problem with switch

Post by EnergiaX »

But when I put the [switch] inside of the [then] i have error:
<invalid WML found> [effect] not supprted
In game (the game turns on, the error is displayed as it tries to take an artifact)

meaby [effect] it can not be inside [then]

Somewhere I can find information about what tag can be in what tag?
Caladbolg
Posts: 198
Joined: January 1st, 2016, 4:40 pm
Location: Hopelessly trapped within the Submachine

Re: Problem with switch

Post by Caladbolg »

You might have to do some digging around, but this is a good starting point:
https://wiki.wesnoth.org/ActionWML
It says that ConditionalActionsWML (which [switch] is a part of) belongs to ActionWML, and you have a list of cases where it can be used; [object] is not one of them.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Problem with switch

Post by Ravana »

Inside [case] goes ActionWML, and [effect] is not part of ActionWML. Possible solutions for your use are:
[insert_tag],
[lua],
multiple [object]s.

I suggest last one.
EnergiaX
Posts: 19
Joined: May 12th, 2018, 10:59 am

Re: Problem with switch

Post by EnergiaX »

Ok, thx.
Making a few objects will be the most easy.
[topic can close]
Post Reply