Input value, variable grammar

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
Heindal
Posts: 1357
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Input value, variable grammar

Post by Heindal »

I admit I don't know it, because I never needed it so far.

Is there a way to allow the player to freely input a variable that I can save?
e.g. - Enter your name here ...

Also I wonder if there is a description of how wml variables can be manipulated in a better way.
So far I use things like this: $({PRICE}/2) --> it will take the macro placeholder price and divide it and put out its value.
Is there a description for the syntax, somewhere?

For example is it possible to set several single variables at the same time?
Array handling with wml would be useful, too.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Input value, variable grammar

Post by gfgtdf »

Heindal wrote:I admit I don't know it, because I never needed it so far.

Is there a way to allow the player to freely input a variable that I can save?
e.g. - Enter your name here ...
[message] has a [text_input] that is iirc also used in a mainline scenario. But ofc you can also use wesnoth.show_dialog
Heindal wrote: Also I wonder if there is a description of how wml variables can be manipulated in a better way.
So far I use things like this: $({PRICE}/2) --> it will take the macro placeholder price and divide it and put out its value.
Is there a description for the syntax, somewhere?
You mean a docuemtation about formula? afaik there is teh formulaai wikipage. Also celmin recently wokred on the formula implementation so maybe the wiki pages were improves aswell.
Heindal wrote: For example is it possible to set several single variables at the same time?
Array handling with wml would be useful, too.
Not sure what you mean here.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Heindal
Posts: 1357
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Input value, variable grammar

Post by Heindal »

Thanks gfgtdf,

I will try out to use the suggested method, however I feel like I've already found a better solution.

I will look into the wiki page than. I've already browsed through that, but never found something like that.

The last question is something that is a basic in every coding language.

For example in javascript you use a comma seperated list to set variables to a specific value (0 or 1 or meatrolls). This also defines these 'variables', so they exist and can be addressed and manipulated.

You might have looked into Strange Legacy and maybe realized that I'm defining a lot variables right from the start. Even so this is not necessary, as a variable in WML get's a value and is defined when manipulated the first time, I've used this features to generate a list of several consumable rpg items. This way I can assure that the list/overview shows '0' from the start. So the question is - is that possible:

[set_variables]
name=variable1,variable2,variable3
value=0
[/set_variables]
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Input value, variable grammar

Post by zookeeper »

Heindal wrote:So the question is - is that possible:

[set_variables]
name=variable1,variable2,variable3
value=0
[/set_variables]
No, [set_variable] can't set multiple variables at once, and [set_variables] only operates on arrays.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Input value, variable grammar

Post by gfgtdf »

Heindal wrote:Thanks gfgtdf,

I will try out to use the suggested method, however I feel like I've already found a better solution.
I''m suprised to hear that since afaik these two are the only ways to get arbitary text input from the user, mabye you can explain how you have done it?
Heindal wrote: I will look into the wiki page than. I've already browsed through that, but never found something like that.

The last question is something that is a basic in every coding language.

For example in javascript you use a comma seperated list to set variables to a specific value (0 or 1 or meatrolls). This also defines these 'variables', so they exist and can be addressed and manipulated.

You might have looked into Strange Legacy and maybe realized that I'm defining a lot variables right from the start. Even so this is not necessary, as a variable in WML get's a value and is defined when manipulated the first time, I've used this features to generate a list of several consumable rpg items. This way I can assure that the list/overview shows '0' from the start. So the question is - is that possible:
I dont remember having looked at strange legacys code, which doesn't mean i never did.
Heindal wrote:
[set_variables]
name=variable1,variable2,variable3
value=0
[/set_variables]
No [set_variable] cannot do that but you can alwas use lua/wml to define your own wml tag/macro to do this.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Input value, variable grammar

Post by Sapient »

Heindal wrote: I wonder if there is a description of how wml variables can be manipulated in a better way.
So far I use things like this: $({PRICE}/2) --> it will take the macro placeholder price and divide it and put out its value.
Is there a description for the syntax, somewhere?
See the documentation for Special attribute values, specifically: key = "$(formula-expression)". If you have a more specific question, just ask.
Heindal wrote: For example is it possible to set several single variables at the same time?
The easiest way to initialize a bunch of variables at the start of a scenario is probably with the [variables] tag.

Code: Select all

[variables]
 variable1,variable2,variable3=0,0,0
[/variables]
Heindal wrote: Array handling with wml would be useful, too.
There is a sticky post at the top of the WML Workshop about array handling. It is slightly outdated, but the information is still useful. If you have a more specific question, just ask.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Input value, variable grammar

Post by gfgtdf »

Sapient wrote: The easiest way to initialize a bunch of variables at the start of a scenario is probably with the [variables] tag.

Code: Select all

[variables]
 variable1,variable2,variable3=0,0,0
[/variables]
I reccomend not to do this, it is efectlveley undefined how this behaves if there are already varaibles from the previous scenario, in particular it might happen that this discards all variables from the previous scenario.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Input value, variable grammar

Post by Sapient »

gfgtdf wrote:
Sapient wrote: The easiest way to initialize a bunch of variables at the start of a scenario is probably with the [variables] tag.

Code: Select all

[variables]
 variable1,variable2,variable3=0,0,0
[/variables]
I reccomend not to do this, it is efectlveley undefined how this behaves if there are already varaibles from the previous scenario, in particular it might happen that this discards all variables from the previous scenario.
Wow that sounds like a great way to clear variables! Just kidding, that sounds horrible... surely a merge would be more useful?

Still, it should be valid for 1st scenario... if it's broken for 1st scenario that's definitely a bug.

Thanks for the tip.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Input value, variable grammar

Post by gfgtdf »

Sapient wrote: Still, it should be valid for 1st scenario...
Not sure, it might interfere with the variables creates by [options] https://wiki.wesnoth.org/OptionWML (i wonder why that page called OptionWML instead of OptionsWML ?). Didn't test that though.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Heindal
Posts: 1357
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Input value, variable grammar

Post by Heindal »

Hi Sapient and gfgtdf,

I will see if I can use variables, maybe in a test campaign. According the input idea that I had: I like to think out of the box - its a terrible curse.
I made several buttons which can influence a variable. I'm not quite sure if that is possible for a name (in javascript you can add text to a string variable with +=""), but I just wanted the player to quickly buy and sell a number of products. This is something you probably have seen on consoles or devices without keyboard.
example.png

Thanks

Heindal
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Post Reply