set_variable nested in "if then" using iteration: provisional results

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
zookeeper
WML Wizard
Posts: 9734
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: set_variable nested in "if then" using iteration: provisional results

Post by zookeeper » April 1st, 2018, 6:25 pm

What he means is:

Don't do this:

Code: Select all

[if]
    [variable]
        name=$variablename
Do this:

Code: Select all

[if]
    [variable]
        name=variablename
It's asking for the variable name to use/check/set/etc. So you want to give it the variable name. Only use the $ sign when you want the value of the variable.

hyper_cubed
Posts: 31
Joined: March 31st, 2018, 7:52 pm
Location: USA

Re: set_variable nested in "if then" using iteration: provisional results

Post by hyper_cubed » April 1st, 2018, 6:42 pm

You are all awesome, Zookeeper's interpretation of what Ravanna was saying immediately fixed my problem. I can now dynamically pick up any specials as long as a mod uses the typical categories! I have been trying to figure this out for a few days now.

Code: Select all

#get all specials categories and ids in order to query based on either sub data or specials meta data
	#create specials category list
	[set_variables]
		name=specials_categories
			[value]
				category="attacks" #0
			[/value]
			[value]
				category="berserk" #1
			[/value]
			[value]
				category="chance_to_hit" #2
			[/value]
			[value]
				category="damage" #3
			[/value]
			[value]
				category="disable" #4
			[/value]
			[value]
				category="drains" #5
			[/value]
			[value]
				category="dummy" #6
			[/value]
			[value]
				category="firststrike" #7
			[/value]
			[value]
				category="heal_on_hit" #8
			[/value]
			[value]
				category="petrifies" #9
			[/value]
			[value]
				category="plague" #10
			[/value]
			[value]
				category="poison" #11
			[/value]
			[value]
				category="slow" #12
			[/value]
			[value]
				category="swarm" #13
			[/value]
	[/set_variables]
	
	#if special exist, get it and store tag name along with id
	{VARIABLE j 0}
	[while]
		[variable]
			name="j"
			less_than=$unit.attack.length
		[/variable]
		[do]
			{VARIABLE k 0}
			[while]
				[variable]
					name="k"
					less_than=$specials_categories.length
				[/variable]
				[do]
					{VARIABLE l 0}
					[while]
						[variable]
							name="l"
							less_than=3
						[/variable]
						[do]
							{VARIABLE specials_category_content "$specials_categories[$k].category"}
							{VARIABLE special_id_content "$unit.attack[$j].specials.$specials_categories[$k].category|[$l].id"}
							[if]
								[variable]
									#used Ravanna's variable assignment and then used the interpretation of zookeeper
									name=special_id_content
									#implemented Sapient's advice on emptys
									not_equals="$empty"
								[/variable]
								[then]
									[set_variables]
										name=specials_array
										mode=insert
										[value]
											category=$specials_category_content
											id=$specials_category_content
										[/value]
									[/set_variables]
								[/then]
							[/if]
							{CLEAR_VARIABLE specials_category_content}
							{CLEAR_VARIABLE special_id_content}
							#check if special id procs using the in game inspector
							{VARIABLE unit.variables.special_id_$j|$k|$l| $unit.attack[$j].specials.$specials_categories[$k].category|.length}
						{VARIABLE_OP l add 1}
						[/do]
					[/while]
					{CLEAR_VARIABLE l}
				{VARIABLE_OP k add 1}
				[/do]
			[/while]
			{CLEAR_VARIABLE k}
		{VARIABLE_OP j add 1}
		[/do]
	[/while]
	{CLEAR_VARIABLE j}
	{CLEAR_VARIABLE specials_categories}
Attachments
Success.PNG

User avatar
Pentarctagon
Forum Administrator
Posts: 3517
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: set_variable nested in "if then" using iteration: provisional results

Post by Pentarctagon » April 1st, 2018, 7:06 pm

@hyper_cubed: In the future, please don't doublepost.
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
Moderator
Posts: 1832
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: set_variable nested in "if then" using iteration: provisional results

Post by Ravana » April 1st, 2018, 7:13 pm

You correctly retrieve ids you underlined there, and then ask their value. You ask for variable named poison. It is not assigned any value.

hyper_cubed
Posts: 31
Joined: March 31st, 2018, 7:52 pm
Location: USA

Re: set_variable nested in "if then" using iteration: provisional results

Post by hyper_cubed » April 1st, 2018, 7:20 pm

Ravana wrote:
April 1st, 2018, 7:13 pm
You correctly retrieve ids you underlined there, and then ask their value. You ask for variable named poison. It is not assigned any value.
I think I understand what you are saying. When the engine querys for variable name, and then I use substitution to hook into name then I am setting the variable name to whatever dynamic value that my lookup yields, whereas, I should have omitted the $ to drill down to the actual variable name and not the value.

Okay.

Also, @Pentarctigon: Sorry about that, I thought that my last post left out a few things. Thanks for the kind notification.

Post Reply