Page 1 of 1

[help] conditions

Posted: Wed Mar 04, 2020 7:17 pm
by elproxxgamer
Hi, does anyone know how I put a condition on my inventory example: if I have 2 chocolates that eliminate one.
It is for a trading system

Code: Select all

screen inventory_screen():
    imagebutton:
        idle "frame"
        action Show ("inventario")
    
           

            
           
        
screen inventario:
    
   
    modal True 
    hbox align (0.9,0.0):
        textbutton "Close Inventory":
            
            action [ Hide("inventario"),
                     Show("inventory_screen"),
                     Return(None)]
    frame align (0.4,0.1):
        add "inventory"align (0.48,0.23)
        style_group "invstyle"
        area (0.3, 0.07, 500, 500)
        vbox :
            for idx, item in enumerate(myBackpack.mySet): 
                hbox: 
                    for x in range(3):
                        if len(myBackpack.mySet)>x+idx*3:
                            text (str(myBackpack.mySet[x+(idx*3)].amount)) 
                            add myBackpack.mySet[x+(idx*3)].image
                
                     
                     
                    
              
    
            
            
    
init -1 python:
    class Item(object):
        def __init__(self, name, cost, wt, damage, image, amount=0, **kwargs):
            
            self.name = name
            self.cost = cost
            self.wt = wt
            self.damage = damage
            self.image = image
            self.amount = amount
            
    class Backpack(object):
        def __init__(self, maxwt, gold, **kwargs):
            self.maxwt = maxwt
            self.space_left = maxwt
            self.mySet = []
            self.gold = gold
            
        def add_Item(self, item, found=False):
            if item.wt <= self.space_left and (item.cost <= self.gold or found):
                if self.foundItemByName(item)==False:
                    self.mySet.append(item)
                else:
                    item = self.foundItemByName(item)
                self.space_left -= item.wt
                item.amount += 1
                if not found:
                    self.gold -= item.cost
                return "{0} added to inventory.".format(item.name)
            else:
                if item.wt > self.space_left:
                    return "There is not enough space in your inventory!"
                elif item.cost > self.gold:
                    return "You don't have enough gold!"
                else:
                    return "There is some problem here."

        def foundItemByName(self, item):
            for x in self.mySet:
                
                if x.name==item.name:
                    return x
            return False
        
        def remove_Item(self, item):
            if item in self.mySet:
                item.amount -= 1
                self.space_left += item.wt
                if item.amount == 0:
                    self.mySet.remove(item)
                return "{0} removed.".format(item.name)
            else:
                return "{0} not in inventory!".format(item.name)
      
#Variable declarations
default self.mySet = []
default myBackpack = Backpack(50, 50)
default money = 50
default chocolate = Item("chocolatee", 0, 0, 0, "chocolate" )
default banana = Item("banana",0 ,0 , 0, "inv_banana")
default lacer = Item("lacer",0 ,0 , 0, "inv_laser")
default arma = Item("arma",0 ,0, 0, "inv_gun")

# The game starts here.
label start:  
   
    show screen inventory_screen()
    $result = myBackpack.add_Item(banana)    
    $result = myBackpack.add_Item(chocolate)
    $result = myBackpack.add_Item(lacer)
    $result = myBackpack.add_Item(arma)
    $result = myBackpack.add_Item(chocolate)
    $result = myBackpack.add_Item(chocolate)
    $result = myBackpack.add_Item(arma)
    $result = myBackpack.remove_Item(chocolate)
    "hello"

                          
    return

Re: [help] conditions

Posted: Wed Mar 04, 2020 8:44 pm
by rayminator
you do have a spelling mistake here it might be the problem it properly not though

Code: Select all

default chocolate = Item("chocolatee", 0, 0, 0, "chocolate" )

Re: [help] conditions

Posted: Wed Mar 04, 2020 9:25 pm
by elproxxgamer
I have no mistake, I just don't know how to make a condition

Re: [help] conditions

Posted: Wed Mar 04, 2020 11:04 pm
by rayminator
elproxxgamer wrote: Wed Mar 04, 2020 9:25 pm I have no mistake, I just don't know how to make a condition
this what conditions are and chocolate doesn't end with 2 e's

https://www.renpy.org/doc/html/conditio ... statements

Examples are:

Code: Select all

if flag:
    e "You've set the flag!"

if points >= 10:
    jump best_ending
elif points >= 5:
    jump good_ending
elif points >= 1:
    jump bad_ending
else:
    jump worst_ending

Re: [help] conditions

Posted: Thu Mar 05, 2020 11:53 am
by elproxxgamer
I don't know how to apply it to the code in which list I have to look for that condition.
example:

Code: Select all

if ------- <= 1:
	$ result = myBackpack.remove_Item (chocolate)
else:
	"You have nothing to give."
It is understood, I don't have to put in front of the if

Re: [help] conditions

Posted: Thu Mar 05, 2020 2:11 pm
by rayminator
this might help you more on that

Inventory System (or: How to Store Data in a Useful Way)
viewtopic.php?f=51&t=44730#p458992

ConditionSwitch tutorial
viewtopic.php?f=51&t=19063#p246889