Questions RE: Several Functions for a Game

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.
Message
Author
deinarious
Regular
Posts: 68
Joined: Thu Jun 19, 2008 1:27 am
Completed: Watashi wa Onigiri, A Day Off, T.M.O.G.E
Projects: None.
Contact:

Questions RE: Several Functions for a Game

#1 Post by deinarious » Thu Jun 19, 2008 8:50 pm

Okay, I am new to Ren'Py (and programming in general), and I had some questions regarding functions I wanted to add to my game.

First off, how would I make a mini-game that required the player to match a set of keys or symbols, perhaps even musical notes, that rewarded the player with something, like bonus points for a certain girl, or an item?

Second, how would I make a shop system that coincided with an inventory system and a gift giving system?

And third, how would I make a special power system, like spells or such, along with stats to go with them? My thought was to make a few spells that the player would know from the start, and would learn through various parts of the game, to do things like predict what the favorable response would be for a question, or to impress the characters that the player is trying to win over.

Please respond.

User avatar
BellosTheMighty
Regular
Posts: 63
Joined: Wed Aug 01, 2007 11:11 pm
Contact:

Re: Questions RE: Several Functions for a Game

#2 Post by BellosTheMighty » Thu Jun 19, 2008 9:25 pm

deinarious wrote: And third, how would I make a special power system, like spells or such, along with stats to go with them? My thought was to make a few spells that the player would know from the start, and would learn through various parts of the game, to do things like predict what the favorable response would be for a question, or to impress the characters that the player is trying to win over.
I'm reminded of the old Lone Wolf gamebooks: "If you wish to debate the obnoxious guard, turn to page 87. If you wish to walk away and find another way in, turn to page 26. If you have the Kai Discipline of Psi-Surge and wish to explode this mother#%^&er's brain, turn to page 233."

Admittedly a rather liberal paraphrase, but you get the idea. I'm sure something similar can be done with Ren'Py. Figure out how to make a menu option that doesn't show up- or, alternately, shows up but is inert- unless the player has whatever skill would be useful.

If you can't do that, the low-rent method is to make said option "always on" and then return an "I don't have that skill." message if the player clicks on it. After which you either re-display the menu and and let him try again or, if you're feeling cruel, say "...so instead I <whatever>".
----
"Yes, ninety percent would never get finished, and ninety percent of the rest would suck. That's the way it always works. That's how you get stuff that kicks ass." -Andrew Plotkin

deinarious
Regular
Posts: 68
Joined: Thu Jun 19, 2008 1:27 am
Completed: Watashi wa Onigiri, A Day Off, T.M.O.G.E
Projects: None.
Contact:

Re: Questions RE: Several Functions for a Game

#3 Post by deinarious » Thu Jun 19, 2008 10:12 pm

could I see an example of that please?

ParsonSyunOwen
Regular
Posts: 27
Joined: Sun Jun 08, 2008 6:01 pm
Contact:

Re: Questions RE: Several Functions for a Game

#4 Post by ParsonSyunOwen » Thu Jun 19, 2008 10:42 pm

Well, for the low-rent version:

Code: Select all

menu:
    "Punch him in the face":
        "I punch him in the face."
        jump punch
    "Kick him in the shins":
        "I kick him in the shins."
        jump kick
    "KAMEHAMEHA!":
        if Kamehameha == "known":
            "I blast him into orbit."
            jump kame
        else:
            "I don't know how to do that, so I kick him in the shins instead."
            jump kick
I'm pretty sure the higher-level stuff is doable, but I'm a bit new to this myself. ^_^;;;;;; Anyone else have an idea?

User avatar
BellosTheMighty
Regular
Posts: 63
Joined: Wed Aug 01, 2007 11:11 pm
Contact:

Re: Questions RE: Several Functions for a Game

#5 Post by BellosTheMighty » Thu Jun 19, 2008 10:56 pm

ParsonSyunOwen wrote:Well, for the low-rent version:

Code: Select all

menu:
    "Punch him in the face":
        "I punch him in the face."
        jump punch
    "Kick him in the shins":
        "I kick him in the shins."
        jump kick
    "KAMEHAMEHA!":
        if Kamehameha == "known":
            "I blast him into orbit."
            jump kame
        else:
            "I don't know how to do that, so I kick him in the shins instead."
            jump kick
I'm pretty sure the higher-level stuff is doable, but I'm a bit new to this myself. ^_^;;;;;; Anyone else have an idea?
Yeah, that's prety much it. For the "repeat the choice again" method, it's a little trickier, but basically you put a label right before the menu and then jump back:

