[engine] Functions
Moderator: Forum Moderators
Forum rules
Before posting a new idea, you must read the following:
Before posting a new idea, you must read the following:
[engine] Functions
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.
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.
Re: [engine] Functions
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."
Re: [engine] Functions
... and if I wish 1.5 multiplier?
Re: [engine] Functions
I hate to be rude but it is one of the most ugliest things I ever seen in DSLs.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.
Re: [engine] Functions
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.
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."
Re: [engine] Functions
Was syntax
discussed and rejected already?
Is there any chance some patch for this syntax will be accepted?
Sometimes I have some free time.
Code: Select all
gold="if(someside.gold>150, max(1.5*someside.gold, 100), 80)"
Is there any chance some patch for this syntax will be accepted?
Sometimes I have some free time.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: [engine] Functions
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]
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: [engine] Functions
Also, the following will work if you have stored the side information in container named "someside"
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.
Code: Select all
gold="$(if($someside.gold>150, max((15*$someside.gold)/10, 100), 80))"
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."
Re: [engine] Functions
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.
Re: [engine] Functions
Ok, that means Wesnoth 1.7.3 or greater. Thanks... showing my outdatedness.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.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
- thespaceinvader
- Retired Art Director
- Posts: 8414
- Joined: August 25th, 2007, 10:12 am
- Location: Oxford, UK
- Contact:
Re: [engine] Functions
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.
Back to work. Current projects: Catching up on commits. Picking Meridia back up. Sprite animations, many and varied.