Renpy

noping123

Well-Known Member
Game Developer
Jun 24, 2021
1,420
2,268
The short answer is, you need to code them in.

The long answer is more complex, and really depends on what it is you actually want to do. Without knowing more specifics, or just speaking in general terms, you'd very likely need to learn python code to add minigames, and then write the code yourself. (Or find code someone else has written, then adapt it).
 

mad8

Newbie
Jun 24, 2019
35
51
The short answer is, you need to code them in.

The long answer is more complex, and really depends on what it is you actually want to do. Without knowing more specifics, or just speaking in general terms, you'd very likely need to learn python code to add minigames, and then write the code yourself. (Or find code someone else has written, then adapt it).
I already made mini games.
But i dont know how to add and sync in renpy.
Like winning game add money
and losing game remain same.
 

noping123

Well-Known Member
Game Developer
Jun 24, 2021
1,420
2,268
If you provide your code, I can probably help. Without that, it's hard to figure out what's working and what's not, but if you do, I can take a look and figure out whats wrong
 

mad8

Newbie
Jun 24, 2019
35
51
#The different symbols are named "slot1.png", "slot2.png" and so on. Replace the images with your own if you want.
# The images should be 136x136 pixels.

# Change how often each symbol will show. (Must be a total of 100)
init python:
slot_1_value = 5
slot_2_value = 10
slot_3_value = 15
slot_4_value = 20
slot_5_value = 20
slot_6_value = 30

# Change starting amount of coins and standard bet size.
init python:
coins = 100
bet = 1
win = 0

#The following decides the animation for rotating the slot machine. The number defines the speed of the rotation.
image left_slot:
"slot1.png"
.1
"slot2.png"
.1
"slot3.png"
.1
"slot4.png"
.1
"slot5.png"
.1
"slot6.png"
.1
repeat

image center_slot:
"slot2.png"
.1
"slot4.png"
.1
"slot6.png"
.1
"slot1.png"
.1
"slot3.png"
.1
"slot5.png"
.1
repeat

image right_slot:
"slot6.png"
.1
"slot2.png"
.1
"slot5.png"
.1
"slot1.png"
.1
"slot4.png"
.1
"slot3.png"
.1
repeat

# This is the screen for rotating the three slots. Slotmachine.png is the background. The rest are buttons and images placed on the background image.
screen play():
modal True
imagebutton:
idle "slotmachine.png"
xalign 0.5
yalign 0.5
imagebutton:
idle "left_slot"
xalign 0.287
yalign 0.45
imagebutton:
idle "center_slot"
xalign 0.42
yalign 0.45
imagebutton:
idle "right_slot"
xalign 0.55
yalign 0.45
imagebutton:
idle "play.png"
xalign 0.74
yalign 0.415
imagebutton:
idle "stop.png"
hover "stop_yes.png"
xalign 0.66
yalign 0.415
action Hide ("play"), Show ("wincheck")
imagebutton:
idle "up_arrow_grey.png"
xalign 0.7
yalign 0.53
imagebutton:
idle "down_arrow_grey.png"
xalign 0.7
yalign 0.64
vbox:
textbutton "{size=28}{color=#e8ba13}BET [bet]{/color}{/size}"
xalign 0.29
yalign 0.62
vbox:
textbutton "{size=28}{color=#e8ba13}COINS [coins]{/color}{/size}"
xalign 0.42
yalign 0.62

# This is the screen that shows when you stop the spinning slots.
# Change the amount of coins won by changing the multiplier.

screen wincheck():
$ slot_1_win = bet * 250
$ slot_2_win = bet * 50
$ slot_3_win = bet * 33
$ slot_4_win = bet * 25
$ slot_5_win = bet * 25
$ slot_6_win = bet * 15

# Calculations to determine which symbol should be shown.

$ leftrandom = renpy.random.randint(1,100)
$ centerrandom = renpy.random.randint(1,100)
$ rightrandom = renpy.random.randint(1,100)

# The following calculations determine if you have a winning combination.

if leftrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value) and centerrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value) and rightrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
$ coins += slot_6_win
if leftrandom <= slot_1_value and centerrandom <= slot_1_value and rightrandom <= slot_1_value:
$ coins += slot_1_win
if leftrandom > slot_1_value and leftrandom <= (slot_1_value + slot_2_value) and centerrandom > slot_1_value and centerrandom <= (slot_1_value + slot_2_value) and rightrandom > slot_1_value and rightrandom <= (slot_1_value + slot_2_value):
$ coins += slot_2_win
if leftrandom > (slot_1_value + slot_2_value) and leftrandom <= (slot_1_value + slot_2_value + slot_3_value) and centerrandom > (slot_1_value + slot_2_value) and centerrandom <= (slot_1_value + slot_2_value + slot_3_value) and rightrandom > (slot_1_value + slot_2_value) and rightrandom <= (slot_1_value + slot_2_value + slot_3_value):
$ coins += slot_3_win
if leftrandom > (slot_1_value + slot_2_value + slot_3_value) and leftrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and centerrandom > (slot_1_value + slot_2_value + slot_3_value) and centerrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and rightrandom > (slot_1_value + slot_2_value + slot_3_value) and rightrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value):
$ coins += slot_4_win
if leftrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and leftrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value) and centerrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and centerrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value) and rightrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and rightrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
$ coins += slot_5_win

