ADRIFT Forum


The place to discuss the ADRIFT Interactive Fiction toolkit

keeping count of a random variable's results

This forum is the place to learn about and discuss ADRIFT 5. Feel free to mention any bugs you find here, but please also add these to the Bugs & Enhancements list.

Please also refer to the ADRIFT 5 Wiki for more information.

keeping count of a random variable's results

Postby moskys » Mon Mar 20, 2017 10:37 am

Hi!

I'm pretty sure someone has already asked something like that before but I want the PC to execute a task several times, getting completely random results, and then trigger different paths depending on that results. Let's say I want the player to roll a dice 3 times: if he got a >3 result at least once, he earns a point in another number variable which will be checked later as a restriction for future tasks. So I've created an array variable 'dice' with the possible results (1, 2, 3, 4, 5, 6) and then created a specific 'roll dice' task in which you see the text: 'You roll the dice and get a %dice[RAND(1,6)]%'.

But now I can't figure out how to keep count of that result. Thanks in advance for your help
moskys
 
Posts: 4
Joined: Mon Jan 23, 2017 9:05 am

Re: keeping count of a random variable's results

Postby ice_wanted » Mon Mar 20, 2017 10:25 pm

Put the result of %dice[rand(1,6)]% in a variable?
ice_wanted
 
Posts: 79
Joined: Thu Aug 22, 2013 1:12 am

Re: keeping count of a random variable's results

Postby ralphmerridew » Tue Mar 21, 2017 2:11 am

How often will you be doing stuff like that?

The direct way would be:
Set die1 to %RAND(1,6)%
Set die2 to %RAND(1,6)%
Set die3 to %RAND(1,6)%
Set numhigh to %IF(%die1% > 3, 1, 0) + IF(%die2% > 3, 1, 0) + IF(%die3% > 3, 1, 0)%
Set pointgain to %IF(%numhigh% > 0, 1, 0)%
Increase othervariable by %pointgain%.

(It's possible to combine some of those into a single expression.)
Bloodhounds can make you laugh and cuss in the same breath. They are endearing, faithful, and can sling drool ten feet in any direction. -- Virginia Lanier
User avatar
ralphmerridew
 
Posts: 2489
Joined: Fri Dec 13, 2002 11:56 pm
Location: Missouri

Re: keeping count of a random variable's results

Postby moskys » Tue Mar 21, 2017 11:20 am

ralphmerridew wrote:How often will you be doing stuff like that?

The direct way would be:
Set die1 to %RAND(1,6)%
Set die2 to %RAND(1,6)%
Set die3 to %RAND(1,6)%
Set numhigh to %IF(%die1% > 3, 1, 0) + IF(%die2% > 3, 1, 0) + IF(%die3% > 3, 1, 0)%
Set pointgain to %IF(%numhigh% > 0, 1, 0)%
Increase othervariable by %pointgain%.

(It's possible to combine some of those into a single expression.)


Thanks but I don't get it, this is my first 'programming' experience with functions and expressions. The 'dice' variables are text Arrays, so when I try to set them to %RAND(1,6)% there's a blank box to introduce a value or another variable before the = and I don't really know what to do. That's what I see:

Set - dice1 - [(blank)] = RAND(1,6) -- and I cannot even press OK if I don't introduce an 'own value' or select another variable in that blank text box :blush:

___
ice_wanted wrote:Put the result of %dice[rand(1,6)]% in a variable?

Yeah, but I don't know how to do the math. My idea was: you roll the dice, you get (and see) a random result, this result is stored somewhere. But I guess it's not as easy as it seemed at first - for me at least :)
moskys
 
Posts: 4
Joined: Mon Jan 23, 2017 9:05 am

Re: keeping count of a random variable's results

Postby moskys » Tue Mar 21, 2017 12:31 pm

OK, I think I've just come up with a proper way to do it. My problem was using 'dice' variables as text arrays instead of just number. Also, I think showing that '%dice[RAND(1,6)]%' as a text output in my 'roll dice' task was a mistake too. I guess it could be made just with functions and expressions but here's the solution I've found:

So now I have 4 number variables:
dice
throwdice
checkdice
countdice

The 'roll dice' task sets a random result (1,6) for 'throwdice': set throwdice = RAND(1,6)
Then it runs an intermediate system task (a primitive but effective method) to check that random result: set 'checkdice' = if (%throwdice% < 3, 0, 1)
From there you have another couple of excluding systems task:
->'dice fail' is restricted to checkdice=0, and it shows the PC a random result: '%dice[RAND(1,3)]%
->'dice ok' is restricted to checkdice>0, increases 'countdice' by 1 and shows the PC a random result: %dice[RAND(4,6)]%
And both of them set 'throwdice' and 'checkdice' variables to 0 again for the next turn.

So I've actually split a random event into two random events: in the first I just check a kind of 50-50% coin flip (which remains invisibly for the PC) and then after the second the PC 'sees' an actual dice puntuation and some text related to it. I guess I could bypass the first step (the roll dice task), but this system allows me to introduce different probabilities in different scenarios just by adjusting the parameters of that random event, if needed (like changing the required puntuation to win or having a more-than-six-faced roll). I know i'ts not very funny to have random elements in IF but it could add some spice for secondary puzzles.

Thanks a lot for your advices, you made me think twice and it helped. Hope this helps other people too
moskys
 
Posts: 4
Joined: Mon Jan 23, 2017 9:05 am

Re: keeping count of a random variable's results

Postby ralphmerridew » Tue Mar 21, 2017 10:33 pm

Why are you generating a new random number? Why not just show %dice[throwdice]%?

Also, you could get the same chance of success by rolling a single eight-sided die, where throwing a 1 fails and anything else succeeds.
Bloodhounds can make you laugh and cuss in the same breath. They are endearing, faithful, and can sling drool ten feet in any direction. -- Virginia Lanier
User avatar
ralphmerridew
 
Posts: 2489
Joined: Fri Dec 13, 2002 11:56 pm
Location: Missouri

Re: keeping count of a random variable's results

Postby moskys » Wed Mar 22, 2017 11:29 am

ralphmerridew wrote:Why are you generating a new random number? Why not just show %dice[throwdice]%?



Yeah, I saw that too after posting my initial solution :roll:
moskys
 
Posts: 4
Joined: Mon Jan 23, 2017 9:05 am


Return to ADRIFT 5.0

Who is online

Users browsing this forum: No registered users and 3 guests

cron