Page 1 of 3

Questions RE: Several Functions for a Game

Posted: Thu Jun 19, 2008 8:50 pm
by deinarious
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.

Re: Questions RE: Several Functions for a Game

Posted: Thu Jun 19, 2008 9:25 pm
by BellosTheMighty
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>".

Re: Questions RE: Several Functions for a Game

Posted: Thu Jun 19, 2008 10:12 pm
by deinarious
could I see an example of that please?

Re: Questions RE: Several Functions for a Game

Posted: Thu Jun 19, 2008 10:42 pm
by ParsonSyunOwen
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?

Re: Questions RE: Several Functions for a Game

Posted: Thu Jun 19, 2008 10:56 pm
by BellosTheMighty
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.

Re: Questions RE: Several Functions for a Game

Posted: Thu Jun 19, 2008 11:41 pm
by deinarious
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.

Re: Questions RE: Several Functions for a Game

Posted: Thu Jun 19, 2008 11:48 pm
by BellosTheMighty
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.

Re: Questions RE: Several Functions for a Game

Posted: Thu Jun 19, 2008 11:59 pm
by deinarious
*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.

Re: Questions RE: Several Functions for a Game

Posted: Fri Jun 20, 2008 1:50 am
by JQuartz
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'

Re: Questions RE: Several Functions for a Game

Posted: Fri Jun 20, 2008 2:12 am
by deinarious
yeah, that must be what was wrong with my variables.

Re: Questions RE: Several Functions for a Game

Posted: Fri Jun 20, 2008 5:35 am
by Gau_Veldt
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.

Re: Questions RE: Several Functions for a Game

Posted: Fri Jun 20, 2008 6:01 am
by Jake
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!"

Re: Questions RE: Several Functions for a Game

Posted: Fri Jun 20, 2008 6:03 am
by Gau_Veldt
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.

Re: Questions RE: Several Functions for a Game

Posted: Fri Jun 20, 2008 6:06 am
by Gau_Veldt
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.

Re: Questions RE: Several Functions for a Game

Posted: Fri Jun 20, 2008 6:16 am
by Jake
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.