[help] conditions

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
elproxxgamer
Newbie
Posts: 9
Joined: Sun Aug 11, 2019 9:53 pm
itch: renpytom
Contact:

[help] conditions

#1 Post by elproxxgamer » Wed Mar 04, 2020 7:17 pm

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

User avatar
rayminator
Miko-Class Veteran
Posts: 558
Joined: Fri Feb 09, 2018 12:05 am
Projects: Redoing games to fix spelling mistakes other companys that don't care
Location: Canada
Contact:

Re: [help] conditions

#2 Post by rayminator » Wed Mar 04, 2020 8:44 pm

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" )
when I try to help someone I point them into 2 direction what's right and wrong so they can learn how to

elproxxgamer
Newbie
Posts: 9
Joined: Sun Aug 11, 2019 9:53 pm
itch: renpytom
Contact:

Re: [help] conditions

#3 Post by elproxxgamer » Wed Mar 04, 2020 9:25 pm

I have no mistake, I just don't know how to make a condition

User avatar
rayminator
Miko-Class Veteran
Posts: 558
Joined: Fri Feb 09, 2018 12:05 am
Projects: Redoing games to fix spelling mistakes other companys that don't care
Location: Canada
Contact:

Re: [help] conditions

#4 Post by rayminator » Wed Mar 04, 2020 11:04 pm

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
when I try to help someone I point them into 2 direction what's right and wrong so they can learn how to

elproxxgamer
Newbie
Posts: 9
Joined: Sun Aug 11, 2019 9:53 pm
itch: renpytom
Contact:

Re: [help] conditions

#5 Post by elproxxgamer » Thu Mar 05, 2020 11:53 am

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

User avatar
rayminator
Miko-Class Veteran
Posts: 558
Joined: Fri Feb 09, 2018 12:05 am
Projects: Redoing games to fix spelling mistakes other companys that don't care
Location: Canada
Contact:

Re: [help] conditions

#6 Post by rayminator » Thu Mar 05, 2020 2:11 pm

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
when I try to help someone I point them into 2 direction what's right and wrong so they can learn how to

Post Reply

Who is online

Users browsing this forum: drKlauz, Google [Bot], SowaKisa