Question with renpy.random.randint

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Hoseigndie
Regular
Posts: 31
Joined: Sat Jun 02, 2018 3:00 pm
Contact:

Question with renpy.random.randint

#1 Post by Hoseigndie »

Hello all,

I have a question with "renpy.random.randint".
In my game, I have this code once a day :

$ randomnum = renpy.random.randint(1,4)

This code make 4 differentes action in the day.

My question is, how to make a random choice without the last one selected ?

Exemple, I have randomnum==2, the next morning the choice will be made without the 2. Only 1, 3 and 4.

I hope you understand my question ... Sorry for my english ;)

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Question with renpy.random.randint

#2 Post by Per K Grok »

Hoseigndie wrote: Fri Dec 21, 2018 11:28 am Hello all,

I have a question with "renpy.random.randint".
In my game, I have this code once a day :

$ randomnum = renpy.random.randint(1,4)

This code make 4 differentes action in the day.

My question is, how to make a random choice without the last one selected ?

Exemple, I have randomnum==2, the next morning the choice will be made without the 2. Only 1, 3 and 4.

I hope you understand my question ... Sorry for my english ;)
You could do it like this.

You make a list with you 4 options.

$ action_list=[1,2,3,4]

You then use randint to chose which position in the list to use. Remember that the first position is '0' not '1'.

You pick the number at that position and remove that member from the list.

You repeat this day 2, now, to start off with, only with three members in the list i.e [1,3,4], since you removed one position day 1.

Make sure you are adjusting the numbers put into radint so you only can look at positions that are filled in the list.

randint(0,3)
randint(0,2)
randint(0,1)

Day four you of course only have one member left to chose from.

If you are unfamiliar with lists read up on 'python list'. It's a useful tool.

Hoseigndie
Regular
Posts: 31
Joined: Sat Jun 02, 2018 3:00 pm
Contact:

Re: Question with renpy.random.randint

#3 Post by Hoseigndie »

I am not comfortable with the lists.
But Can I make a renpy.random.randint without a number ?
For exemple, I can make this way :

if randomnum==2:
renpy.random.choice(1,4) <=== can I make this code without the 2 ???

Sorry but my level in Python is not high :(

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Question with renpy.random.randint

#4 Post by Per K Grok »

Hoseigndie wrote: Fri Dec 21, 2018 1:03 pm I am not comfortable with the lists.
But Can I make a renpy.random.randint without a number ?
For exemple, I can make this way :

if randomnum==2:
renpy.random.choice(1,4) <=== can I make this code without the 2 ???

Sorry but my level in Python is not high :(
I don't think there is any such out of the box function.

Another way could be to use a while loop that will keep on looping until the random function picks a number that has not been picked yet.

Hacky and not really easier to do than the list method.

I still think it is worth the effort to get a bit more familiar with lists.

Hoseigndie
Regular
Posts: 31
Joined: Sat Jun 02, 2018 3:00 pm
Contact:

Re: Question with renpy.random.randint

#5 Post by Hoseigndie »

Thx for your response ...
I will try to learn this option ;)

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]