[SOLVED] error: 'int' object has no attribute '__getitem__'

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
jbguyman
Newbie
Posts: 2
Joined: Mon Jan 08, 2018 3:26 pm
Contact:

[SOLVED] error: 'int' object has no attribute '__getitem__'

#1 Post by jbguyman »

hey everyone! im really new to the whole renpy coding thing but i have been expirimenting with it for about 2 weeks now. i was trying to create a combat system for an idea i had but i keep getting the error it the title. i was wondering how to fix it but i (clearly) havent been able to, so i thought i would try to get help. here is my code (sorry if it is badly written):

Code: Select all

define m = Character("mc")
define b = Character("enemy")



screen stat_test:
    frame:
        xalign 0.01 yalign 0.05
        xminimum 220 xmaximum 220
        vbox:
            text "main character" size 2 xalign 0.5
            null height 5
            hbox:
                bar:
                    maximum 130
                    value mc_hp1
                    range mc_max_hp1
                    left_gutter 0
                    right_gutter 0
                    thumb None
                    thumb_shadow None
                    
                null width 5
                
                text "[mc_hp1] / [mc_max_hp1]" size 16
                
                
    frame:
        xalign 0.99 yalign 0.05
        xminimum 220 xmaximum 220
        vbox:
            text "enemy" size 2 xalign 0.5
            null height 5
            hbox:
                bar:
                    maximum 130
                    value em_hp1
                    range en_max_hp1
                    left_gutter 0
                    right_gutter 0
                    thumb None
                    thumb_shadow None
                    
                null width 5
                
                text "[em_hp1] / [en_max_hp1]" size 16  
                
    


        
        
label start:
    $ mc_hp1 = 100
    $ mc_max_hp1 = 100
    $ em_hp1 = 50
    $ en_max_hp1 = 50
    $ en_dpt1 = 10
    $ mc_dpt1 = 8
    $ mc_def1 = 2
    $ defend1 = False
    show screen stat_test
    while (em_hp1 > 0) and (mc_hp1 > 0):   
        
        menu:
            "Attack!":
                m "i attack"
                $ em_hp1 -= mc_dpt1
                
            "defend":
                m "i defend"
                $ defend1 = True
        
        b "i will slash your neck right off your body!"
        if defend1 == True:
            $ mc_hp1 -= en_dpt1 - mc_def1
        
        else:
            $ mc_hp1 -= en_dpt1
    
    hide screen stat_test
    
    if em_hp1 <= 0:
        if mc_hp1 <= 0:
            "Everybody loses!"
        else:
            m "I win!"
    else:
        b "youre too weak to beat me!"
        
return
thanks in advance!
Last edited by jbguyman on Wed Jan 17, 2018 6:14 pm, edited 1 time in total.

ReDZiX
Regular
Posts: 32
Joined: Thu Jan 04, 2018 12:42 pm
Contact:

Re: error: 'int' object has no attribute '__getitem__'

#2 Post by ReDZiX »

Problem is in your bar, specifically the maximum property. The traceback points to this:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While processing the maximum property of anonymous style: #<--- LOOK HERE
  File "game/script.rpy", line 60, in script
    menu:
TypeError: 'int' object has no attribute '__getitem__'
Maximum expects a list or a tuple containing the maximum width and height of the bar, and you're giving only one number (I'm assuming it's the width). So either use:

Code: Select all

xmaximum 130
Or use a tuple containing height as well:

Code: Select all

maximum (130,20)

jbguyman
Newbie
Posts: 2
Joined: Mon Jan 08, 2018 3:26 pm
Contact:

Re: error: 'int' object has no attribute '__getitem__'

#3 Post by jbguyman »

Thanks, ReDZiX! Youre a lifesaver!

Post Reply

Who is online

Users browsing this forum: dragondatingsim, Google [Bot], Ocelot