Using *rand with a text variable


#1

Is there a way to use *rand with a text variable and a number instead of two numbers?
*rand blah 1 "Variable"

(“Variable” is a variable that holds a number defined previously by the user using *input_number)

Thank you!


#2

Not sure what you want exactly but rand requires two numbers to defind what it is rolling such as 1 5 or 20 30. As far as using text var I have seen it in if only so far, of course I am not good with the updated code

*rand var 1 5
*if (var=5)
 *set text_var "something"
 *goto some_place
*if (rand=4)
 *set text_var "something_else"
 *goto some_place

#3

Alright, thanks.

It’s too bad, really; that’ll limit my program exponentially.

Edit: Never mind. That doesn’t make any sense.


#4

What exactly do you want to happen as there many ways to tackle a problem in CS and someone may have a better answer for you :smile:


#5

Alright, so.

That dice game I published a couple of days ago. I originally wanted for the player to be able to input a crazy number and watch it get multiplied and randomized by another number they entered.

The player inputs one number. It is the number of dice being rolled.

Then s/he/it inputs another number. It is the number of faces each die has.

Each die’s number is randomized by the number of sides, then added to form a sum dependent on the number of total dice.


However, I’ve found another solution. I’m just going to have a *choice between the most commonly used variants of dice that I found here https://en.wikipedia.org/wiki/Dice#Variants


#6

I’m pretty sure you can pass variables for the min and max values of rand, if that’s what you’re asking?


#7

Yes. How would I go about doing this?


#8

I believe

*Rand var 1 6

would generate a number between 1 and 6. You could use a gosub to roll that dice as many times as the user specifies. I have a dice mechanic that will generate creature stats based on the hit dice (sides) and the number of dice (determined by level).

So here is my code to generate a random amount of hit points for an enemy:

Level ${enemy_level} ${enemy_description} (${hit_dice_count}d${enemy_hit_dice_sides})

*label health_gen
*if hit_dice_count > 0
	*set hit_dice_result 0
	*rand hit_dice_result 1 enemy_hit_dice_sides
	*set enemy_health + hit_dice_result
	The roll for die ${hit_dice_count} is ${hit_dice_result}.
	*set hit_dice_count - 1
	*goto health_gen
The ${enemy_description}'s base health is ${enemy_hit_dice_sides}. The ${enemy_description}'s total health is ${enemy_health}. 

So this would read:

Level 3 Goblin (3d8)
The roll for die 3 is 6.
The roll for die 2 is 7.
The roll for die 1 is 5.
The goblin’s base health is 8. The Goblin’s total health is 26.

(That’s 8+6+7+5)


#9

Yeah. That’s pretty much what I ended up doing.

Your method looks like it could be more robust, though.


#10

After doing this for a while you learn some tricks to simplify long bits of code. :] Feel free to copy!