Basic commands: affection / show / button

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
martom13
Newbie
Posts: 13
Joined: Sat Oct 28, 2023 12:42 pm
Contact:

Basic commands: affection / show / button

#1 Post by martom13 »

I know that maybe somebody will be upset that I am asking this very basic thing. But even after several mounts I didn´t find it. :D :cry:
Because probably everyone knows how to do it. So nobody teaching it /showing it.

If my characters need to obtain something..affection, health potions etc.
Example:

default lucy_love = 0
then
$ lucy_love = lucy_love +1
(so...in game my character will gain "lucy_love")
This what I saw, and I was using it like this.
But then I find myself using just
$ lucy_love += 1

What is the different? Work both.

But how I will reset it? Like if main character will go with Jane instead of Lucy. Lucy is upset and he should lost all his points. Then I need $ lucy_love -= ?? I tried just $ lucy_love == 0. Didn´t work.
Or..how to make it not going into minus (below zero).


Another issue for example with positions of pictures.
I can´t find how to use command "show" with more possibilities then "at left" "at right" "at center"...
For sure I saw that people are using two or three characters on one side...but HOW?
Can I use xpos, ypos, xalign, yalign with commands like "show" "scene" ?
Because I tried and it didn´t work...but..It could just be wrong spacing.
I saw videos where they use command "image", but again..what is difference from "show".

When I create button...can I put there something else then "jump" like command for show or counting like $ lucy_love += 1 etc. ?

I am pretty sure these commands are very basic thing...so this must make a lot of people smile.
Thank you for advise.

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

Re: Basic commands: affection / show / button

#2 Post by m_from_space »

martom13 wrote: Sat Oct 28, 2023 12:58 pm I know that maybe somebody will be upset that I am asking this very basic thing. But even after several mounts I didn´t find it. :D :cry:
Because probably everyone knows how to do it. So nobody teaching it /showing it.
Nobody will get upset, but please put your code into [ code ] ... [ /code ] (without the spaces) tags next time you post here. It's hard to read otherwise.
$ lucy_love = lucy_love +1
...
$ lucy_love += 1

What is the different? Work both.
It's doing the same, just two methods of writing it in Python. Welcome to the world of programming. ;) The latter one is a shorter variant.
The same would apply to this:

Code: Select all

$ mike_love = 5

$ lucy_love = lucy_love + mike_love
# is the same as
$ lucy_love += mike_love
But how I will reset it? Like if main character will go with Jane instead of Lucy. Lucy is upset and he should lost all his points. Then I need $ lucy_love -= ?? I tried just $ lucy_love == 0. Didn´t work.
Or..how to make it not going into minus (below zero).

Code: Select all

# set the variable to 50
$ lucy_love = 50

# increase by 5
$ lucy_love += 5

# decrease by 2
$ lucy_love -= 2

# multiply by 2
$ lucy_love *= 2

# reduce it by 5, but make sure it's not below zero afterwards
$ lucy_love -= 5
if lucy_love < 0:
    $ lucy_love = 0

# reduce it by 5, but not below zero (alternative)
$ lucy_love = max(0, lucy_love - 5)
Another issue for example with positions of pictures.
I can´t find how to use command "show" with more possibilities then "at left" "at right" "at center"...
For sure I saw that people are using two or three characters on one side...but HOW?
Can I use xpos, ypos, xalign, yalign with commands like "show" "scene" ?
Because I tried and it didn´t work...but..It could just be wrong spacing.
Actually the "at" statement sounds like it defines only position (which confused me when I was learning about Renpy many years ago). But "at" refers to ATL transforms, which are definitions for position, but also transformations, so movements, rotations, alpha values etc. So don't think of it as just some kind of position. Also you can create your own ATL statements.

Code: Select all

# show a picture using the "center" transform (which is predefined by Renpy)
show eileen at center

# same thing, different method (and this is how you can use xalign, xpos etc.)
show eileen:
    xalign 0.5 yalign 1.0
I saw videos where they use command "image", but again..what is difference from "show".
Those are different things, but some people use them in the wrong way.

The "image" statement is only used for defining images (usually when Renpy is loading). The "image" statement is *not* for showing images. For most images in your game, you do not have to define them ever though. Since Renpy is detecting all images inside your "images" folder by default, so they are already available when you start the game. Here you can read more about both statements: https://www.renpy.org/doc/html/displaying_images.html
When I create button...can I put there something else then "jump" like command for show or counting like $ lucy_love += 1 etc. ?
Yes, here you can read all about screen element actions (stuff you can make a button do for example): https://www.renpy.org/doc/html/screen_actions.html

Examples:

Code: Select all

screen myscreen():
    vbox:
        textbutton "Increase Lucy's love!" action SetVariable("lucy_love", lucy_love + 1)
        textbutton "Jump somewhere..." action Jump("label_name")

martom13
Newbie
Posts: 13
Joined: Sat Oct 28, 2023 12:42 pm
Contact:

Re: Basic commands: affection / show / button

#3 Post by martom13 »

Hello. Thank you for reply. I am sorry that it take me time. I was out for several weeks. :D
But I really appreciate the support.

Can I ask two question.
1. What action should I put on button, that button will disappear? (like use buttons with images of staff which need to be collected, cleaned etc.

2. If I want to set some variables to 0, but I am not sure how much will main character have of them.
For example:
$ money = 50 (or 41 or37 etc.)
Main character is mugged by thieves who rob him of all his money.
Because I am not sure where payer go in game and how many money he has - I will use:
$ money = max(0, money -1000) right? (some big number)

Hey..yes..it worked. Perfect.

Thank you

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

Re: Basic commands: affection / show / button

#4 Post by m_from_space »

martom13 wrote: Mon Dec 04, 2023 4:22 pm 1. What action should I put on button, that button will disappear? (like use buttons with images of staff which need to be collected, cleaned etc.
If you want a button to disappear after it's being clicked, just use some variable that handles the visibility of this button. So if I understand correctly, for example you have an imagebutton of an item inside a room and when the player clicks on that item, they collect it and the image should disappear. Is that your question?

martom13
Newbie
Posts: 13
Joined: Sat Oct 28, 2023 12:42 pm
Contact:

Re: Basic commands: affection / show / button

#5 Post by martom13 »

Yes, exactly. There is probably more ways how to do it, but this seems to be more simple for me.

Ek_Dahl
Newbie
Posts: 4
Joined: Thu Dec 14, 2023 9:55 pm
Contact:

Re: Basic commands: affection / show / button

#6 Post by Ek_Dahl »

Hello, if you want to put a variable to zero just do :

$ money = 0

the == statement is used in condition to test equality.

for the button to disappear you should create it under a condition. it will appear only if the variable broom is false...

Code: Select all

if (broom == False) :
	imagebutton "broom.png" :
		pos(150, 150)
		action SetVariable("broom", True)

Post Reply

Who is online

Users browsing this forum: Google [Bot]