Code: Select all

label fight_guy:
menu:
    "Punch him in the face":
        "I punch him in the face."
        jump punch
    "Kick him in the shins":
        "I kick him in the shins."
        jump kick
    "KAMEHAMEHA!":
        if Kamehameha == "known":
            "I blast him into orbit."
            jump kame
        else:
            "I don't know how to do that."
            jump fight_guy
For the "option doesn't show up" method, you just use an if:

Code: Select all

menu:
    "Punch him in the face":
        "I punch him in the face."
        jump punch
    "Kick him in the shins":
        "I kick him in the shins."
        jump kick
    "KAMEHAMEHA!" if Kamehameha == "known":
        "I blast him into orbit."
        jump kame
Keep in mind, however, that with that last one the player won't know that Kamehameha is an option until he reaches this point with it. Whether or not that is a good thing is a matter of design philosophy.
----
"Yes, ninety percent would never get finished, and ninety percent of the rest would suck. That's the way it always works. That's how you get stuff that kicks ass." -Andrew Plotkin

deinarious
Regular
Posts: 68
Joined: Thu Jun 19, 2008 1:27 am
Completed: Watashi wa Onigiri, A Day Off, T.M.O.G.E
Projects: None.
Contact:

Re: Questions RE: Several Functions for a Game

#6 Post by deinarious » Thu Jun 19, 2008 11:41 pm

How would I make it so that the spells are learnable, from things like say, meditation, library research, or using a certain item?

Also, still looking for how to do the mini game and shop/inventory/gift system. Last one preferably with currency.

I appreciate the help. I only started learning Ren'Py successfully yesterday. I tried it once or twice about three or four years ago, and failed miserably because I couldn't understand it, along with being impatient.

The patience was fixed with meditation and alternative religion, and the understanding it is now possible because of the wiki dedicated to Ren'Py, but that's not important.

User avatar
BellosTheMighty
Regular
Posts: 63
Joined: Wed Aug 01, 2007 11:11 pm
Contact:

Re: Questions RE: Several Functions for a Game

#7 Post by BellosTheMighty » Thu Jun 19, 2008 11:48 pm

deinarious wrote:How would I make it so that the spells are learnable, from things like say, meditation, library research, or using a certain item?
Uhhh... the player does the thing, and you set the variable. Very basic.
----
"Yes, ninety percent would never get finished, and ninety percent of the rest would suck. That's the way it always works. That's how you get stuff that kicks ass." -Andrew Plotkin

deinarious
Regular
Posts: 68
Joined: Thu Jun 19, 2008 1:27 am
Completed: Watashi wa Onigiri, A Day Off, T.M.O.G.E
Projects: None.
Contact:

Re: Questions RE: Several Functions for a Game

#8 Post by deinarious » Thu Jun 19, 2008 11:59 pm

*facepalms* right! I forgot that!

-edit- quick question : how do I make a variable properly? just want to make sure I have the right idea.

User avatar
JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Questions RE: Several Functions for a Game

#9 Post by JQuartz » Fri Jun 20, 2008 1:50 am

deinarious wrote:how do I make a variable properly?
I don't really know what is proper but this would work for the kamehameha case:

Code: Select all

$ Kamehameha='known'
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

deinarious
Regular
Posts: 68
Joined: Thu Jun 19, 2008 1:27 am
Completed: Watashi wa Onigiri, A Day Off, T.M.O.G.E
Projects: None.
Contact:

Re: Questions RE: Several Functions for a Game

#10 Post by deinarious » Fri Jun 20, 2008 2:12 am

yeah, that must be what was wrong with my variables.

User avatar
Gau_Veldt
Regular
Posts: 86
Joined: Tue Jun 10, 2008 8:22 pm
Location: Prince George, BC
Contact:

Re: Questions RE: Several Functions for a Game

#11 Post by Gau_Veldt » Fri Jun 20, 2008 5:35 am

deinarious wrote:*facepalms* right! I forgot that!

-edit- quick question : how do I make a variable properly? just want to make sure I have the right idea.
About the only thing to watch for with variables is that if you want them to work for rollback and saving they should be in the start: (or any subsequent) label and not in the init: label.

Code: Select all

start:
  $ my_first_variable = 'something-or-other' # words or text
  $ my_second_variable = 10 # a number
Is the typical way to set a variable.
Last edited by Gau_Veldt on Fri Jun 20, 2008 6:32 am, edited 2 times in total.

