[engine] Functions

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderator: Forum Moderators

Forum rules
Before posting a new idea, you must read the following:
Post Reply
sv75
Posts: 24
Joined: December 9th, 2008, 9:42 am

[engine] Functions

Post by sv75 »

If I get it right, WML lacks calculated functions.
How can I write something like this "enemy starting gold is minimum of 100 and player gold two times"?

Can I use LuaWML for it?

Sorry for my possible mistake.
Velensk
Multiplayer Contributor
Posts: 4002
Joined: January 24th, 2007, 12:56 am

Re: [engine] Functions

Post by Velensk »

Give the enemy 100 gold. Store the players side. Use the [gold] the &<stored_side_variable>.gold to the the enemies side twice.
"There are two kinds of old men in the world. The kind who didn't go to war and who say that they should have lived fast died young and left a handsome corpse and the old men who did go to war and who say that there is no such thing as a handsome corpse."
sv75
Posts: 24
Joined: December 9th, 2008, 9:42 am

Re: [engine] Functions

Post by sv75 »

... and if I wish 1.5 multiplier?
sv75
Posts: 24
Joined: December 9th, 2008, 9:42 am

Re: [engine] Functions

Post by sv75 »

Velensk wrote:Give the enemy 100 gold. Store the players side. Use the [gold] the &<stored_side_variable>.gold to the the enemies side twice.
I hate to be rude but it is one of the most ugliest things I ever seen in DSLs.
Velensk
Multiplayer Contributor
Posts: 4002
Joined: January 24th, 2007, 12:56 am

Re: [engine] Functions

Post by Velensk »

A little more complex. Create a variable. After you've stored the side set the variable to <stored_side_variable>.gold. Modify the variable by a 1.5 modifier (look at the wiki if you don't know how). Then use the [gold] tag to give them gold equal to the variable.

You could if you prefer modify the side rather than using the gold tag if it seems more elegant to you.
"There are two kinds of old men in the world. The kind who didn't go to war and who say that they should have lived fast died young and left a handsome corpse and the old men who did go to war and who say that there is no such thing as a handsome corpse."
sv75
Posts: 24
Joined: December 9th, 2008, 9:42 am

Re: [engine] Functions

Post by sv75 »

Was syntax

Code: Select all

gold="if(someside.gold>150, max(1.5*someside.gold, 100), 80)"
discussed and rejected already?
Is there any chance some patch for this syntax will be accepted?

Sometimes I have some free time.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: [engine] Functions

Post by Anonymissimus »

sv75 wrote: How can I write something like this "enemy starting gold is minimum of 100 and player gold two times"?

Code: Select all

[lua]
code=<< wesnoth.sides[2].gold = math.max(wesnoth.sides[1].gold * 2, 100) >>
[/lua]
in a prestart
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
sv75
Posts: 24
Joined: December 9th, 2008, 9:42 am

Re: [engine] Functions

Post by sv75 »

Great, thanks.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: [engine] Functions

Post by Sapient »

Also, the following will work if you have stored the side information in container named "someside"

Code: Select all

gold="$(if($someside.gold>150, max((15*$someside.gold)/10, 100), 80))"
Note: you cannot simply multiply by 1.5 because FormulaAI language does not yet support floating point numbers, AFAIK.

Also, there is a plan to make side information accessible via auto-stored variables. See the FutureWML page on the wiki for details.

Feel free to submit a patch.
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
Iris
Site Administrator
Posts: 6798
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: [engine] Functions

Post by Iris »

Formulas support fixed-point numbers since r37742. Judging by the output of F { 3 * 0.5 }, it seems to use 3 decimal figures.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: [engine] Functions

Post by Sapient »

shadowmaster wrote:Formulas support fixed-point numbers since r37742. Judging by the output of F { 3 * 0.5 }, it seems to use 3 decimal figures.
Ok, that means Wesnoth 1.7.3 or greater. Thanks... showing my outdatedness.
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
thespaceinvader
Retired Art Director
Posts: 8414
Joined: August 25th, 2007, 10:12 am
Location: Oxford, UK
Contact:

Re: [engine] Functions

Post by thespaceinvader »

It would be reasonably easy to do *1.5 even without decimals. *3, then /2. Easy ;)
http://thespaceinvader.co.uk | http://thespaceinvader.deviantart.com
Back to work. Current projects: Catching up on commits. Picking Meridia back up. Sprite animations, many and varied.
Post Reply