# Determining which symbol should be shown where.
# Showing buttons on top of the background.
modal True
imagebutton:
idle "slotmachine.png"
xalign 0.5
yalign 0.5
if leftrandom <= slot_1_value:
imagebutton:
idle "slot1.png"
xalign 0.287
yalign 0.45
if leftrandom > slot_1_value and leftrandom <= (slot_1_value + slot_2_value):
imagebutton:
idle "slot2.png"
xalign 0.287
yalign 0.45
if leftrandom > (slot_1_value + slot_2_value) and leftrandom <= (slot_1_value + slot_2_value + slot_3_value):
imagebutton:
idle "slot3.png"
xalign 0.287
yalign 0.45
if leftrandom > (slot_1_value + slot_2_value + slot_3_value) and leftrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value):
imagebutton:
idle "slot4.png"
xalign 0.287
yalign 0.45
if leftrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and leftrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
imagebutton:
idle "slot5.png"
xalign 0.287
yalign 0.45
if leftrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
imagebutton:
idle "slot6.png"
xalign 0.287
yalign 0.45
if centerrandom <= slot_1_value:
imagebutton:
idle "slot1.png"
xalign 0.42
yalign 0.45
if centerrandom > slot_1_value and centerrandom <= (slot_1_value + slot_2_value):
imagebutton:
idle "slot2.png"
xalign 0.42
yalign 0.45
if centerrandom > (slot_1_value + slot_2_value) and centerrandom <= (slot_1_value + slot_2_value + slot_3_value):
imagebutton:
idle "slot3.png"
xalign 0.42
yalign 0.45
if centerrandom > (slot_1_value + slot_2_value + slot_3_value) and centerrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value):
imagebutton:
idle "slot4.png"
xalign 0.42
yalign 0.45
if centerrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and centerrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
imagebutton:
idle "slot5.png"
xalign 0.42
yalign 0.45
if centerrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
imagebutton:
idle "slot6.png"
xalign 0.42
yalign 0.45
if rightrandom <= slot_1_value:
imagebutton:
idle "slot1.png"
xalign 0.55
yalign 0.45
if rightrandom > slot_1_value and rightrandom <= (slot_1_value + slot_2_value):
imagebutton:
idle "slot2.png"
xalign 0.55
yalign 0.45
if rightrandom > (slot_1_value + slot_2_value) and rightrandom <= (slot_1_value + slot_2_value + slot_3_value):
imagebutton:
idle "slot3.png"
xalign 0.55
yalign 0.45
if rightrandom > (slot_1_value + slot_2_value + slot_3_value) and rightrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value):
imagebutton:
idle "slot4.png"
xalign 0.55
yalign 0.45
if rightrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and rightrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
imagebutton:
idle "slot5.png"
xalign 0.55
yalign 0.45
if rightrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
imagebutton:
idle "slot6.png"
xalign 0.55
yalign 0.45
imagebutton:
idle "play.png"
hover "play_yes.png"
xalign 0.74
yalign 0.415
action If (coins > bet, true=[ Hide ("wincheck"), Show ("play"), SetVariable("coins", coins-bet)], false=None)
imagebutton:
idle "stop.png"
xalign 0.66
yalign 0.415
imagebutton:
idle "up_arrow_grey.png"
hover "up_arrow_yellow.png"
xalign 0.7
yalign 0.53
action If (bet <=9, true=[ SetVariable("bet", bet+1), SetVariable("coins", coins + win), Hide ("wincheck"), Show ("slotstart")], false=None)
imagebutton:
idle "down_arrow_grey.png"
hover "down_arrow_yellow.png"
xalign 0.7
yalign 0.64
action If (bet >1, true=[ SetVariable("bet", bet-1), SetVariable("coins", coins + win), Hide ("wincheck"), Show ("slotstart")], false=None)
vbox:
textbutton "{size=28}{color=#e8ba13}BET [bet]{/color}{/size}"
xalign 0.29
yalign 0.62
vbox:
textbutton "{size=28}{color=#e8ba13}COINS [coins]{/color}{/size}"
xalign 0.42
yalign 0.62

