making hp con based

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
zant19
Newbie
Posts: 6
Joined: Sun Dec 21, 2014 6:33 am
Contact:

making hp con based

#1 Post by zant19 »

I hope this is the right place to post this, my first time asking a question on here.

so I'm trying to make the player hp = their con score * 5.
When i change the con i can track the change, but when i change the con it doesn't change the player hp.

here is the problem as far as I can simplify---------------

# Declare characters used by this game. The color argument colorizes the

define NAR = Character("Narrator")
define UN = Character("Angle Pie")

# The game starts here.

label start:

$ player_str = 5
$ player_dex = 5
$ player_con = 5
$ player_int = 5
$ player_wis = 5
$ player_cha = 5
$ player_hp = player_con * 5
$ player_mp = player_int * 5


UN "your hp is... %(player_hp)d"
$ player_con += 1
UN "adding 5 your new hp is... %(player_hp)d"
NAR "if it is not 30 then a table gets filpped again."

return # This ends the game.

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

Re: making hp con based

#2 Post by Alex »

There are number of ways to make it, try

Code: Select all

default player_con_1 = 5
default player_hp_1 = player_con_1*5

default player_con_2 = 5
default player_hp_2 = player_con_2*5

default player_con_3 = 5
default player_hp_3 = player_con_3*5


init python:
    def hp_func(x=0):
        global player_con_3, player_hp_3
        player_con_3 += x
        player_hp_3 = player_con_3*5
        
    player_con_4 = 5
    player_hp_4 = player_con_4*5
    def hp_func_2():
        global player_con_4, player_hp_4
        player_hp_4 = player_con_4*5
    config.python_callbacks.append(hp_func_2)
        
# The game starts here.
label start:
    "...1...calculate it everytime manualy"
    "hp_1 - [player_hp_1]"
    "+5 hp"
    $ player_con_1 += 1
    $ player_hp_1 = player_con_1*5
    "hp_1 - [player_hp_1]"
    "?"
    "...2...make a label where all calculations will be done"
    "hp_2 - [player_hp_2]"
    "+5 hp"
    call hp_calc(1)
    "hp_2 - [player_hp_2]"
    "?"
    "...3...create a function"
    "hp_3 - [player_hp_3]"
    "+5 hp"
    $ hp_func(1)
    "hp_3 - [player_hp_3]"
    "?"
    "...4...add a function to the list of python callbacks, so it will be executed everytime you use python"
    $ player_con_4 = 5
    "hp_4 - [player_hp_4]"
    "+5 hp"
    $ player_con_4 += 1
    "hp_4 - [player_hp_4]"
    "?"
    "+5 hp"
    $ player_con_4 += 1
    "hp_4 - [player_hp_4]"
    "?"
    "+5 hp"
    $ player_con_4 += 1
    "hp_4 - [player_hp_4]"
    "?"
    return # to not let game go farther to label hp_calc
    
    


label hp_calc(x=0):
    $ player_con_2 += x
    $ player_hp_2 = player_con_2*5
    return
https://www.renpy.org/doc/html/label.ht ... -statement
viewtopic.php?f=8&t=37507&p=406500&hili ... ck#p406500

zant19
Newbie
Posts: 6
Joined: Sun Dec 21, 2014 6:33 am
Contact:

Re: making hp con based

#3 Post by zant19 »

it took a lot of reading and testing to get it to work, and the posts on viewtopic.php?f=8&t=37507 were just the right thing i needed to get it. So i just want to say thanks!!!!! :D :D :D :D :D :D


new code looks like this now--------

# Declare characters used by this game. The color argument colorizes the

define NAR = Character("Narrator")
define UN = Character("Angle Pie")

init python:

player_con = 5
player_hp = player_con*5

def hp_function():
global player_con, player_hp
player_hp = player_con * 5
config.python_callbacks.append(hp_function)

# The game starts here.

label start:

UN "your hp is... %(player_hp)d"
$ player_con += 1
UN "adding 5 your new hp is... %(player_hp)d"
NAR "if it is not 30 then a table gets filpped again."

return # This ends the game.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]