how to make a shop in renpy?

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
sandorm2
Newbie
Posts: 7
Joined: Thu Mar 30, 2023 11:48 pm
Contact:

how to make a shop in renpy?

#1 Post by sandorm2 »

it sounds simple, but its not. here is my code. what am I doing wrong?

script.rpy:

Code: Select all

define e = Character("Eileen")
default money = 1500

label start:
    e "You've created a new Ren'Py game."
    e "Once you add a story, pictures, and music, you can release it to the world!"
    e "3"
    e "2"
    e "1"
    e "start game!"
screens.rpy:

Code: Select all

screen HUD():
    text "[money]":
        xpos 1600
        ypos 40
    button:
        xpos 100
        ypos 40
        text "spend -100 money"
        action [ SetVariable("money", money-100) ]
init python:
    config.overlay_screens.append('HUD')
when I click the "spend 100 money" button, my money goes down by 100. when I continue the story and go through a few of eileen's messages, then rollback, I can go to before I spent the money and back to 1500 money.
then, when I rollforward, I still have 1500 money. it's as if the choices I made have been disregarded... why?

**note**
this does not happen with:

Code: Select all

menu: 
  "spend 100 money":
      $ money -= 100
in the script.rpy file instead. so why do I get this with a button and not with a menu option?!

how can I make a button for inventory (use items), combat, etc? if players can then rollback and everything is reset then rollforward. nothing will function. so the whole game can only be done with menu? why bother having variables and actions and sreens if only menu works?!
or am I doing something wrong??

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1011
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: how to make a shop in renpy?

#2 Post by m_from_space »

If the user decides to rollback, they clearly want something else. So rolling forward shouldn't just redo their actions.

I'm not creating a game so the user can roll back and forward all the time. What's the point?

But you are doing something wrong: You have a permanent screen on the HUD that changes a variable. I don't think that's a good idea. When your character wants to go shopping, just call a screen or a label for that matter and return after they finish. It also feels more natural than pressing a button that just instant buys stuff.

sandorm2
Newbie
Posts: 7
Joined: Thu Mar 30, 2023 11:48 pm
Contact:

Re: how to make a shop in renpy?

#3 Post by sandorm2 »

this really doesnt help me.
I understand your point about rollback/rollforward. but why does this work with the menu? because when I play renpy games, i often rollback to change my decisions to get a full experience of the game. and sometimes I accidently rollback too far, or I realize I did all options and want to quickly roll forward.

as for your shop comment... I think you are missing the point COMPLETELY here. say you wanted to USE items? How would this work? You have a menu button with items and you use them at ANY point in the game. perhaps a coffee to give you more action points so you can interact with more characters before going to sleep... but then, you can rollback and forward and move PAST interactions you did, and your item is RESTORED! BAM! game breaking. its like a cheat.

this is one of MANY issues and situations. So, how do you implement points/relationship score/items to use/etc/etc/etc a ANY variable that can be stored in a renpy game, and used any time in a button, with character buttons in every map as you go through your day?!
Heck, like ANY renpy game out there with daily tasks, clickable characters, etc?
is rollback just completely disabled for EVERY screen?
What am I missing here?

User avatar
Alex
Lemma-Class Veteran
Posts: 3098
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: how to make a shop in renpy?

#4 Post by Alex »

sandorm2 wrote: Fri Mar 31, 2023 10:53 am ... but why does this work with the menu? ...
This works 'cause there is the line of code to change the variable value. When player rolls back and forward Ren'Py re-run lines of code, so value changes.

In screen player can interact with objects, this might lead to some changes. Screen actions make those changes visible immediately. Those changes will be properly stored on next statement execution (next line of code). Try to click button and save game state at different points. You should get:
- if you click button and not proceed in game, save game state and load it again - money changes won't be saved;
- if you click button and proceed in game, save game state and load it again - money changes will be properly saved.

When player clicked the button in screen (changed the money variable), proceeded in game, then did a rollback to the point before variable was changed, and doing rollforward, the game will rollforward, but it won't do 'clicks' for the player. If player decided to rollback and re-do actions that was made, (s)he should do new actions again.

There will be no cheats, 'cause if player 'will use a cup of coffee' to get some energy to talk to NPC and then rollback to point before using coffee, there will be no extra energy points to do action until player use coffee again.
Try this code with your screen:

Code: Select all

label start:
    "1"
    "2"
    if money < 1000:
        "money: [money] < 1000"
    "3"
    "4"
    "5"
    "?!"
So, if you'll allow rollback in game, player will have to re-do all the actions in screen again.

sandorm2
Newbie
Posts: 7
Joined: Thu Mar 30, 2023 11:48 pm
Contact:

Re: how to make a shop in renpy?

#5 Post by sandorm2 »

but if the player uses a cup of coffee, gets extra energy, does extra tasks with that energy, rollsback, regains the cup of coffee, then rolls forward past the tasks, they will continue the game with the coffee AND tasks completed.

another example. say you have 1 item that if you give to player A or B you can marry them or get something from them. you can use it and get the scene/bonus. then scrollback, get the item back, go past the scene again and then get the same with other character.

say you are in a "fight" your HP is very low. you win against the enemy. your HP is almost finished and you have another fight right away (like a boxing match in a visual novel with 3 rounds). on round 2, you can instanly replenish your health by scrolling back, getting full health again and, you dont need to fight opponent again, just scroll forward and start second round, with full health!

there are many cases where this breaks the game. And if you have items that can be used at any time in inventory, or equipped or wtv.
you can no longer have buttons on screens. every variable can be subject to this issue... and so many cases you can't think of them all...

isnt there a way to press a button and go to a screen or do something, then change a variable and continue the game with the option to go back or forward with the logic following properly??

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1011
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: how to make a shop in renpy?

#6 Post by m_from_space »

sandorm2 wrote: Fri Mar 31, 2023 12:50 pm but if the player uses a cup of coffee, gets extra energy, does extra tasks with that energy, rollsback, regains the cup of coffee, then rolls forward past the tasks, they will continue the game with the coffee AND tasks completed.
Nope, that doesn't work. Game logic will prevent it, as Alex already told you.
another example. say you have 1 item that if you give to player A or B you can marry them or get something from them. you can use it and get the scene/bonus. then scrollback, get the item back, go past the scene again and then get the same with other character.
Yes, that's possible if you allow rollback before menu choices. "Rolling back" literally means that you want to undo things, maybe you are misunderstanding the concept. It's not about "looking back what happened" (although it can be used like it when no choices or interactions are involved).
say you are in a "fight" your HP is very low. you win against the enemy. your HP is almost finished and you have another fight right away (like a boxing match in a visual novel with 3 rounds). on round 2, you can instanly replenish your health by scrolling back, getting full health again and, you dont need to fight opponent again, just scroll forward and start second round, with full health!
If you properly code your game, that's not possible. I mean it's not like there aren't games like this out there.
isnt there a way to press a button and go to a screen or do something, then change a variable and continue the game with the option to go back or forward with the logic following properly??
The logic *is* followed properly. It's just not doing user actions for you when rolling forward.

BeverlyLane
Newbie
Posts: 3
Joined: Wed Apr 26, 2023 4:34 am
Contact:

Re: how to make a shop in renpy?

#7 Post by BeverlyLane »

Define your items Decide what items you want to sell in your shop and define them in a variable. For example, you might define a list of dictionaries that contain the name, price, and image of each item.

Post Reply

Who is online

Users browsing this forum: No registered users