Character creation menu (Stats)

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
Ghuraok
Newbie
Posts: 11
Joined: Wed Jul 19, 2017 7:50 pm
Contact:

Character creation menu (Stats)

#1 Post by Ghuraok »

Hello !

I'm very new to Ren'py and coding in general and I'd like to implement a basic stats system into my game. I would like the player to be able to create his own character and to set the stats with a menu.
I would like a menu with a name input, a minus and plus buttons, the stat's name and value, the remaining creation points and a continue button that only shows when the creation points are all used.
Something like this :
Image
However, I have no idea how to get the buttons - and + to work in the following manner :
Button "+" adds 1 to a stat and removes 1 to the creationpoints value, it has a rule that disable it to prevent the stat value to go further 10 and below 0 for the creationpoints.
Button "-" removes 1 to a stat and adds one to the creationpoints value. + A rule that disable it to prevent the stat value to go below 1.

When it comes to events that add or remove stat points I made the following functions :

Code: Select all

init python:

def plus_stat(x,stat):
        if stat >= 10:
            stat = 10
        else:
            stat += x
            if stat >= 10:
            	stat = 10
        return stat
        
def minus_stat(x,stat):
	if stat <= 1:
		return stat
	else:
		stat -= x
		if stat <= 1:
			stat = 1
	return stat

strengh = 1

label start :
$ strength = plus_stat(2,strength)
"Strength : [strength]"
 output :
 "Strength : 3"
 $ strength = plus_stat(25,strength)
"Strength : [strength]"
 output :
 "Strength : 10"       
Unfortunatly, I don't know how to use this function within buttons inside or outside a screen... I only made a screen I can call only to show the stats but not to change them.
Therefore I need your help to learn how to build a working clean menu that allows the player to set its stats just like a character creation menu. Tutorials, code samples, old threads, anything you think that might help me would be much appreciated.

Thank you for you help.

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Character creation menu (Stats)

#2 Post by Scribbles »

https://www.renpy.org/doc/html/screen_actions.html

That is a list of actions that you can apply to buttons

the Function() action I think will call a function (I copy pasted the info from the site below) I hope that helps! (I'm not great at programming though sorry)

Code: Select all

 Function(callable, *args, **kwargs)

    This Action calls callable with args and kwargs.

    callable
        Callable object.
    args
        position arguments to be passed to callable.
    kwargs
        keyword arguments to be passed to callable. 
Image - Image -Image

User avatar
Ghuraok
Newbie
Posts: 11
Joined: Wed Jul 19, 2017 7:50 pm
Contact:

Re: Character creation menu (Stats)

#3 Post by Ghuraok »

Hey thanks Scribbles,

I've tried to work around the action Function, unfortunatly, whenever I press my button, it just does nothing. Instead, it quits the screen, which never happened before without the action Return(). It's still pretty much dark magic to me but thanks to you I got the right function to do what I want :

Code: Select all

if strength == 0:
        textbutton "-" xpos .49 ypos .20
    else:
        textbutton "-" xpos .49 ypos .20 action [SetVariable("strength", strength - 1), SetVariable("creationpoints", creationpoints + 1)]
    if strength == 10:
        textbutton "+" xpos .64 ypos .20
    elif creationpoints <= 0:
        textbutton "+" xpos .64 ypos .20
    else:
        textbutton "+" xpos .64 ypos .20 action [SetVariable("strength", strength + 1), SetVariable("creationpoints", creationpoints - 1)]
        
if creationpoints <= 0:
        textbutton "Continue" xpos .62 ypos .80 action Return()
    else:
        textbutton "Continue" xpos .62 ypos .80
    textbutton "[creationpoints] left" xpos .60 ypos .65
And it works like a charm ;)

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Character creation menu (Stats)

#4 Post by Scribbles »

I'm glad you figured it out!
Image - Image -Image

Avalonica
Newbie
Posts: 6
Joined: Mon Nov 04, 2019 3:56 pm
Contact:

Re: Character creation menu (Stats)

#5 Post by Avalonica »

Hello. I am making a Character Creation Screen for my first VN. And I would love to implement something like what's partly explained in the above post but for that to work I would need a finished example i.e. a code that I just can paste into a NEW ren'py project and test around with.

So what I need, if we somehow can cannibalize the code from above is something like this:

Points left: 5
Strength: 10 [-] [+]
Dexterity: 10 [-][+]

Points left: 4
Strength: 11 [-] [+] <--- player press + one time and 1 point is taken from "points left" and goes to Strength
Dexterity: 10 [-][+]

Points left: 2
Strength: 11 [-] [+]
Dexterity: 12 [-][+] <--- player press + two times and 2 point is taken from "points left" and goes to Dexterity

Points left: 3
Strength: 11 [-] [+]
Dexterity: 12 [-][+] <--- player press - one time and 1 point is taken from Dexterity and goes back to "points left".

It would be great if anyone accept my plea for help to also make some "formatting" so it looks somewhat nice on screen and I can take it from there. And since this is such a great addition for my VN I'll even credit you for helping me.

The very best regards
A.

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]