User avatar
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Questions RE: Several Functions for a Game

#12 Post by Jake » Fri Jun 20, 2008 6:01 am

He means:

Code: Select all

$ my_variable = 'some_value'
(I presume the extra ']' was a markup-code accident)


Also note that if you're dealing with numbers you don't need the single-quotes:

Code: Select all

$ my_numeric_variable = 10
- if you use the single quotes it means you're dealing with text. If you're usisg numbers, then don't use the single quotes and you can do stuff like:

Code: Select all

$ a = 10
$ b = 5 + a

if (b > 10):
  e "Hey look, a number above ten!"
Server error: user 'Jake' not found

User avatar
Gau_Veldt
Regular
Posts: 86
Joined: Tue Jun 10, 2008 8:22 pm
Location: Prince George, BC
Contact:

Re: Questions RE: Several Functions for a Game

#13 Post by Gau_Veldt » Fri Jun 20, 2008 6:03 am

deinarious wrote:Okay, I am new to Ren'Py (and programming in general), and I had some questions regarding functions I wanted to add to my game.

First off, how would I make a mini-game that required the player to match a set of keys or symbols, perhaps even musical notes, that rewarded the player with something, like bonus points for a certain girl, or an item?

Second, how would I make a shop system that coincided with an inventory system and a gift giving system?

And third, how would I make a special power system, like spells or such, along with stats to go with them? My thought was to make a few spells that the player would know from the start, and would learn through various parts of the game, to do things like predict what the favorable response would be for a question, or to impress the characters that the player is trying to win over.

Please respond.
Any particular minigames would involve dabbling with Displayables and PyGame (look in the cookbook for examples). You might look at the Pong example in the demo as a starting point. Generally speaking minigames will be harder to do than the overall game's script.

Details of any particular minigame you want to do would involve coming up with a formulation of what happens in any minigame you want to make (example for the demo might go something like: ball bounces on top and bottom of screen and paddles. player has left side. computer has right. each player and moves their paddle. player gets a point when other player's paddle misses the ball. first player to 10 wins.)

Giving rewards is just a case of testing (with if) against the outcome of the minigame then adding any reward (by setting variables to represent reward items) if the outcome of the game is appropriate to any rewards.

For a shop system you'll want to look a bit into the Python under the Ren'Py hood. Most undoubtedly the list and dictionary types since they help greatly with this kind of task.

A very simplistic item system would use a list whose elements are the "names" of the items. You can then use the find() method to see if a player has a certain item.

Code: Select all

$ inventory=[
    'apple',
    'peach'
  ]
If you wanted to see if the player has any apples you can use:

Code: Select all

if inventory.find('apple'):
  e "Oh, an apple!  May I have it?"
else:
  e "My, isn't the weather nice today?"
A slightly more advanced inventory could use a dictionary rather than a list using the keys for the names of any item and the value being the quantity of that item. The latter is slightly more work and you would be writing a bit of python code to do so. Though if you learn Python in the process of coding the minigames you want to do this won't be that bad.

User avatar
Gau_Veldt
Regular
Posts: 86
Joined: Tue Jun 10, 2008 8:22 pm
Location: Prince George, BC
Contact:

Re: Questions RE: Several Functions for a Game

#14 Post by Gau_Veldt » Fri Jun 20, 2008 6:06 am

Jake wrote:He means:

Code: Select all

$ my_variable = 'some_value'
(I presume the extra ']' was a markup-code accident)


Also note that if you're dealing with numbers you don't need the single-quotes:

Code: Select all

$ my_numeric_variable = 10
- if you use the single quotes it means you're dealing with text. If you're usisg numbers, then don't use the single quotes and you can do stuff like:

Code: Select all

$ a = 10
$ b = 5 + a

if (b > 10):
  e "Hey look, a number above ten!"
I made the example in a way that documented itself. A number doesn't really do that. And yeah markup glitch. 'tis been edited out.

User avatar
Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Questions RE: Several Functions for a Game

#15 Post by Jake » Fri Jun 20, 2008 6:16 am

Gau_Veldt wrote: I made the example in a way that documented itself. A number doesn't really do that.
Hey, hey, I'm not criticising you. Just noting that a lot of the time people will want to store numbers, and if they believe that they have to put single quotes around all their values then they're going to get confused when they try and do calculations with them.
Server error: user 'Jake' not found

Post Reply

Who is online

Users browsing this forum: akakyouryuu, Google [Bot]