How would I implement a choice of 2 objects/gift system?

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
patheticfallacy
Newbie
Posts: 1
Joined: Thu Apr 27, 2017 12:17 pm
Contact:

How would I implement a choice of 2 objects/gift system?

#1 Post by patheticfallacy »

Hello!

I'm making a small game for a friend. I'm a much better artist than I am a programmer, so I attached a very quick MS Paint mockup of what I'm trying to do. (Please ignore the green halo around the teddy bear. I had to resize it and it had a silly.)
Image
Image
The player would come to a store, and have a choice between two items. The player would purchase one of the items and then, later, give this item to another character. This system would also repeat 3 times, and the items would change each time. For instance, picking between either a magazine or a lighter, and then next time, a chocolate bar or a candy cane. I thiiink I understand how to make the game remember the choices--with if/else statements, basically--but the code to put up this menu is confusing me. This could happen very easily in a text menu, so that's why I'd like to know how to make it as an image-based one. Theoretically, you would also have the option of neither of them, but I think that would come from before this menu would ever show up--just saying "No, I don't want to go to the store" and skipping it entirely. Also, while I'm not averse to having a viewable inventory, there's no need to have an inventory button or anything as... well, it's literally only two options and you never have any other items in your inventory.

I have no issue creating the assets for these screens (they're pretty much almost done!) and I would like to take a look at the code and try to figure out something new if possible.

I've been looking all over to see if there's anything I can use to figure out how to do this, but it's possible I just haven't looked hard enough, so if this question has basically been answered somewhere else feel free to point me there. I've made a few small games with it before, but I still consider myself a giant newbie with renpy, so any help is appreciated! Thank you!

User avatar
SuperbowserX
Veteran
Posts: 270
Joined: Sat Jan 07, 2017 3:09 pm
Contact:

Re: How would I implement a choice of 2 objects/gift system?

#2 Post by SuperbowserX »

You're going to want to have 3 screens. Each screen defines a pair of imagebuttons, and when a player clicks a button, that button sets a variable to a value and then exits itself. You then run an if statement based on what the variable is. Call the screens with call screen, not show screen.

Here's a mockup of what's at the top of your script:

Code: Select all

$ purchase = ""
screen pickitem:
    imagebutton idle "teddy.png" hover "teddypicked.png" action [SetVariable("purchase", "bear"), Return()]
    imagebutton idle "ring.png" hover "ringpicked.png" action [SetVariable("purchase", "ring"), Return()]
"teddy.png" and "ring.png" are just generic names for the paths to your images in the game directory. Also, you need a hover image (i.e. one with a changed background color) so that you can indicate to the player that the mouse is hovering over it.

And then, when you show it in game:

Code: Select all

"What would you like to buy?"
call screen pickitem
if purchase == "bear":
    "You bought a bear!"
else:
    "You bought a ring!"
"Buy something else!"
call screen pickitem2

Post Reply

Who is online

Users browsing this forum: No registered users