So this is a weird issue I haven't seen before. I was playing around with some simple code for a potion creator game, and I run into this issue where when I make a new text button and assign it an action to activate a function, the function will instead activate automatically, or it will be activated by other buttons.
For example, I have this button:
textbutton "Create" action Function(make_potion(li))
But every other textbutton is now calling the "make_potion" function when I click them. I'm not a code expert, but usually when I do buttons like this the function is only called when I click that actual button. Is there something fundamental I'm missing here? I've attached my code below.
Code: Select all
init python:
import renpy.store as store
class potion(store.object):
def __init__(self,name,attribute_1,attribute_2,desc,strength,cost,recipe):
self.name = name
self.attribute_1 = attribute_1
self.attribute_2 = attribute_2
self.desc = desc
self.strength = strength
self.cost = cost
self.recipe = []
def make_potion(used):
global potion_list
strength = 0
effects = ""
for ingredient in used:
strength += ingredient.strength
effects += ingredient.attribute_1
if "Heal" and "Poison" in effects:
renpy.show_screen("tooltip",message = "Potion failed!")
else:
recipe = used
#new_potion = potion(n,att1,att2,desc,strength,cost,recipe)
#potion_list.append(new_potion)
class ing(store.object):
def __init__(self,name,attribute_1,desc,images,hovers,strength,quantity,input_quantity):
self.name = name
self.attribute_1 = attribute_1
self.strength = strength
self.desc = desc
self.images = images
self.hovers=hovers
self.quantity = quantity
self.input_quantity = input_quantity
def create_ing(self,x):
x.append(self)
def select(self):
global selected_ing
if self.quantity > 0:
if self not in selected_ing:
selected_ing.append(self)
self.quantity -= 1
self.input_quantity += 1
else:
self.quantity -= 1
self.input_quantity += 1
def decrease(self):
global selected_ing
if self.input_quantity == 1:
selected_ing.remove(self)
self.quantity += self.input_quantity
self.input_quantity = 0
else:
self.quantity += 1
self.input_quantity -= 1
def increase(self):
if self.quantity > 0:
self.quantity -= 1
self.input_quantity += 1
default ingredients = []
default selected_ing = []
default potion_list = []
default recipes = []
default starblast = ing("Starblast","Heal","A beautiful flower with an earthy smell.", "images/starblast.png","images/pumpkinseed.png",1,4,0)
default pumpkinseeds = ing("Pumpkin Seeds","Poison","Seeds from a pumpkin.", "images/pumpkinseed.png", "images/starblast.png",1,4,0)
label start:
$ starblast.create_ing(ingredients)
$ pumpkinseeds.create_ing(ingredients)
scene white
call screen ingredient_list(ingredients,selected_ing)
"..."
return
screen tooltip(message):
zorder 5
frame:
background "tooltip_box"
xmaximum 276
ymaximum 77
xfill True
yfill True
# xalign 0.5
# yalign 0.1
# left_padding 20
# top_padding 20
# right_padding 20
# bottom_padding 20
xalign 0.5
ypos 800
text message style "tooltip_style" xalign 0.5 yalign 0.5
timer 3 action Hide("tooltip")
screen ingredient_list(ingredients,li,scroll="vpgrid"):
tag menu
frame:
xalign 0.5
yalign 0.5
xsize 500
ysize 200
vpgrid:
cols 1
xsize 500
ysize 200
yfill True
xfill True
side_yfill True
scrollbars "vertical"
mousewheel True
draggable True
pagekeys True
transclude
for item in li:
$ name = item.name
$ pic = item.images
$ quantity = item.quantity
$ count = item.input_quantity
hbox:
textbutton "<" action Function(item.decrease)
text "[name] [count]"
textbutton ">" action Function(item.increase)
textbutton "Create" action Function(make_potion(li))
frame:
xsize 500
ysize 500
yfill True
xfill True
vpgrid:
cols 4
xsize 500
ysize 500
yfill True
xfill True
side_yfill True
spacing 20
scrollbars "vertical"
mousewheel True
draggable True
pagekeys True
transclude
transclude
for item in ingredients:
$ name = item.name
$ pic = item.images
$ h = item.hovers
$ quantity = item.quantity
$ li = selected_ing
vbox:
imagebutton:
idle pic
hover h
action Function(item.select)
#action item.select(li)
hbox:
spacing 10
text "[name]" style "ing_style" xsize 100
text "([quantity])" style "ing_style" xsize 100
style ing_style:
size 15