TypeError: list indicies must be integers or slices, not NoneType [SOLVED]

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
KINJA
Newbie
Posts: 9
Joined: Mon May 13, 2024 5:14 pm
Contact:

TypeError: list indicies must be integers or slices, not NoneType [SOLVED]

#1 Post by KINJA »

PREMISE:

Hello!

I made a horror game that came out on Steam recently, and I'm looking into making some DLC for it. A feature of the DLC is the use of a radio. Here's what the bare bones version of the radio's interface looks like:

Image

How this works is that it uses a set of screens, one that is the radio itself, and a custom bar slider that acts as the tuner. The numbers above the bar correspond to the current radio station, which is important to this section of the game. Here's the code I've made to create this screen:

Code: Select all

screen Leave:
    frame:
        align (.79,.8)
        padding (20,10)
        textbutton "LEAVE" action Jump("AnotherDay"):
            activate_sound "audio/typeClick.mp3"

init python:
    signals = [
        101.1, 101.2, 101.3, 101.4,
        102.1, 102.2, 102.3, 102.4,
        103.1, 103.2, 103.3, 103.4,
        104.1, 104.2, 104.3, 104.4
        ]
    persistent.signal = 0
    stationNum = persistent.signal
    currentSignal = signals[stationNum]

screen radioBar2:
    bar:
        value FieldValue(persistent, "signal", 15, style="radio_slider", step=1, force_step = False)
        align (.5,.5)
        xsize 600
        ysize 35
        thumb "gui/slider/rad_thumb.png"
        thumb_offset 32
        left_gutter 13
        right_gutter 13

screen cellRadio():
    $ stationNum = persistent.signal
    $ currentSignal = signals[stationNum]
    frame:
        align (0.5,0.5)
        padding (100,80)
        vbox:
            spacing 30
            frame:
                align (.5,.5)
                padding (25,15)
                text "[currentSignal]" size 50 font "fonts/digital-7.ttf"
            use radioBar2

    use Leave
    
label radioScreen:
    call screen cellRadio
    
THE PROBLEM:

Here's the issue: When the cellRadio screen is open, and I go to the pause menu, there's an issue when I come back, but ONLY from the Options screen (the EXACT same screen as the 'Preferences' screen in a vanilla Ren'py project found in screens.rpy). When I right click and go to Options, and then right click to close it and come back to the gameplay, it will return an error. The error is the same as the subject line for this post: TypeError: list indicies must be integers or slices, not NoneType. For anyone curious, here's exactly what the error screen looks like:

Image

The main question is this: Why do the Options screen and the cellRadio screen have issues with each other? I've tried deleting and altering certain values used in cellRadio, but nothing really changes. Curiously, deleting $ stationNum = persistent.signal and $ currentSignal = signals[stationNum] results in a different error:

Image

TROUBLESHOOTING:

I've tried a bit of troubleshooting on my end. I think this is because something in the 'signals' list is turning up as "None," or that the range I'm using is too large, but I haven't found any significant change that stops either error. Because this ONLY happens with the Options screen, I assumed it might be an issue with the bars on that screen and the cellRadio screen. I've tried using different bar settings like StaticValue instead of FieldValue, and while the radio still functioned after making the proper edits, it still turned up the same error.

Apologies if this is a long post, but I'd like to get this issue resolved soon, and wanted to make sure I provided as many different facets of the issue as possible. Thanks in advance to anyone who has any info on this issue!
Last edited by KINJA on Tue May 14, 2024 2:43 pm, edited 1 time in total.
None of the Avengers help Blade out with the literal hordes of vampires that walk the Earth and that's genuinely insane to me.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1034
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: TypeError: list indicies must be integers or slices, not NoneType

#2 Post by m_from_space »

KINJA wrote: Tue May 14, 2024 12:06 am Apologies if this is a long post, but I'd like to get this issue resolved soon, and wanted to make sure I provided as many different facets of the issue as possible. Thanks in advance to anyone who has any info on this issue!
So it looks like your "stationNum" suddenly appears to be of NoneType, instead of being an integer. The first thing that comes to mind is that you define variables inside a python block. I always tell people to better not do that, because Renpy treats all of them as constants. I have no clue if this really is the issue here, but better declare your variables like this (outside of a python block of course):

Code: Select all

define signals = [
        101.1, 101.2, 101.3, 101.4,
        102.1, 102.2, 102.3, 102.4,
        103.1, 103.2, 103.3, 103.4,
        104.1, 104.2, 104.3, 104.4
        ]
default persistent.signal = 0
default stationNum = persistent.signal
default currentSignal = signals[stationNum]
You may also want to update Renpy if you are using an older version. Let me know if that fixes the issue! If not, please post your "options" screen here.

User avatar
KINJA
Newbie
Posts: 9
Joined: Mon May 13, 2024 5:14 pm
Contact:

Re: TypeError: list indicies must be integers or slices, not NoneType

#3 Post by KINJA »

m_from_space wrote: Tue May 14, 2024 4:04 am
KINJA wrote: Tue May 14, 2024 12:06 am Apologies if this is a long post, but I'd like to get this issue resolved soon, and wanted to make sure I provided as many different facets of the issue as possible. Thanks in advance to anyone who has any info on this issue!
So it looks like your "stationNum" suddenly appears to be of NoneType, instead of being an integer. The first thing that comes to mind is that you define variables inside a python block. I always tell people to better not do that, because Renpy treats all of them as constants. I have no clue if this really is the issue here, but better declare your variables like this (outside of a python block of course):

Code: Select all

define signals = [
        101.1, 101.2, 101.3, 101.4,
        102.1, 102.2, 102.3, 102.4,
        103.1, 103.2, 103.3, 103.4,
        104.1, 104.2, 104.3, 104.4
        ]
default persistent.signal = 0
default stationNum = persistent.signal
default currentSignal = signals[stationNum]
You may also want to update Renpy if you are using an older version. Let me know if that fixes the issue! If not, please post your "options" screen here.
So this is what I had originally! I thought putting them in a python block would help, but it didn't seem to.

However! I changed it back to define/default, and while I still got the error, updating Ren'py actually solved the issue!! I knew it was going to end up being something simple that I was missing haha, thanks a bunch dude!
None of the Avengers help Blade out with the literal hordes of vampires that walk the Earth and that's genuinely insane to me.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]