# Showing amount of money won in the last spin.
if leftrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value) and centerrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value) and rightrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
vbox:
textbutton "{size=28}{color=#e8ba13}WIN [slot_6_win]{/color}{/size}"
xalign 0.545
yalign 0.62
if leftrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and leftrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value) and centerrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and centerrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value) and rightrandom > (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and rightrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value + slot_5_value):
vbox:
textbutton "{size=28}{color=#e8ba13}WIN [slot_5_win]{/color}{/size}"
xalign 0.545
yalign 0.62
if leftrandom > (slot_1_value + slot_2_value + slot_3_value) and leftrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and centerrandom > (slot_1_value + slot_2_value + slot_3_value) and centerrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value) and rightrandom > (slot_1_value + slot_2_value + slot_3_value) and rightrandom <= (slot_1_value + slot_2_value + slot_3_value + slot_4_value):
vbox:
textbutton "{size=28}{color=#e8ba13}WIN [slot_4_win]{/color}{/size}"
xalign 0.545
yalign 0.62
if leftrandom > (slot_1_value + slot_2_value) and leftrandom <= (slot_1_value + slot_2_value + slot_3_value) and centerrandom > (slot_1_value + slot_2_value) and centerrandom <= (slot_1_value + slot_2_value + slot_3_value) and rightrandom > (slot_1_value + slot_2_value) and rightrandom <= (slot_1_value + slot_2_value + slot_3_value):
vbox:
textbutton "{size=28}{color=#e8ba13}WIN [slot_3_win]{/color}{/size}"
xalign 0.545
yalign 0.62
if leftrandom > slot_1_value and leftrandom <= (slot_1_value + slot_2_value) and centerrandom > slot_1_value and centerrandom <= (slot_1_value + slot_2_value) and rightrandom > slot_1_value and rightrandom <= (slot_1_value + slot_2_value):
vbox:
textbutton "{size=28}{color=#e8ba13}WIN [slot_2_win]{/color}{/size}"
xalign 0.545
yalign 0.62
if leftrandom <= slot_1_value and centerrandom <= slot_1_value and rightrandom <= slot_1_value:
vbox:
textbutton "{size=28}{color=#e8ba13}WIN [slot_1_win]{/color}{/size}"
xalign 0.545
yalign 0.62


#This is the screen shown at start or when you change bet size
screen slotstart():
modal True
imagebutton:
idle "slotmachine.png"
xalign 0.5
yalign 0.5
imagebutton:
idle "mime.png"
xalign 0.287
yalign 0.45
imagebutton:
idle "mime.png"
xalign 0.42
yalign 0.45
imagebutton:
idle "mime.png"
xalign 0.55
yalign 0.45
imagebutton:
idle "play.png"
hover "play_yes"
xalign 0.74
yalign 0.415
action If (coins >= bet, true=[ Hide ("slotstart"), Show ("play"), SetVariable("coins", coins-bet)], false=None)
imagebutton:
idle "stop.png"
xalign 0.66
yalign 0.415
imagebutton:
idle "up_arrow_grey.png"
hover "up_arrow_yellow.png"
xalign 0.7
yalign 0.53
action If (bet <=9, true=[ SetVariable("bet", bet+1)], false=None)
imagebutton:
idle "down_arrow_grey.png"
hover "down_arrow_yellow.png"
xalign 0.7
yalign 0.64
action If (bet >1, true=[ SetVariable("bet", bet-1)], false=None)
vbox:
textbutton "{size=28}{color=#e8ba13}BET [bet]{/color}{/size}"
xalign 0.29
yalign 0.62
vbox:
textbutton "{size=28}{color=#e8ba13}MONEY [coins]{/color}{/size}"
xalign 0.42
yalign 0.62

# This is where the game starts
label start:
scene bg winter1
with Dissolve(0.5)
show layla_happy at left
with moveinleft
"This is a slot machine from Mime Media AS. Enjoy!"

# Call screen must be used to start the slot machine minigame
call screen slotstart

# There is currently no imagebutton added to exit the slot machine. You can however exit by going to the main menu (escape).
return
 

noping123

Well-Known Member
Game Developer
Jun 24, 2021
1,420
2,268
The ones ive made so far wouldn't really help since it's so different. I'll give a shot at figuring out what you want.

If I understand correctly, you want to add money within the main game (outside the slot machine) when you win, but do nothing if you lose? Correct me if im misunderstanding. That can be achieved a few different ways depending on your goal. For example

Code:
#you assign money value, in the main game

$ money = 100

#after you exit the slot machine, you add the coin value to the money

$ money += coins

#now you can do whatever with the money

"You have [money]"

That'd just add your total coin value to your money.

If instead you wanted to only add money if say, you finished with more than 100 coins (the starting value), or more than 150, or whatever then you'd just

Code:
$money = 100

if (coins >150):
    $ money += coins

or if you want to add a specific amount of money

Code:
$ money = 100

if (coins>150):
    $ money += 5
    
