ADRIFT Forum


The place to discuss the ADRIFT Interactive Fiction toolkit

Using Rand in a variable

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.

Using Rand in a variable

Postby ohhaykfrankk » Wed Mar 13, 2019 10:32 pm

I literally have no idea what I'm doing wrong.

How do I set a variable to a random number? I've tried all the works. I need it to tell the player the number, So e.g. Variable "Gambling" set to a random number between 19 and 2641, will say "You have won %gambling% dollars" But it keeps outputting "rand(19, 2641)"

And while I'm here, I will then need some sort of task (I don't know how to add?) to have the random amount of money be added to my money. (Another variable).

Thank you all. I wish there was more to the wiki page so I didn't have to ask so many questions.
ohhaykfrankk
 
Posts: 11
Joined: Sat Mar 09, 2019 2:18 am

Re: Using Rand in a variable

Postby DazaKiwi » Wed Mar 13, 2019 10:44 pm

I suspect you are typing out "rand(19, 2641)" in the output area, you need to use an expression if you want to do that or to store the value in a string variable use an action to set a variable to rand(19, 2641) especially if you want to track these winnings later.
Attachments
How to use Rand_v1.taf
I threw together a quick little demo for both methods
(14.84 KiB) Downloaded 21 times
User avatar
DazaKiwi
 
Posts: 627
Joined: Thu Oct 21, 2010 9:05 am
Location: New Zealand
Points: 16

Re: Using Rand in a variable

Postby The0didactus » Wed Mar 13, 2019 10:48 pm

ohhaykfrankk wrote:I literally have no idea what I'm doing wrong.

How do I set a variable to a random number? I've tried all the works. I need it to tell the player the number, So e.g. Variable "Gambling" set to a random number between 19 and 2641, will say "You have won %gambling% dollars" But it keeps outputting "rand(19, 2641)"

And while I'm here, I will then need some sort of task (I don't know how to add?) to have the random amount of money be added to my money. (Another variable).

Thank you all. I wish there was more to the wiki page so I didn't have to ask so many questions.



Just so there's no ambiguity, here's a screenshot of me doing what you're trying to do, I think. I do this kind of thing all the time.
Here, we have a variable: "CargoSilverPieces" which is the player's "wallet"
and I'm telling adrift to increase that variable by an amount between 2 and 4.

You can use the same command to "modify" the random number by another variable. So I can type RAND (2, 4)+%gamblingbonus% to add a number to my randomly generated number. This is a good command for RPG style "rolls".
If RAND (1, 10)+%strength% is greater than 10, success
If RAND (1, 10)+%strength% is less than 10, failure.
Attachments
Capture.PNG
Capture.PNG (47.04 KiB) Viewed 380 times
The0didactus
 
Posts: 213
Joined: Sun Mar 30, 2014 8:20 pm
Points: 30

Re: Using Rand in a variable

Postby ohhaykfrankk » Wed Mar 13, 2019 11:21 pm

DazaKiwi, that works! I was trying to use a different task to change it instead of just putting it with the task itself. Geez.

The0didactus, I don't know anything about rolls lol. It seems like what you're saying would work to add it to my money, but then how do I have the money variable change?

So, using DazaKiwi's fix, it said "You have earned 1818 dollars". My money is initially at 1000, so how do I make it add the 1818 to my money? Or can I not because it's random?
ohhaykfrankk
 
Posts: 11
Joined: Sat Mar 09, 2019 2:18 am

Re: Using Rand in a variable

Postby saabie » Wed Mar 13, 2019 11:51 pm

In DazaKiwi's example you can add a second action "[Increase] [MyMoney] by [%GambleRoll%]"
Then in the message you can use both variables:

You gamble on a roll of some dice and win...$%GambleRoll%. You now have a total of $%MyMoney%

Note that the task must have "Display completion message [after] executing actions" set on the Advanced page.
saabie
 
Posts: 973
Joined: Fri Aug 12, 2011 2:07 am
Location: Adelaide, South Australia
Points: 25


Return to ADRIFT 5.0

Who is online

Users browsing this forum: No registered users and 4 guests

cron