[Solved] How can I use it as an "action"?

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
User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

[Solved] How can I use it as an "action"?

#1 Post by Nanahs »

If "Coin" starts with 0. Like this:

Code: Select all

    $ Coins=0
I wanted a button that would increase the value of coins when being clicked.

Like:

Code: Select all

    $ Coins += 1
How can I make an "action" that would do that?
I wanted to use an image of coins to create an imagebutton with that "action".

Image

I've only seen this being used, and I have only used, this with "if" statement and menu choice.
So I'm not sure if it's possible.

Thanks.
Last edited by Nanahs on Wed Feb 13, 2019 1:01 pm, edited 3 times in total.

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

Re: How can I use it as an "action"?

#2 Post by Alex »

You can make a screen with the button

Code: Select all

textbutton "Get coin" action SetVariable("Coins", Coins+1) # name of variable in quotes (you named it with capital C)
https://www.renpy.org/doc/html/screen_a ... etVariable
https://www.renpy.org/doc/html/screens.html#imagebutton

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How can I use it as an "action"?

#3 Post by trooper6 »

But as always, remember you should be initializing your variables like this:

Code: Select all

default coins = 0
rather than like this

Code: Select all

$coins =  0
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: How can I use it as an "action"?

#4 Post by Nanahs »

Thank you so much guys! :)

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: [Solved] How can I use it as an "action"?

#5 Post by Nanahs »

It's working great! Thanks!
Just one question. If I wanted to stablish a limit, how would it be?

Like, if you could only get 10 coins, and after this imagebutton wouldn't add more coins when clicked.

I tried a few things like "max_coins=10", etc and a few other codes, but they didn't work.

Thanks.

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

Re: [Solved] How can I use it as an "action"?

#6 Post by Alex »

It would be

Code: Select all

textbutton "Get coin" action If(Coins<10, SetVariable("Coins", Coins+1), None)
https://www.renpy.org/doc/html/screen_actions.html#If

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: [Solved] How can I use it as an "action"?

#7 Post by Nanahs »

Alex wrote: Wed Feb 13, 2019 4:59 pm It would be

Code: Select all

textbutton "Get coin" action If(Coins<10, SetVariable("Coins", Coins+1), None)
https://www.renpy.org/doc/html/screen_actions.html#If
Thank you so much! :)

Post Reply

Who is online

Users browsing this forum: Google [Bot], peach_light