"You have [money]"
If you were looking to make the slot machine a 1 time thing, then you really wouldn't have to worry about it much after that.
If it was replayable, you'd just want to make sure you reset the value of coins either every time you entered the slot or after you exit, after doing the money adjustment. for example:

Code:
$money = 100

if (coins>150)
    $ money += 5

$coins = 100
'

And if you wanted to pay for the slot, you could subtract money every time you started it, or manipulate it any other way you'd like.

This is what I added (I also added an exit button in the slot machine, that jumped to the label i created)

Code:
    $ money = 100

    call screen slotstart

    label newlabel:

        scene bgwinter1

        if (coins > 150):
            $ money += 5
        elif (coins < 100):
            $ money -= 5
        $ coins = 100
        "You have [money]"

    call screen slotstart
Every time I exited with less than 100 coins, I lost 5 money, everytime I exited with more, I won 5 money, if I exited with 100-150, nothing changed, and it just repeated entering the slot machine over and over. Obviously you'd prefer something like an imagebutton to click to enter the slot machine, but this was just a quick and dirty example.

I'm not sure if that's what you were asking or not, if not lmk and I'll see what I can do.
 

mad8

Newbie
Jun 24, 2019
35
51
The ones ive made so far wouldn't really help since it's so different. I'll give a shot at figuring out what you want.

If I understand correctly, you want to add money within the main game (outside the slot machine) when you win, but do nothing if you lose? Correct me if im misunderstanding. That can be achieved a few different ways depending on your goal. For example

Code:
#you assign money value, in the main game

$ money = 100

#after you exit the slot machine, you add the coin value to the money

$ money += coins

#now you can do whatever with the money

"You have [money]"

That'd just add your total coin value to your money.

If instead you wanted to only add money if say, you finished with more than 100 coins (the starting value), or more than 150, or whatever then you'd just

Code:
$money = 100

if (coins >150):
    $ money += coins

or if you want to add a specific amount of money

Code:
$ money = 100

if (coins>150):
    $ money += 5
  
"You have [money]"
If you were looking to make the slot machine a 1 time thing, then you really wouldn't have to worry about it much after that.
If it was replayable, you'd just want to make sure you reset the value of coins either every time you entered the slot or after you exit, after doing the money adjustment. for example:

Code:
$money = 100

if (coins>150)
    $ money += 5

$coins = 100
'

And if you wanted to pay for the slot, you could subtract money every time you started it, or manipulate it any other way you'd like.

This is what I added (I also added an exit button in the slot machine, that jumped to the label i created)

Code:
    $ money = 100

    call screen slotstart

    label newlabel:

        scene bgwinter1

        if (coins > 150):
            $ money += 5
        elif (coins < 100):
            $ money -= 5
        $ coins = 100
        "You have [money]"

    call screen slotstart
Every time I exited with less than 100 coins, I lost 5 money, everytime I exited with more, I won 5 money, if I exited with 100-150, nothing changed, and it just repeated entering the slot machine over and over. Obviously you'd prefer something like an imagebutton to click to enter the slot machine, but this was just a quick and dirty example.

I'm not sure if that's what you were asking or not, if not lmk and I'll see what I can do.
If you add some of other example/source code for a clue. it would be more easier for you too.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,130
14,809
Alright, er... It's a code for a slot machine, but why something so complex ?


Note: It's wrote on the fly, I haven't tested it. The purpose is more to show the process than to make an effective slot machine
Python:
# Assuming that "star" is '1', and that there's only three wining combinations:
# ***, **X and *XX

init python:
    def slotMachineRoll():
        # 6 symbol on the slots.
        store.leftSlot = renpy.random.randint(1,6)
        store.centerSlot = renpy.random.randint(1,6)
        store.rightSlot = renpy.random.randint(1,6)

    def slotMachineGain():
        combination = ( leftSlot * 100 ) + ( centerSlot * 10 ) + rightSlot
        if combination == 111:  # three stars, jackpot
            return 100
        elif 110 <= combination < 120: # star, start, whatever
            return 50
        elif 100 <= combination < 200: # star, whatever, whatever
            return 10
        return 0

default leftSlot = 0
default centerSlot = 0
default rightSlot = 0

label slotMachine:
    # Remove the 10 it cost to roll the machine
    $ money -= 10
    # Generate the slot combination.
    $ slotMachineRoll()
    # Display the screen showing the slots roll, then stop on the right combination
    # Note: the screen is not depicted in this exemple.
    screen rollingMachine
    # Compute the gain
    $ gain = slotMachineWin()
    # Tell something to the player
    if gain != 0:
       "Oh, you won"
    else:
       "Sorry you lost"
    # Add the potential gains.
    $ money += gain
    # What to do next
    menu:
        "roll again":
            jump slotMachine
        "quit":
            jump somewhereElse
 
  • Like
Reactions: guest1492