Changes to WML
Moderator: Forum Moderators
Changes to WML
I've just commited two changes to WML:
"victory_when_enemies_defeated" has been added. If "victory_when_enemies_defeated=no" is found in the scenario, then the level will not end when all enemy sides have been defeated. This allows you to create scenarios where an enemy side has no leader, or where there simply is no enemy side.
the [set_variable] tag has been modified to allow "random=...." The usage is as such.. // random generation works as follows:
some examples:
If you see a reason to in your campaigns, please use these and let me know if there are any issues. There shouldn't be, of course; but you never know.
"victory_when_enemies_defeated" has been added. If "victory_when_enemies_defeated=no" is found in the scenario, then the level will not end when all enemy sides have been defeated. This allows you to create scenarios where an enemy side has no leader, or where there simply is no enemy side.
the [set_variable] tag has been modified to allow "random=...." The usage is as such.. // random generation works as follows:
Code: Select all
random=<comma delimited list>
If the first element of the list looks like a number*, then we
assume that we are supposed to generate an integer in a specified
range, so the second element had better be a number, too. Otherwise,
the elements are treated as strings and one is randomly chosen from
the list.
* "looks like a number" means first char is a digit or "-".
Code: Select all
# choose from a list
[set_variable]
name=blahblah
random=one,two,three,four
[/set_variable]
# choose from another list
[set_variable]
name=blahblah
random=alpha,beta,gamma
[/set_variable]
# choose a number in a given range
[set_variable]
name=bluhbluh
random=-1,3
[/set_variable]
# choose a number in given range again
[set_variable]
name=bluhbluh
random=0,100
[/set_variable]
# effectively the same as using 'value=' instead of 'random='
[set_variable]
name=bluhbluh
random=9
[/set_variable]
# empty strings are legal
[set_variable]
name=bluhbluh
random=,sdfs,sfsdf,fsfdssfs,sdfsdfsfdsdfsdf,,
[/set_variable]
# weighted list if you want it to usually choose "no"
[set_variable]
name=wonkywonky
random=yes,no,no,no,no
[/set_variable]
If you see a reason to in your campaigns, please use these and let me know if there are any issues. There shouldn't be, of course; but you never know.
Re: Changes to WML
That's nice, and will be very useful!kmj wrote:If you see a reason to in your campaigns, please use these and let me know if there are any issues. There shouldn't be, of course; but you never know.
Just one thought: isn't there any unset_variable? Randomness will be of much use, but most of the time the variable should be temporary, otherwise savegames will soon be cluttered up with obsolete variables...
--
Cedric
Re: Changes to WML
the easiest fix would be to use the same variable over and over, whenever possible.. but that's a good point..cedric wrote:That's nice, and will be very useful!kmj wrote:If you see a reason to in your campaigns, please use these and let me know if there are any issues. There shouldn't be, of course; but you never know.
Just one thought: isn't there any unset_variable? Randomness will be of much use, but most of the time the variable should be temporary, otherwise savegames will soon be cluttered up with obsolete variables...
--
Cedric
Looks great!
One thing: I would suggest using a '-' notation for ranges of random numbers. i.e.
random=1,10
should mean 'picks 1 or 10 with equal probability'. Allow
random=1-10
to be expanded internally to
random=1,2,3,4,5,6,7,8,9,10
and thus mean 'picks a random number between 1 and 10'.
You could also have for instance
random=-20--10,0,10-20
to mean 'pick at random a number in the range -20 to -10, 0, or a number in the range 10-20, with all numbers having equal chance of being chosen'
Otherwise, all looks great
David
One thing: I would suggest using a '-' notation for ranges of random numbers. i.e.
random=1,10
should mean 'picks 1 or 10 with equal probability'. Allow
random=1-10
to be expanded internally to
random=1,2,3,4,5,6,7,8,9,10
and thus mean 'picks a random number between 1 and 10'.
You could also have for instance
random=-20--10,0,10-20
to mean 'pick at random a number in the range -20 to -10, 0, or a number in the range 10-20, with all numbers having equal chance of being chosen'
Otherwise, all looks great
David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming
-
- Posts: 826
- Joined: January 21st, 2004, 1:10 am
- Location: San Diego, CA
The following code works...Christophe33 wrote:Will the random funcction allows to generate a random coordinate (within some factor) for the plcement of an object....like the sceptre of fire?
It really sounds great.
Code: Select all
[event]
name=start
[set_variable]
name=xpos
random=5,15
[/set_variable]
[set_variable]
name=ypos
random=1,6
[/set_variable]
[unit]
description=Rodalfed
type=Elder Mage
side=1
x=$xpos
y=$ypos
[/unit]
[/event]
...of course, with random placement you'll have to be careful you don't ask it to place on a wall or some such thing.
I agree, reseeding should be implemented. Although I must admit that my programming knowledge is limited, all of my Computer Science teachers stressed remembering to reseed when talking about using a random function.Slainte wrote:Random will come very handy... and I think reseeding it is about mandatory...
Anyways, these are great additions to WML and I know the scenario developers will be very pleased.
-Gafgarion
"Language is the source of misunderstandings." -Antoine de Saint-ExupéryElvish Pillager wrote:Normal Trolls use clubs, not ostriches.
1-10 considered harmful...
I agree with dave that having a notation for intervals would be helpful, but I think "-" imposes an unnecessary limitation: what about an interval from -20 to -10?
Therefore I propose either using ".." as infix as in
or (I do not know if this is possible) even " to " as in
Therefore I propose either using ".." as infix as in
Code: Select all
random=1..10
Code: Select all
random=1 to 10
This is true, but given that locations are locations and these are numeric values, I'd rather have the inconsistency than use "-10--1"... I've updated the code in CVS, as specified.. Numeric and string values can be intermingled, as long as no string values contain "..".cedric wrote:Right, more readable, albeit not consistent with the ranges notation currently used (for locations)...kmj wrote:Yeah, I think using -1..-10 is more readable than -1--10. I should have that committed in the next couple of days.
--
Cedric
Realistically, I think that the frequency of use of negative numbers as random numbers would be rare. I very very rarely generate random negative numbers in programming.
[quote='Slainte']
One thing i am not sure... (still learning my way 'round wml and scenarios... is there a way to pass variables from scenario to scenario? Are those variables created in the scenario persistent?
[/quote]
Yes, variables created are persistent.
See for example Muff Malal's Peninsula, where a variable is created to see if Moremirmu is found and survives the battle, then that variable is checked in Valley of Death to see if Moremirmu should come and help the player.
Variables wouldn't be very useful if they weren't persistent.
David
[quote='Slainte']
One thing i am not sure... (still learning my way 'round wml and scenarios... is there a way to pass variables from scenario to scenario? Are those variables created in the scenario persistent?
[/quote]
Yes, variables created are persistent.
See for example Muff Malal's Peninsula, where a variable is created to see if Moremirmu is found and survives the battle, then that variable is checked in Valley of Death to see if Moremirmu should come and help the player.
Variables wouldn't be very useful if they weren't persistent.
David
“At Gambling, the deadly sin is to mistake bad play for bad luck.” -- Ian Fleming