[SOLVED]Making hp heal potions
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.
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.
[SOLVED]Making hp heal potions
I was trying to make a rpg frame and want to know. how to make a potion to heal hp? i followed the example of a script but it need a define to "gain" someone can help me?
Last edited by leoxhurt on Sun Sep 17, 2017 9:38 am, edited 1 time in total.
- DannyGMaster
- Regular
- Posts: 113
- Joined: Fri Sep 02, 2016 11:07 am
- Contact:
Re: Making hp heal potions
For an introduction to how to create items and an inventory to hold them, among other good things, check here:
viewtopic.php?f=51&t=44730
As for the HP Healing part, you need to create a function that will add up a specific number to the variable that holds the HP parameter of a character, without exceeding his/her maximum HP, supposing your battler has that stat defined.
A quick example:
In this code I give max_hp and hp as separate single stats, you will see why in a moment.
The function for changing a battler's HP would be something like this:
This function receives a battler object as first argument, and an amount (a number) as a second parameter. It takes the battler's HP value, increases it with the number specified, then it checks if the hp variable exceeds the max_hp value. If it does, it resets it, so HP can never normally exceed whatever max HP the character may have.
You can then call this function from your Item object's code, or from your battle menu, or anywhere, that really depends on you and how you code your game.
viewtopic.php?f=51&t=44730
As for the HP Healing part, you need to create a function that will add up a specific number to the variable that holds the HP parameter of a character, without exceeding his/her maximum HP, supposing your battler has that stat defined.
A quick example:
Code: Select all
init python:
class Battler(object):
def __init__(self, name, max_hp):
self.name = name
self.max_hp = max_hp
self.hp = self.max_hp
default adam = Battler("Adam", 100)
The function for changing a battler's HP would be something like this:
Code: Select all
init python:
def heal_hp(battler, amount):
battler.hp += amount
if battler.hp > battler.max_hp:
battler.hp = battler.max_hp
You can then call this function from your Item object's code, or from your battle menu, or anywhere, that really depends on you and how you code your game.
The silent voice within one's heart whispers the most profound wisdom.
Re: Making hp heal potions
the ""defeault adam init python:DannyGMaster wrote: ↑Tue Aug 29, 2017 12:37 pm For an introduction to how to create items and an inventory to hold them, among other good things, check here:
viewtopic.php?f=51&t=44730
As for the HP Healing part, you need to create a function that will add up a specific number to the variable that holds the HP parameter of a character, without exceeding his/her maximum HP, supposing your battler has that stat defined.
A quick example:In this code I give max_hp and hp as separate single stats, you will see why in a moment.Code: Select all
init python: class Battler(object): def __init__(self, name, max_hp): self.name = name self.max_hp = max_hp self.hp = self.max_hp default adam = Battler("Adam", 100)
The function for changing a battler's HP would be something like this:
This function receives a battler object as first argument, and an amount (a number) as a second parameter. It takes the battler's HP value, increases it with the number specified, then it checks if the hp variable exceeds the max_hp value. If it does, it resets it, so HP can never normally exceed whatever max HP the character may have.Code: Select all
init python: def heal_hp(battler, amount): battler.hp += amount if battler.hp > battler.max_hp: battler.hp = battler.max_hp
You can then call this function from your Item object's code, or from your battle menu, or anywhere, that really depends on you and how you code your game.
class Battler(object):
def __init__(self, name, max_hp):
self.name = name
self.max_hp = max_hp
self.hp = self.max_hp
i will try to add this in my code, thanks
Re: Making hp heal potions
i got this error in the code:DannyGMaster wrote: ↑Tue Aug 29, 2017 12:37 pm For an introduction to how to create items and an inventory to hold them, among other good things, check here:
viewtopic.php?f=51&t=44730
As for the HP Healing part, you need to create a function that will add up a specific number to the variable that holds the HP parameter of a character, without exceeding his/her maximum HP, supposing your battler has that stat defined.
A quick example:In this code I give max_hp and hp as separate single stats, you will see why in a moment.Code: Select all
init python: class Battler(object): def __init__(self, name, max_hp): self.name = name self.max_hp = max_hp self.hp = self.max_hp default adam = Battler("Adam", 100)
The function for changing a battler's HP would be something like this:
iThis function receives a battler object as first argument, and an amount (a number) as a second parameter. It takes the battler's HP value, increases it with the number specified, then it checks if the hp variable exceeds the max_hp value. If it does, it resets it, so HP can never normally exceed whatever max HP the character may have.Code: Select all
init python: def heal_hp(battler, amount): battler.hp += amount if battler.hp > battler.max_hp: battler.hp = battler.max_hp
You can then call this function from your Item object's code, or from your battle menu, or anywhere, that really depends on you and how you code your game.
Code: Select all
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.
File "game/wtg_rpg.rpy", line 180: expected an indented block
self->.HP = self.maxHP
^
Ren'Py Version: Ren'Py 6.99.12.4.2187
Re: Making hp heal potions
this error was solved, but i setted the item as:leoxhurt wrote: ↑Wed Aug 30, 2017 1:46 pmi got this error in the code:DannyGMaster wrote: ↑Tue Aug 29, 2017 12:37 pm For an introduction to how to create items and an inventory to hold them, among other good things, check here:
viewtopic.php?f=51&t=44730
As for the HP Healing part, you need to create a function that will add up a specific number to the variable that holds the HP parameter of a character, without exceeding his/her maximum HP, supposing your battler has that stat defined.
A quick example:In this code I give max_hp and hp as separate single stats, you will see why in a moment.Code: Select all
init python: class Battler(object): def __init__(self, name, max_hp): self.name = name self.max_hp = max_hp self.hp = self.max_hp default adam = Battler("Adam", 100)
The function for changing a battler's HP would be something like this:
iThis function receives a battler object as first argument, and an amount (a number) as a second parameter. It takes the battler's HP value, increases it with the number specified, then it checks if the hp variable exceeds the max_hp value. If it does, it resets it, so HP can never normally exceed whatever max HP the character may have.Code: Select all
init python: def heal_hp(battler, amount): battler.hp += amount if battler.hp > battler.max_hp: battler.hp = battler.max_hp
You can then call this function from your Item object's code, or from your battle menu, or anywhere, that really depends on you and how you code your game.
obs: the self.HP and maxHP of my char script is in this wayCode: Select all
I'm sorry, but errors were detected in your script. Please correct the errors listed below, and try again. File "game/wtg_rpg.rpy", line 180: expected an indented block self->.HP = self.maxHP ^ Ren'Py Version: Ren'Py 6.99.12.4.2187
Code: Select all
$ pot = Item("Small Potion", "A Small Potion that heals 20 hp", "potevida.png", act=heal_hp)
- DannyGMaster
- Regular
- Posts: 113
- Joined: Fri Sep 02, 2016 11:07 am
- Contact:
Re: Making hp heal potions
If I understand correctly, you have a Potion icon in some sort of item screen, and when you click on it, it only activates when you take the mouse out of it?leoxhurt wrote: ↑Wed Aug 30, 2017 1:46 pm this error was solved, but i setted the item as:but when i try to activate it, only active if i click on it and my mouse leave the icon area, how to fix it?Code: Select all
$ pot = Item("Small Potion", "A Small Potion that heals 20 hp", "potevida.png", act=heal_hp)
I don't know if this is the cause but I assume you created the pot inside a label (from the $ mark you put before it), in your script. If that's the case, maybe you should define it outside of a label, using the default statement.
Code: Select all
default pot = Item("Small Potion", "A Small Potion that heals 20 hp", "potevida.png", act=heal_hp)
label start:
# The game starts here.
# And continues on.
The silent voice within one's heart whispers the most profound wisdom.
Re: Making hp heal potions
DannyGMaster wrote: ↑Thu Aug 31, 2017 8:34 amIf I understand correctly, you have a Potion icon in some sort of item screen, and when you click on it, it only activates when you take the mouse out of it?leoxhurt wrote: ↑Wed Aug 30, 2017 1:46 pm this error was solved, but i setted the item as:but when i try to activate it, only active if i click on it and my mouse leave the icon area, how to fix it?Code: Select all
$ pot = Item("Small Potion", "A Small Potion that heals 20 hp", "potevida.png", act=heal_hp)
I don't know if this is the cause but I assume you created the pot inside a label (from the $ mark you put before it), in your script. If that's the case, maybe you should define it outside of a label, using the default statement.
Code: Select all
default pot = Item("Small Potion", "A Small Potion that heals 20 hp", "potevida.png", act=heal_hp) label start: # The game starts here. # And continues on. [/quote] yes, i used a $ to define, but i setted now on defeault and the same trouble keeps until i used the defeault thing you said, but i can show the code if nedded to solve this
Re: Making hp heal potions
leoxhurt wrote: ↑Thu Aug 31, 2017 8:40 amyes, i used a $ to define, but i setted now on defeault and the same trouble keeps until i used the defeault thing you said, but i can show the code if nedded to solve thisDannyGMaster wrote: ↑Thu Aug 31, 2017 8:34 amIf I understand correctly, you have a Potion icon in some sort of item screen, and when you click on it, it only activates when you take the mouse out of it?leoxhurt wrote: ↑Wed Aug 30, 2017 1:46 pm this error was solved, but i setted the item as:but when i try to activate it, only active if i click on it and my mouse leave the icon area, how to fix it?Code: Select all
$ pot = Item("Small Potion", "A Small Potion that heals 20 hp", "potevida.png", act=heal_hp)
I don't know if this is the cause but I assume you created the pot inside a label (from the $ mark you put before it), in your script. If that's the case, maybe you should define it outside of a label, using the default statement.
Code: Select all
default pot = Item("Small Potion", "A Small Potion that heals 20 hp", "potevida.png", act=heal_hp) label start: # The game starts here. # And continues on.
- DannyGMaster
- Regular
- Posts: 113
- Joined: Fri Sep 02, 2016 11:07 am
- Contact:
Re: Making hp heal potions
Yes, If you can show the relevant code, it may help us understand what the problem is.
The silent voice within one's heart whispers the most profound wisdom.
Re: Making hp heal potions
DannyGMaster wrote: ↑Thu Aug 31, 2017 8:49 amYes, If you can show the relevant code, it may help us understand what the problem is.
Code: Select all
class Item(store.object):
def __init__(self, name, desc, icon=False, player=None, value=0, act=None, action=None, heal_hp= 0, type="item", recipe=False):
global cookbook
self.name = name
self.desc = desc
self.actions = []
self.heal_hp = heal_hp
self.player=player
self.action = action
self.icon = icon
self.value = value
self.act = act # screen action
self.type = type # type of item
self.recipe = recipe # nested list of [ingredient, qty]
def use(self): #here we define what should happen when we use the item
if self.hp>0: #healing item
self.hp = self.hp+self.hp
if self.hp > self.maxhp: # can't heal beyond max HP
self.hp = self.maxhp
inventory.drop(self) # consumable item - drop after use
if recipe:
cookbook.append(self)
cookbook.sort(key=lambda i: i.name) #alpha order
def change(self, name, heal_hp, desc=False, icon=False, value=False, act=False, recipe=False, action=False):
self.name = name
if desc:
self.desc = desc
if icon:
self.icon = icon
if value:
self.value = value
if act:
self.act = act
if action:
self.action = action
if heal_hp:
self.heal_hp = heal_hp
if recipe:
self.recipe = recipe
class Inventory(store.object):
def __init__(self, name, money=0, barter=100):
self.name = name
self.money = money
self.barter = barter #percentage of value paid for items
self.inv = [] # items stored in nested list [item object, qty]
self.sort_by = self.sort_name
self.sort_order = True #ascending, descending
self.grid_view = True
def buy(self, item, price):
self.deposit(price)
self.take(item[0])
def check(self, item):
if self.qty(item):
for i in self.inv:
if i[0] == item:
return self.inv.index(i) # returns item index (location)
Code: Select all
def heal_hp():
wtg_player.HP += 6
if wtg_player.HP > wtg_player.maxHP:
wtg_player.HP = wtg_player.maxHP
- DannyGMaster
- Regular
- Posts: 113
- Joined: Fri Sep 02, 2016 11:07 am
- Contact:
Re: Making hp heal potions
The problem doesn't seem to be here. I was referring also to the code of the screen, where the icon is shown
(I presume as an imagebutton) and when the clicking process occurs.
(I presume as an imagebutton) and when the clicking process occurs.
The silent voice within one's heart whispers the most profound wisdom.
Re: Making hp heal potions
i don't created a specific screen to the potion, the icon appears in the inventory screen by the call "icon" in the item and inventory code, but if you want to see the screeen inventory i will leave it hereDannyGMaster wrote: ↑Thu Aug 31, 2017 9:11 am The problem doesn't seem to be here. I was referring also to the code of the screen, where the icon is shown
(I presume as an imagebutton) and when the clicking process occurs.
Code: Select all
screen inventory_screen(first_inventory, second_inventory=False, trade_mode=False, bank_mode=False):
default crafting_screen = False
tag menu
modal False
frame yalign 0.41 xalign 1.0:
hbox:
textbutton "{color=#FFFFFF}Fechar Inventário{/color}" action [ Hide("inventory_screen"), Show("mochila")]
frame yalign 0.0 xalign 0.367:
style_group "invstyle"
hbox:
spacing 25
vbox:
label first_inventory.name
if not second_inventory:
text "Ouro: [first_inventory.money]"
if second_inventory:
use money(first_inventory, second_inventory, bank_mode)
use inventory_view(first_inventory, second_inventory, trade_mode)
use view_nav(first_inventory)
use sort_nav(first_inventory)
if not second_inventory:
textbutton "Modo de Criação" action ToggleScreenVariable("crafting_screen")
if second_inventory:
vbox:
label second_inventory.name
use money(second_inventory, first_inventory, bank_mode)
use inventory_view(second_inventory, first_inventory, trade_mode)
use view_nav(second_inventory)
use sort_nav(second_inventory)
if crafting_screen:
use crafting(first_inventory)
screen inventory_view(inventory, second_inventory=False, trade_mode=False):
side "c r":
style_group "invstyle"
area (0, 0, 400, 360)
vpgrid id ("vp"+inventory.name):
draggable True
mousewheel True
xsize 350 ysize 460
if inventory.grid_view:
cols 3 spacing 10
else:
cols 1 spacing 25
for item in inventory.inv:
$ name = item[0].name
$ desc = item[0].desc
$ value = item[0].value
$ qty = str(item[1])
hbox:
if item[0].icon:
$ icon = item[0].icon
$ hover_icon = im.Sepia(icon)
imagebutton:
idle LiveComposite((100,100), (0,0), icon, (0,0), Text(qty))
hover LiveComposite((100,100), (0,0), hover_icon, (0,0), Text(qty))
action (If(not second_inventory, item[0].act, (If(trade_mode, Function(trade,inventory, second_inventory, item), Function(transaction,inventory, second_inventory, item)))))
hovered Show("tooltip",item=item,seller=second_inventory)
unhovered Hide("tooltip")
if not inventory.grid_view:
vbox:
text name
if not trade_mode:
text "Lista de Valor: [value]"
if second_inventory:
text ("Valor de venda: " + str(calculate_price(item, second_inventory)) + ")")
else:
textbutton "[Nome] ([Nº])" action (If(not second_inventory, item[0].act,(If(trade_mode, Function(trade,inventory, second_inventory, item), Function(transaction,inventory, second_inventory, item))))) hovered Show("tooltip",item=item,seller=second_inventory) unhovered Hide("tooltip")
if not inventory.grid_view:
vbox:
text "Lista de Valor: [value]"
if not trade_mode and second_inventory:
text "Valor de venda: " + str(calculate_price(item, second_inventory)) + ")"
## maintains spacing in empty inventories.
if len(inventory.inv) == 0:
add Null(height=100,width=100)
vbar value YScrollValue("vp"+inventory.name)
- DannyGMaster
- Regular
- Posts: 113
- Joined: Fri Sep 02, 2016 11:07 am
- Contact:
Re: Making hp heal potions
Okay, the only suspicious part I see is still the $ marks here:
Remove them and see if it now works correctly. If it doesn't, then the problem is somewhere else and if that were the case, I wouldn't really know how to help you.
Code: Select all
$ name = item[0].name
$ desc = item[0].desc
$ value = item[0].value
$ qty = str(item[1])
hbox:
if item[0].icon:
$ icon = item[0].icon
$ hover_icon = im.Sepia(icon)
The silent voice within one's heart whispers the most profound wisdom.
Re: Making hp heal potions
he give me a errorDannyGMaster wrote: ↑Thu Aug 31, 2017 10:05 am Okay, the only suspicious part I see is still the $ marks here:
Remove them and see if it now works correctly. If it doesn't, then the problem is somewhere else and if that were the case, I wouldn't really know how to help you.Code: Select all
$ name = item[0].name $ desc = item[0].desc $ value = item[0].value $ qty = str(item[1]) hbox: if item[0].icon: $ icon = item[0].icon $ hover_icon = im.Sepia(icon)
Code: Select all
[code]
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 113, in script
"Você se encontra em uma vila vazia, que parece estar abandonada, pois apesar de ser dia não se vê uma pessoa nas ruas e há diversos pertences abandonados."
File "game/inventory.rpy", line 161, in execute
screen inventory_screen(first_inventory, second_inventory=False, trade_mode=False, bank_mode=False):
File "game/inventory.rpy", line 161, in execute
screen inventory_screen(first_inventory, second_inventory=False, trade_mode=False, bank_mode=False):
File "game/inventory.rpy", line 169, in execute
frame yalign 0.0 xalign 0.367:
File "game/inventory.rpy", line 171, in execute
hbox:
File "game/inventory.rpy", line 173, in execute
vbox:
File "game/inventory.rpy", line 179, in execute
use inventory_view(first_inventory, second_inventory, trade_mode)
File "game/inventory.rpy", line 195, in execute
screen inventory_view(inventory, second_inventory=False, trade_mode=False):
File "game/inventory.rpy", line 195, in execute
screen inventory_view(inventory, second_inventory=False, trade_mode=False):
File "game/inventory.rpy", line 196, in execute
side "c r":
File "game/inventory.rpy", line 199, in execute
vpgrid id ("vp"+inventory.name):
File "game/inventory.rpy", line 207, in execute
for item in inventory.inv:
File "game/inventory.rpy", line 209, in execute
imagebutton:
File "game/inventory.rpy", line 209, in keywords
imagebutton:
NameError: name 'qty' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 113, in script
"Você se encontra em uma vila vazia, que parece estar abandonada, pois apesar de ser dia não se vê uma pessoa nas ruas e há diversos pertences abandonados."
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\ast.py", line 613, in execute
renpy.exports.say(who, what, interact=self.interact)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\exports.py", line 1147, in say
who(what, interact=interact)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\character.py", line 877, in __call__
self.do_display(who, what, cb_args=self.cb_args, **display_args)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\character.py", line 716, in do_display
**display_args)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\character.py", line 508, in display_say
rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\ui.py", line 285, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 2526, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 2793, in interact_core
root_widget.visit_all(lambda i : i.per_interact())
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 495, in visit_all
d.visit_all(callback)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 495, in visit_all
d.visit_all(callback)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 495, in visit_all
d.visit_all(callback)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\screen.py", line 399, in visit_all
callback(self)
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 2793, in <lambda>
root_widget.visit_all(lambda i : i.per_interact())
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\screen.py", line 409, in per_interact
self.update()
File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\screen.py", line 578, in update
self.screen.function(**self.scope)
File "game/inventory.rpy", line 161, in execute
screen inventory_screen(first_inventory, second_inventory=False, trade_mode=False, bank_mode=False):
File "game/inventory.rpy", line 161, in execute
screen inventory_screen(first_inventory, second_inventory=False, trade_mode=False, bank_mode=False):
File "game/inventory.rpy", line 169, in execute
frame yalign 0.0 xalign 0.367:
File "game/inventory.rpy", line 171, in execute
hbox:
File "game/inventory.rpy", line 173, in execute
vbox:
File "game/inventory.rpy", line 179, in execute
use inventory_view(first_inventory, second_inventory, trade_mode)
File "game/inventory.rpy", line 195, in execute
screen inventory_view(inventory, second_inventory=False, trade_mode=False):
File "game/inventory.rpy", line 195, in execute
screen inventory_view(inventory, second_inventory=False, trade_mode=False):
File "game/inventory.rpy", line 196, in execute
side "c r":
File "game/inventory.rpy", line 199, in execute
vpgrid id ("vp"+inventory.name):
File "game/inventory.rpy", line 207, in execute
for item in inventory.inv:
File "game/inventory.rpy", line 209, in execute
imagebutton:
File "game/inventory.rpy", line 209, in keywords
imagebutton:
File "<screen language>", line 211, in <module>
NameError: name 'qty' is not defined
Windows-7-6.1.7601-SP1
Ren'Py 6.99.12.4.2187
A Tale of Truths and Lies Demo 1.4.5
- DannyGMaster
- Regular
- Posts: 113
- Joined: Fri Sep 02, 2016 11:07 am
- Contact:
Re: Making hp heal potions
Okay, you probably did not understand, sorry about that.
Just to be sure, I wanted you to take out only the $, not the entire lines. It would end up looking like this:
Just to be sure, I wanted you to take out only the $, not the entire lines. It would end up looking like this:
Code: Select all
name = item[0].name
desc = item[0].desc
value = item[0].value
qty = str(item[1])
hbox:
if item[0].icon:
icon = item[0].icon
hover_icon = im.Sepia(icon)
The silent voice within one's heart whispers the most profound wisdom.
Who is online
Users browsing this forum: Ahrefs [Bot], Andredron, Google [Bot]