[set_variables] not doing anything for me

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
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

[set_variables] not doing anything for me

Post by A Guy »

I'm trying to use [insert_tag] to create a spell menu that adjusts as the game goes on, but [set_variables] isn't working for me AT ALL. Here's a little code I used to test it before I committed to anything. I can't find what I did wrong.

Code: Select all

	[set_variables]
		name=$side_number|.spells.option
		mode=append
		[value]
			[message]
				message={MENU_IMG_TXT "attacks/fireball.png" "Fireball"}
			[/message]
			[command]
				[message]
					speaker=narrator
					side_for=$side_number
					message= _ "This spell inflicts 10 damage to target unit."
				[/message]
			[/command]
		[/value]
	[/set_variables]
EDIT: Still having problems. If it helps, I used inspect and nothing showed up, nothing was adjusted.
I'm just... a guy...
I'm back for now, I might get started on some work again.
User avatar
doofus-01
Art Director
Posts: 4128
Joined: January 6th, 2008, 9:27 pm
Location: USA

Re: [set_variables] not doing anything for me

Post by doofus-01 »

Where did you get that code? Is there an example where something like that works? It looks nothing like what's in the wiki, to me at least...
Maybe you should post more of your code.
BfW 1.12 supported, but active development only for BfW 1.13/1.14: Bad Moon Rising | Trinity | Archaic Era |
| Abandoned: Tales of the Setting Sun
GitHub link for these projects
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: [set_variables] not doing anything for me

Post by A Guy »

Nevermind, I found the problem. I just needed message=, instead of putting it in brackets.

Code from wiki.wesnoth.org/InternalActionsWML

EDIT: Nevermind, STILL not working.
I'm just... a guy...
I'm back for now, I might get started on some work again.
User avatar
doofus-01
Art Director
Posts: 4128
Joined: January 6th, 2008, 9:27 pm
Location: USA

Re: [set_variables] not doing anything for me

Post by doofus-01 »

[message] & [command] inside [set_variables]? I don't think that's in the wiki. Maybe you want to be using [message]->[command] from a [fire_event]?
BfW 1.12 supported, but active development only for BfW 1.13/1.14: Bad Moon Rising | Trinity | Archaic Era |
| Abandoned: Tales of the Setting Sun
GitHub link for these projects
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: [set_variables] not doing anything for me

Post by A Guy »

doofus-01 wrote:[message] & [command] inside [set_variables]? I don't think that's in the wiki. Maybe you want to be using [message]->[command] from a [fire_event]?
I've done tag manipulation like that before, I'm just confused why it isn't working in this instance. It works when I remove the variable substitution (replace $side_number with a defined side, like 1), but problem is, I need the variable substitution.

EDIT: FOUND THE PROBLEM. THE EVENT THAT SETS THE VARIABLE BASED ON $side_number IS A PRESTART EVENT. God, I feel stupid now.
I'm just... a guy...
I'm back for now, I might get started on some work again.
User avatar
doofus-01
Art Director
Posts: 4128
Joined: January 6th, 2008, 9:27 pm
Location: USA

Re: [set_variables] not doing anything for me

Post by doofus-01 »

Good you got it working. I don't think I helped, but cheers anyway.

For anyone reading this who is confused: it doesn't make any sense to me either.
BfW 1.12 supported, but active development only for BfW 1.13/1.14: Bad Moon Rising | Trinity | Archaic Era |
| Abandoned: Tales of the Setting Sun
GitHub link for these projects
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: [set_variables] not doing anything for me

Post by Pentarctagon »

doofus-01 wrote:Good you got it working. I don't think I helped, but cheers anyway.

For anyone reading this who is confused: it doesn't make any sense to me either.
You can store code in the [set_variables] tag. For example, one way I've done it is:

Code: Select all

[set_variables]
name=varname

[value]
message="my message"
[command]
...stuff to do...
[/command]
[/value]
[/set_variables]
and then later do:

Code: Select all

[insert_tag]
name=option
variable=varname
[/insert_tag]
and it will essentially wrap the [option] tag around the data in "varname" and create an option with the message of "my message" that executes whatever you put in the [command] tags. The data can then be modified via dot notation, for example:

Code: Select all

{VARIABLE varname.message "new message"}
which would now display an option with the message "new message" instead.

The [insert_tag] tag also wraps the [option] tag (or whatever tag you used) around every index. So you can also append more options into the array as varname[1], varname[2], etc. and the [insert_tag] would create an option for each index.
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
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: [set_variables] not doing anything for me

Post by Elvish_Hunter »

A Guy wrote:I can't find what I did wrong.
I think that the probem is in this line:

Code: Select all

name=$side_number|.spells.option
Let's pretend that it's the side 3 turn. In that moment, $side_number takes the "3" value. So, your variable name will be 3.spells.option, and this doesn't work because variable names cannot start with a number (and that's common to all programming languages). You can try, for example, using this instead:

Code: Select all

name=side_$side_number|.spells.option
EDIT: after shadowmaster's post, I found out that, unlike every other language, WML can handle even variable names entirely made with numbers:

Code: Select all

-- this Lua code works fine
wesnoth.set_variable(3,"test")
EDIT 2: and I also completely missed that edit:
A Guy wrote:EDIT: FOUND THE PROBLEM. THE EVENT THAT SETS THE VARIABLE BASED ON $side_number IS A PRESTART EVENT. God, I feel stupid now.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Iris
Site Administrator
Posts: 6798
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: [set_variables] not doing anything for me

Post by Iris »

Elvish_Hunter wrote:and this doesn't work because variable names cannot start with a number
WML variables can.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
Post Reply