[SOLVED]list indices must be integers not (CLASS NAME)

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
Killverin
Newbie
Posts: 10
Joined: Wed May 25, 2022 4:45 pm
Contact:

[SOLVED]list indices must be integers not (CLASS NAME)

#1 Post by Killverin » Sat Sep 17, 2022 7:04 pm

So, I've a tangled system for managing special attributes like defense, ect, that go up and down during combat. It works great with multiple effects on multiple enemies, but only if they're applied to one enemy per turn. Then I made a smoke bomb.

Code: Select all

elif pick == "hurt":              #<----- The button sends us here, a function has loaded all the special damage and regular damage, now we pick a target
                    $ pick = ui.interact()
                    $ enemies[pick]["crnt_hp"] -= LoadDam         #<-------- From the list of active enemies, the pick now suffers effects, both regular and special.
                    $ enemies[pick]["grit"] -= LoadGritDam
                    if LoadGritDam >= 0: #Nested to 9                 #<----- Here we load up special attribute damage that will be returned after a clock runs out
                        if FloatingGrit1 == 0:                                     
                            $ FloatingGrit1 += LoadGritDam
                            $ FloatingTarget1 = pick
                        elif FloatingGrit2 == 0:      #<--- this goes on 9 times
                    $ Grit_Check()      #<--Here, the  numbers are assigned to their clocks. [pick == "hurt"] has no issues here. This block is the last shown in the post.                   
The way these special damage numbers are assigned to their clocks works fine, and I can see it fill up my Grit_Check() with no issues round after round, and it all returns fine. Then I add blanket effects, it needs to hit all targets on the board.

Code: Select all

elif pick == "blanket":                   # <------- Returns "blanket" from ui.interact() so we know it applies to all enemies
                    if enemies[0] == True enemies[0].crnt_hp >= 0:
                        $ current_blanket_enemy1 = enemies[0]
                        if current_blanket_enemy1["crnt_hp"] > 0:
                            $ current_blanket_enemy1["crnt_hp"] -= LoadDam
                            $ current_blanket_enemy1["grit"] -= LoadGritDam
                            $ AmbGrt.amount -= LoadGritDam
                            if LoadGritDam >= 0: #Nested to 9
                                if FloatingGrit1 == 0:
                                    $ FloatingGrit1 += LoadGritDam
                                    $ FloatingTarget1 = current_blanket_enemy1
                                elif FloatingGrit2 == 0:     #<----------this goes on for 9 cycles, but assigns a quantity of grit to be returned after a clock runs out.
                     if enemies[1] == True and enemies[1].crnt_hp >= o:    #<--- It goes on for as many enemies as can be in a battle.
                     		Then after all
                           $ Grit_Check()    #<---- after "blanket" Grit_Check() throws the title error "list indices must be integers not NPC. Where is shown below.
                      
Like I said, the below function works great one at a time. i can read that a lot of timers are active at once. When I try to get more than one running in a turn, throws the error.

Code: Select all

def Grit_Check():
	global GritTimer1
        global FloatingGrit1
        global FloatingTarget1
        if GritTimer1 == 0 and FloatingGrit1 >= 0:
            enemies[FloatingTarget1]["grit"] += FloatingGrit1   <---#As I've said, "hurt" can fill this whole block to the 9s, literally, with no issue. Even "blanket"
           AmbGrt.amount += FloatingGrit1                          #can assign its first GritTimer with no problem. If I've assigned GritTimer1 with "hurt" then
            FloatingGrit1 = 0                                      #"blanket" will assign its first target to GritTimer2 and fall over on GritTimer 3
            FloatingTarget1 = 0
        if GritTimer1 <= 0:
            GritTimer1 = 0
        global GritTimer2
        global FloatingGrit2
        global FloatingTarget2
        if GritTimer2 == 0 and FloatingGrit2 >= 0:
            enemies[FloatingTarget2]["grit"] += FloatingGrit2      # <-------Here is where we see the error, if i run a blanket with not GritTimer1 active
            AmbGrt.amount += FloatingGrit2                                                 # "list indices must be integers not NPC"
            FloatingGrit2 = 0
            FloatingTarget2 = 0
        if GritTimer2 <= 0:
            GritTimer2 = 0
        global GritTimer3 .......    #<---------- This also goes on 9 times
So there it is. Any ideas as to what I'm doing wrong?
Bonus question, why isn't [if enemies[0] == True] working? The only reason I'm not doing an index and [len(enemies)] is to see if that was my problem, but now I'm curious.
Any help appreciated.
I'm an ignorant fool. Thanks for reading :)
Last edited by Killverin on Sat Sep 17, 2022 9:31 pm, edited 1 time in total.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1882
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: list indices must be integers not (CLASS NAME)

#2 Post by Ocelot » Sat Sep 17, 2022 7:33 pm

YOur main problem: you write the same code several times. By doing that you can accidently write them somewhat differently, which might lead to problems. If you have problems, see what is different btween those pieces of code.
I just point one difference:

Code: Select all

$ enemies[pick]["crnt_hp"] -= LoadDam 
$ FloatingTarget1 = pick
# . . .
$ current_blanket_enemy1["crnt_hp"] -= LoadDam
$ FloatingTarget1 = current_blanket_enemy1
Second line in both snippets is the same (if you ignore varable names). The first one is different. This is a sign of problem. Why are they different? What exactly those variables contain and how they are related. Why don't you write pick["crnt_hp"] -= LoadDam in first case or enemies[current_blanket_enemy1]["crnt_hp"] -= LoadDam in second?
When you'll understand that, the cause of error will be apparent.

Code: Select all

if enemies[0] == True enemies[0].crnt_hp >= 0:
showl not work as written at all. If you ignore that, enemies[0] == True will resolve to True if you stored True there before and not in other cases.
If you tell, what exactly you were hoping to achieve, I will be able to tell what is more appropriate here instead.
< < insert Rick Cook quote here > >

Killverin
Newbie
Posts: 10
Joined: Wed May 25, 2022 4:45 pm
Contact:

Re: list indices must be integers not (CLASS NAME)

#3 Post by Killverin » Sat Sep 17, 2022 9:30 pm

That sent me chasing quite a lot, but your help has solved my problem.

I've moved past the bonus problem like I said, reimplemented index +1 len(enemies) loop. But The idea was that some battles wouldn't have 3 enemies, so I didn't want it to fire if there weren't that many items in the list. So if enemies[1] is there.

You were a big help, thanks so much.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]