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.
Post Reply
ohhaykfrankk
Posts: 11
Joined: Sat Mar 09, 2019 2:18 am
Points: 10

Using Rand in a variable

Post by ohhaykfrankk »

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.
User avatar
DazaKiwi
Posts: 835
Joined: Thu Oct 21, 2010 10:05 am
Points: 71
Location: New Zealand

Re: Using Rand in a variable

Post by DazaKiwi »

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 77 times
The0didactus
Posts: 309
Joined: Sun Mar 30, 2014 9:20 pm
Points: 150

Re: Using Rand in a variable

Post by The0didactus »

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 844 times
ohhaykfrankk
Posts: 11
Joined: Sat Mar 09, 2019 2:18 am
Points: 10

Re: Using Rand in a variable

Post by ohhaykfrankk »

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?
saabie
Posts: 1024
Joined: Fri Aug 12, 2011 3:07 am
Points: 50
Location: Adelaide, South Australia

Re: Using Rand in a variable

Post by saabie »

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.
Post Reply