Page 1 of 1

Random Number generation

PostPosted: September 11th, 2020, 9:13 pm
by keefersa
Hello,

another question from a beginner. I am trying to generate random numbers to be used with generating revolts in a game and am in need of a bit of advice on constructing an expression.
I have set up a test counter, created a Calculated Property named Revolt, with the expression If(GetProperty(d10_result)>=4,Fred,Barney
along with a Report Action property just to find the result of Revolt.
The module also has a d10 die.

I got the message "Bad Data in Module: Expression evaluation error Test Counter - Calculated Property[Revolt]={If(GetProperty(d10-result)>=4,Fred,Barney)}, Error=Command not found: GetProperty( int)

Do I need to do something else to generate a random numeric result before using it?

Thanks for any advice.

Re: Random Number generation

PostPosted: September 11th, 2020, 10:06 pm
by marktb1961
I think that the actual error "Error=Command not found: GetProperty( int)" is caused because the parameter for GetProperty is a String, so you need to put quote marks around "d10_result". Also in your post you have the reference d10-result (ie. minus not underscore) which would cause the error.

However, you don't need to use GetProperty because you can use the Property name directly. Try this expression in your Calculated Property:

d10_result >=4 ? "Fred" : "Barney"

I've assumed that Fred and Barney are literal strings, hence the quotes around them. Omit the quotes if they are also Properties.

The latest version of Vassal makes it easier to access the Random number generator. See the v3.4 Release Notes and the Expression Builder in v.3.4.0 onwards for more information.

Mark

Re: Random Number generation

PostPosted: September 14th, 2020, 8:06 pm
by keefersa
Thanks Mark,

I went with your suggestion for the calculated property without the GetProperty. This works fine now in terms of getting a random result, although once I've run it, the results never change if I run it again. Do I need to somehow reset values to get a new die roll or is this something I could incorporate into the calculated property?

Scott

Re: Random Number generation

PostPosted: September 14th, 2020, 8:24 pm
by jrwatts
If you use "Random(10) >= 4" in your calculated property, you'll get a new random number between 1 and 10 every time the property is checked. ("isRandom(70)" would be functionally the same, returning true 70% of the time.)

Re: Random Number generation

PostPosted: September 16th, 2020, 9:21 pm
by keefersa
Thanks, I'll give this a try. I am using an older version of VASSAL 3.2.17 as 3.3.2 was slow to load a new game, making it harder to check out whether changes were working. Do these functions exist in VASSAL 3.2.17?

Re: Random Number generation

PostPosted: September 16th, 2020, 9:56 pm
by jrwatts
No sorry, Random() and isRandom() are new to 3.4.0.