AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

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
McRad
Regular
Posts: 28
Joined: Wed Oct 14, 2015 5:52 pm
Projects: Eastbound Stars: The Drowning Halls
Contact:

AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#1 Post by McRad »

Hello everybody! I am trying to work on my game, but I have been stuck on this error that I can't wrap my head around.

TLDR; Version of my issue:

I'm making an inventory system for the game and I have decided to use classes in order to streamline things and for it to work better down the line. I am using classes for both the character stats and the inventory...

My issue comes up with a certain attribute I put in...

This attribute contains a small set which refers to individual slots of armor the character can put on.

I have used the SetVariable function in order to fill the "helm" portion of the armor slot.

Code: Select all

SetVariable (MC.armor["helm"], itemselect)
I don't fully comprehend the meaning of this error message (I only assume that I did something wrong that Renpy didn't like/couldn't handle)

Full Code:
character definition

Code: Select all

init python:
    class Player:
        def __init__(self, hp, mp, ki, mood, level):
            self.hp = hp
            self.max_hp = hp
            self.mp = mp
            self.max_mp = mp
            self.ki = ki
            self.max_ki = ki
            self.mood = mood
            self.armor = {"helm": None, "chest": None, "legs": None, "arms": None}
            self.weapon = None
            level = level
            
    MC = Player (100, 0, 0, "Neutral", 1)
items

Code: Select all

init python:
    class items:
        def __init__(self, name, weight, price):
            self.name = name
            self.weight = int(weight)
            self.price = int(price)
            
init python:
    class armor(items):
        def __init__(self, name, weight, price, defense, type):
            items.__init__(self, name, weight, price)
            self.defense = int(defense)
            self.type = type
            
init python:
    class Armory:
        def __init__(self):
            self.inventory =[]
            
    armory = Armory()
inventory screen

Code: Select all

screen armoryscreen():
    modal True
    imagebutton auto "background_%s" action SetVariable ("itemselect", "Empty")
    text "Normal Items"
    textbutton "Close" xpos .05 ypos .9 action [Hide ('armoryscreen')]
    textbutton "Key Items" action [Hide ("armoryscreen"), Show ('inventoryscreen')] xpos 0.85 ypos .9
    vpgrid:
        ypos .1
        xpos .3
        cols 2
        xspacing 200
        yspacing 5
        for items in armory.inventory:
            textbutton "[items.name]" action SetVariable ("itemselect", items)
        for i in range(len(armory.inventory), 20):
            vbox
    if isinstance(itemselect, armor):
        if itemselect.type == "helm":
            textbutton "Equip Helm" action SetVariable (MC.armor["helm"], itemselect) xpos 0.85 ypos .2
            textbutton "Unequip Helm" action SetVariable (MC.armor["helm"], None) xpos 0.85 ypos .3

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#2 Post by PyTom »

Can you post the full traceback, please?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#3 Post by philat »

Lots of minor issues in what you've posted, but pretty sure this is an issue of SetVariable needing a string ("MC.armor['helm']").

McRad
Regular
Posts: 28
Joined: Wed Oct 14, 2015 5:52 pm
Projects: Eastbound Stars: The Drowning Halls
Contact:

Re: AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#4 Post by McRad »

philat wrote: Fri Jun 21, 2019 12:26 am Lots of minor issues in what you've posted, but pretty sure this is an issue of SetVariable needing a string ("MC.armor['helm']").
Nope... Renpy crashes when loading the game and it says it's a syntax issue... So I'm positive it's not that...

PyTom wrote: Thu Jun 20, 2019 11:58 pm Can you post the full traceback, please?
Sure, I've added it down below
traceback.txt
(3.33 KiB) Downloaded 15 times

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#5 Post by philat »

I am really pretty sure it is. MC.armor["helm"], which you are supplying to SetVariable, is None by default. The error is saying saying None doesn't have the method rpartition, which SetVariable is trying to call because it's set up to take strings. I mean, it could technically be something else but the error is pretty clear - there's a None where a string is required.

McRad
Regular
Posts: 28
Joined: Wed Oct 14, 2015 5:52 pm
Projects: Eastbound Stars: The Drowning Halls
Contact:

Re: AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#6 Post by McRad »

philat wrote: Fri Jun 21, 2019 12:33 am I am really pretty sure it is. MC.armor["helm"], which you are supplying to SetVariable, is None by default. The error is saying saying None doesn't have the method rpartition, which SetVariable is trying to call because it's set up to take strings. I mean, it could technically be something else but the error is pretty clear - there's a None where a string is required.
Well, I tried fixing it (I'm pretty sure you meant that I shouldn't use None and should make up items that do nothing instead) and it said:
AttributeError: 'armor' object has no attribute 'split'

I am unsure how this factors in... but your guess is probably better than mine

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#7 Post by philat »

...no, I said SetVariable takes a string as the first argument. https://www.renpy.org/doc/html/screen_a ... etVariable

Code: Select all

SetVariable("MC.armor['helm']", itemselect)

McRad
Regular
Posts: 28
Joined: Wed Oct 14, 2015 5:52 pm
Projects: Eastbound Stars: The Drowning Halls
Contact:

Re: AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#8 Post by McRad »

philat wrote: Fri Jun 21, 2019 12:58 am ...no, I said SetVariable takes a string as the first argument. https://www.renpy.org/doc/html/screen_a ... etVariable

Code: Select all

SetVariable("MC.armor['helm']", itemselect)
Okay, I see what you're saying now...

However Renpy has gone to say that MC.armor['helm'] doesn't exist

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#9 Post by philat »

It's relatively recent that SetVariable supports object attributes out of the box anyway, so it may not support a dictionary as an object attribute. *shrug* I hadn't bothered trying. Quick test seems to show that SetDict(MC.armor, "helm", itemselect) is probably what you want.

McRad
Regular
Posts: 28
Joined: Wed Oct 14, 2015 5:52 pm
Projects: Eastbound Stars: The Drowning Halls
Contact:

Re: AttributeError: 'nonetype' object has no attribute 'rpartition' after I change a variable in a set in a class

#10 Post by McRad »

philat wrote: Fri Jun 21, 2019 1:36 am It's relatively recent that SetVariable supports object attributes out of the box anyway, so it may not support a dictionary as an object attribute. *shrug* I hadn't bothered trying. Quick test seems to show that SetDict(MC.armor, "helm", itemselect) is probably what you want.
Thank you! It seems to work perfectly now!

Post Reply

Who is online

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