Create account / Log in

Random Number generation

Talk about module design ideas and techniques.

Moderators: uckelman, Tim M

Random Number generation

Postby keefersa » September 11th, 2020, 9:13 pm

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.
keefersa
 
Posts: 15
Joined: July 5th, 2020, 11:11 am

Re: Random Number generation

Postby marktb1961 » September 11th, 2020, 10:06 pm

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
Platform used:
Vassal 3.4.10
MacOS Big Sur
iMac (27", mid-2020)
User avatar
marktb1961
 
Posts: 331
Joined: October 4th, 2018, 2:36 pm
Location: Liverpool, England

Re: Random Number generation

Postby keefersa » September 14th, 2020, 8:06 pm

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
keefersa
 
Posts: 15
Joined: July 5th, 2020, 11:11 am

Re: Random Number generation

Postby jrwatts » September 14th, 2020, 8:24 pm

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.)
jrwatts
 
Posts: 125
Joined: April 29th, 2020, 10:30 pm

Re: Random Number generation

Postby keefersa » September 16th, 2020, 9:21 pm

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?
keefersa
 
Posts: 15
Joined: July 5th, 2020, 11:11 am

Re: Random Number generation

Postby jrwatts » September 16th, 2020, 9:56 pm

No sorry, Random() and isRandom() are new to 3.4.0.
jrwatts
 
Posts: 125
Joined: April 29th, 2020, 10:30 pm


Return to Module Design

Who is online

Users browsing this forum: No registered users and 5 guests

cron