tekelili advanced WML questions

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
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

tekelili advanced WML questions

Post by tekelili »

Hi, to not spam never more wml forum I decided put togegher all my silly questions here.

To no spam this thread I will avoid "thanks posts", but of course thanks a lot to anyone who answer :)

To inaugurate my noob questions here is the first:



I want to trigger an event on a turn related to a variable. I tried this:

[set_variable]
name=eruption
value=10
[/set_variable]

[event]
name=turn ($eruption+2)
[/event]



This is not working probably because is "invented stuff". How can I trigger an event on a variable turn?
Last edited by tekelili on December 18th, 2013, 7:49 am, edited 1 time in total.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: tekelili WML noob questions

Post by zookeeper »

Code: Select all

[event]
    name=new turn
    first_time_only=no
    
    [if]
        [variable]
            name=turn_number
            numerical_equals="$($eruption + 2)"
        [/variable]
        
        [then]
User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: tekelili WML noob questions

Post by tekelili »

I hope this is last one for some time:

I want display a message of 2 lines having different typo size each line. in other words, I want to display theese 2 [print] tags in just one [print] tag to avoid second one instant delete first one:

[print]
text=Volcano Active
size=40
duration=700
red,green,blue=255,0,0
[/print]
[print]
text="(Eruption on Turn "+$eruption+")"
size=20
duration=700
red,green,blue=255,0,0
[/print]

It is possible?
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
User avatar
Dovolente
Posts: 140
Joined: April 17th, 2007, 9:02 pm
Location: Southeastern US
Contact:

Re: tekelili WML noob questions

Post by Dovolente »

I don't know if span or multiple lines works with [print], but you could try:

Code: Select all

text="<span size='large'>Volcano etc</span>
Eruption etc"
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: tekelili WML noob questions

Post by monochromatic »

Use pango markup.
Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: tekelili WML noob questions

Post by Anonymissimus »

tekelili wrote:I want to trigger an event on a turn related to a variable. I tried this:

[set_variable]
name=eruption
value=10
[/set_variable]

[event]
name=turn ($eruption+2)
[/event]

Code: Select all

	[event]
		name=turn 1
		[set_variable]
			name=eruption
			value=10
		[/set_variable]
		[event]
			delayed_variable_substitution=no
			name="turn $($eruption+2)"
		[/event]
	[/event]
1. The variable must (of course) already be set at the time the inner event is spawned.
2. delayed...=no required
3. "" required around the event name

In case of 1.9 the best approach is probably to use [filter_condition] in zookeeper's approach, instead of [if][variable][then].
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: tekelili WML noob questions

Post by tekelili »

I have a new issue. I want a side starts game with village_gold=5, and be able to change during game to village_gold=2 by an event.

But after try it, I couldnt. After consult WML guide I becomed to think tha sides can only be defined oce at begining of cfg and can not be changed anymore, because so is how wesnoth works. ¿I am right?

this is what I tried:
Spoiler:
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: tekelili WML noob questions

Post by tekelili »

I am trying to learn to use arrays, but looks like I am doing something wrong or I didnt understand wml guide at all :cry:

I want create an array named fruits, and storage "banana", "orange" and "melon" on 0,1 and 2 positions of fruits array.

Then I want use:

[label]
x=10
y=10
value=$fruits[2]
[/label]

Can anyone give me exact code to create that array and a label "melon" is showed on 10.10?

Thanks a lot for help.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: tekelili WML noob questions

Post by Anonymissimus »

untested:

Code: Select all

		[set_variables]
			name=fruits
			[value]
				name=banana
			[/value]
			[value]
				name=orange
			[/value]
			[value]
				name=melon
			[/value]
		[/set_variables]
		#...
		[label]
			x=10
			y=10
			text=$fruits[2].name
		[/label]
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: tekelili WML noob questions

Post by tekelili »

I am having what looks a silly problem, to go across an array I want use a while tag in wich I add +1 to a index, but it looks like I dont know how do that. BtW:

[set_variable]
name=ArrayIndex
value=2
[/set_variable]
[set_variable]
name=ArrayIndex
value=$ArrayIndex+1
[/set_variable]

It looks like I am not having 3 as value storaged inside ArrayIndex variable after execute these 2 tags. I have also tried different modifications of like value=$($ArrayIndex+1) but none looks work.

What code should I use to add +1 to a given variable value inside that variable?
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
User avatar
lipk
Developer
Posts: 637
Joined: July 18th, 2011, 1:42 pm

Re: tekelili WML noob questions

Post by lipk »

[set_variable]
name=ArrayIndex
value=2
[/set_variable]
[set_variable]
name=ArrayIndex
value=$ArrayIndex+1
[/set_variable]
Unfortunately, WML can't handle mathematical expressions. Everything which can't be parsed as a number will be cosnidered to be a string. Strings' numerical value is 0. I said stupid things again :evil: . I'm going to retire, become a monk, and never comment in WML threads again.
If you want to numerically increase a value, then you should do this:

Code: Select all

[set_variable]
  name=MyNumericalValue
  add=1
[/set_variable]
EDIT: for iterating through arrays you're recommended to use the FOREACH macro. details
Last edited by lipk on August 12th, 2011, 10:06 am, edited 1 time in total.
Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: tekelili WML noob questions

Post by Anonymissimus »

tekelili wrote:to go across an array
Any reason for not using the core FOREACH macro then ?

use:
value="$($ArrayIndex+1)"
(with the quotes!)
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: tekelili WML noob questions

Post by Sapient »

Restating and clarifying...

First point

The standard way of iterating through an array in WML would be like so (where 'i' is the chosen name of the index variable)...

Code: Select all

{FOREACH fruits i}
    [message]
        speaker=narrator
        message="Element $i in the fruits array is: $fruits[$i].name"
    [/message]
{NEXT i}
Second point

As already mentioned by lipk, the standard way of incrementing a variable in WML is using [set_variable] add=

Third point

As mentioned by Anonymissimus, if you want to use FormulaAI notation to perform math inside a WML string value, please always remember to surround the string with quote marks! Otherwise the '+' sign will unfortunately be interpreted as a low level string concatenation.

Better to focus on the basics, though, before using FormulaAI notation inside WML strings, e.g. "$(...)"

By the way, the SyntaxWML page on the wiki answers most of these questions, but there's nothing wrong with asking here if it isn't clear enough.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
tekelili
Posts: 1038
Joined: August 19th, 2009, 9:28 pm

Re: tekelili WML noob questions

Post by tekelili »

I have problems to syncronize image and sound during events:

I want remove a wall to free some units and then move them, I am using this kind of code
Spoiler:
My problem is during game first of all units moves before walls are removed, wich looks ugly. Any idea why?

Other similar problem, I want place several units on map and use a sound each time one of them are placed
Spoiler:
But all units are placed in map during game and I only hear sound effect just 1 time

As always, thanks a lot for help :)
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Post Reply