TypeError: string indices must be integers

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
User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

TypeError: string indices must be integers

#1 Post by TellerFarsight »

This is a simplified version of the code I'm using, but hopefully everything important is here. When I try to run the full code, I get "TypeError: string indices must be integers", referring to the line indicated here. I think it's because I'm misunderstanding "for m in mails". Any ideas?

Code: Select all

screen mailbox():
    modal True
    add "gui/nvl.png"
    style_prefix "mailbox"
    button:
        area (10,70,260,50)
        text "Main Folder"
        action Show("mailbox3a", mails="mainfolder")
screen mailbox3a(mails):
    tag mailbox3
    style_prefix "mailbox3"
    frame:
        area(10,150,630,300)
        vbox:
            for m in mails:
                button:  ### This is the line the error refers to ###
                    hbox:
                        text m["sender"]
                        text m["subject"]
                    action Show("email_display", folder="Main Folder", sender=m["sender"], subject=m["subject"], email=m["email"])

label start:
    $ mainfolder = [
        {"sender":"Eileen",
            "subject":"Maily Mail",
            "email":"Bla Bla Bla",},
        {"sender":"Lucy",
            "subject":"Testing",
            "email":"Bleep Bloop",}
        ]

    show screen mailbox
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: TypeError: string indices must be integers

#2 Post by Remix »

action Show("mailbox3a", mails="mainfolder")

You are passing mails in as a string, where you really want a variable name...

action Show("mailbox3a", mails=mainfolder)
Frameworks & Scriptlets:

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: TypeError: string indices must be integers

#3 Post by trooper6 »

A few things.

1) I know I've told you this before, and I feel like it is all I say, but define your variables using default. So that mainfolder variable you are defining inside lable start should be defined outside of the label using default. And ANY variable you are using should be defined using default outside of a label. So that should be fixed.
2) In your mailbox screen you pass in a string called "mainfolder", you don't pass in the mainfolder object. So take the quotation marks out. But first make sure you are defining your variable using default.

Edit: Remix Ninja'd me. But didn't mention you still need to fix your variable declaration.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: TypeError: string indices must be integers

#4 Post by TellerFarsight »

Thanks both of you for the help; I didn't know which string was causing the issue

and yes trooper, I went back through my entire code to define all the variables with default. It was causing me some problems before but I don't even remember why at this point. You may need to beat "define variables outside labels with default" into me again one day, but I'll get it eventually.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: TypeError: string indices must be integers

#5 Post by TellerFarsight »

Code: Select all

default mainfolder = [{"sender":"N","subject":"L","email":"B",},]
Any idea how to have the default be that it displays nothing?
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: TypeError: string indices must be integers

#6 Post by DannyGMaster »

TellerFarsight wrote:
Any idea how to have the default be that it displays nothing?
You mean like make it display no text? Make the values empty strings.

Code: Select all

default mainfolder = [{"sender":" ","subject":" ","email":" ",},]
The silent voice within one's heart whispers the most profound wisdom.

Post Reply

Who is online

Users browsing this forum: 3N16M4, munni, Ocelot