SexScripts : Displaying a random number - https://ss.deviatenow.com:443/viewtopic.php?f=4&t=305 Page 1 of 1

Displaying a random number

WorkUOut [ Sun Mar 24, 2013 3:47 pm ]

Hello everyone,

Apologies to present another basic question, but have struggled a bit to get the line from the main documentation to work in my script:

getRandom(max)
Returns a random number between 0 and max (excluded).
Example : if(getRandom(2) == 0) ...

I'd like to use this to assign a number like "apply X number of clothespegs...". In that case does this information get "plugged" into the text in "show" or somewhere else?

Thanks for any direction you can provide!

Re: Displaying a random number

doti [ Sun Mar 24, 2013 5:32 pm ]

No need to apology, it's a pleasure.
getRandom() will create, return a number. Then the symbol + is enough to group some things in order to create a character string. Two examples :
Code:
def number = getRandom(6) + 1
def fullString = "Put "+number+" clothespegs"
show(fullString)

Shorter :
Code:
show("Put "+(getRandom(6) + 1)+" clothespegs")

As you can see, there's sometimes a trick : using parenthesis to make sure + concatenate strings or add numbers.

Re: Displaying a random number

WorkUOut [ Mon Mar 25, 2013 1:49 am ]

Thanks for your help! Looking forward to publishing my first two scripts soon...

Re: Displaying a random number

LMW [ Sat Apr 06, 2013 12:12 pm ]

I've coded a quick shortcut here:

Code:
Random random = new Random()

def r = {
   min, max ->
   return random.nextInt((max+1)-min)+min
}

show("Put "+r(3,6)+" clothespegs on ya bits")

Gives you a random number between a minimum and a maximum. Useful for waiting random lengths of time, or giving yourself r(1,4)*6 strokes of the cane

LMW

Page 1 of 1 All times are UTC + 1 hour [ DST ]
https://ss.deviatenow.com:443/
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010, 2011