[Solved] Inventory and Character Stats Screen, __init error when saving and loading?

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
felisselita
Newbie
Posts: 16
Joined: Thu Jul 21, 2011 12:26 am
Completed: "Starstorm", a BL visual novel game
Tumblr: felisselita
Deviantart: felisselita
itch: felis-selita
Contact:

[Solved] Inventory and Character Stats Screen, __init error when saving and loading?

#1 Post by felisselita » Mon Mar 18, 2019 12:26 am

Hello.

I was using the inventory and character stats system made by Remix >> viewtopic.php?f=51&t=47911
and tried to put the character's stats and inventory in some screens.

I made some characters and put them into a list.

Code: Select all

define character.mc_inv = Character("Andreia")
define character.erkan_inv = Character("Erkan")
default mc_inv = CharacterStats('mc_inv', weapon = "", head = "", body = "", boots = "", ATK=0, DEF=0, STR=85, AGI=65, max_HP=100, max_MP=70, bag=Inventory(needle=2,pair_of_scissors=1))
default erkan_inv = CharacterStats('erkan_inv', weapon = "", head = "", body = "", boots = "", ATK=0, DEF=0, STR=105, AGI=90, max_HP=120, max_MP=80, bag=Inventory())

Code: Select all

    $ character_list = []
    $ character_list.append(mc_inv)
    $ character_list.append(erkan_inv)
    
    $ mc_inv.HP = mc_inv.max_HP
    $ mc_inv.MP = mc_inv.max_MP
    $ erkan_inv.HP = erkan_inv.max_HP
    $ erkan_inv.MP = erkan_inv.max_MP
The MP and HP was needed to show the screen below.

I put a screen with inventory buttons per character.

Code: Select all

screen inventory_button:
    $ y = 0.2
    for chara in character_list:        
        textbutton "[chara.name]":
            xalign 0.5
            yalign y
            action [Show("test_show"), SetVariable("now_chara", chara), Hide("inventory_button")]
        $ y +=0.05
Each of those buttons show the character's inventory.

Code: Select all

screen test_show:
    modal True
    text "Close your inventory {p}before saving.":
        xalign 0.85
        yalign 0.3
    # i initially thought the error in saving was because i didn't close inventory before saving, that's why i put the text above.
    # now i'm not so sure what causes the error.
    textbutton "Close inventory":
        xalign 0.9
        yalign 0.4
        action [Hide("test_show"), Hide("item_interact"), Show("inventory_button"), Return()]

    $ test_y = 0.25
    $ test_x = 0.05
    $ their_bag = now_chara.bag
    
    text "{b}[now_chara.name].{/b}":
        xanchor 0.0 xpos 0.05 yanchor 0.0 ypos 0.05
    text "Money = [now_chara.money]. HP = [now_chara.HP] / [now_chara.max_HP] . MP = [now_chara.MP] / [now_chara.max_MP]. Affection = [now_chara.affection]":
        xanchor 0.0 xpos 0.05 yanchor 0.0 ypos 0.1
    text "STR = [now_chara.STR]. ATK = [now_chara.ATK]. Weapon : [now_chara.weapon].":
        xanchor 0.0 xpos 0.05 yanchor 0.0 ypos 0.15
    text "AGI = [now_chara.AGI]. DEF = [now_chara.DEF]. Armor : (Head : [now_chara.head] / Body : [now_chara.body] / Boots : [now_chara.boots].)":
        xanchor 0.0 xpos 0.05 yanchor 0.0 ypos 0.2
    for item in their_bag.items:
        text "[item.title] : [item.amount]":
            xanchor 0 yanchor 0 xpos test_x ypos test_y
        if now_chara.weapon and (now_chara.weapon==item.title): #indicate the selected weapon
            text "Equipped":
                xpos 0.35 ypos test_y
        textbutton "Info":
            xpos 0.5
            ypos test_y
            action [SetVariable("selected_item", item), Function(renpy.call, label="interact_inventory")]
        $ test_y +=0.05
Pressing 'info' button will show informations about the item, and button to use/equip/unequip them. However, the "info" button goes to a label called "interact_inventory" because I read in some threads here that we need to add $ renpy.retain_after_load() each time before accessing a screen, so that the changes made in the screen can be saved.

Code: Select all

label interact_inventory:
    $ renpy.retain_after_load()
    call screen item_interact
    return
This is the actual item_interact screen.

Code: Select all

screen item_interact:
    #modal True
    text "[selected_item.title]":
        xpos 0.4 ypos 0.6
    text "[selected_item.description]":
        xpos 0.4 ypos 0.65
    if selected_item.ATK >0 and selected_item.amount >0:
        if now_chara.weapon == selected_item.title:
            textbutton "Unequip":
                xpos 0.8
                ypos 0.8
                action[UnequipItem(selected_item)]
        else:
            textbutton "Equip":
                xpos 0.8
                ypos 0.8
                action[EquipItem(selected_item)]
    elif selected_item.amount >0:
        textbutton "Use":
            xpos 0.8
            ypos 0.8
            action[WeUse(selected_item)]
    textbutton "Hide info":
        xpos 0.6
        ypos 0.8
        action [Hide("item_interact")]
All of these work perfectly, except when we save and load the game. The game can be saved, but it can't be loaded. It gives this error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00action_file.rpy", line 331, in __call__
    renpy.load(fn)
TypeError: ('__init__() takes exactly 4 arguments (1 given)', <class 'renpy.game.CallException'>, ())

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 29, in script
    $ ui.interact()
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\ast.py", line 785, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\python.py", line 1448, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 29, in <module>
    $ ui.interact()
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\ui.py", line 277, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\core.py", line 2276, in interact
    repeat, rv = self.interact_core(preloads=preloads, **kwargs)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\core.py", line 2907, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\screen.py", line 625, in event
    rv = self.child.event(ev, x, y, st)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\layout.py", line 188, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\layout.py", line 877, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\layout.py", line 188, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\behavior.py", line 785, in event
    return handle_click(self.clicked)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\behavior.py", line 728, in handle_click
    rv = run(action)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\display\behavior.py", line 290, in run
    return var(*args, **kwargs)
  File "renpy/common/00action_file.rpy", line 331, in __call__
    renpy.load(fn)
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\loadsave.py", line 579, in load
    roots, log = loads(location.load(filename))
  File "C:\Users\User\Documents\ART_SL\renpy-6.99.4-sdk\renpy\loadsave.py", line 49, in loads
    return cPickle.loads(s)
TypeError: ('__init__() takes exactly 4 arguments (1 given)', <class 'renpy.game.CallException'>, ())

Windows-8-6.2.9200
Ren'Py 6.99.4.467
trial of stats & invent 0.0
My question is: how did this error appear? What should I do to fix it?

I attach the whole renpy game folder with the scripts and all below.

I thought of posting a reply on Remix's original thread but I'm afraid I have altered it too much, so I made a new ask. Anyway, I don't claim ownership to the original inventory and stats system...

Thank you in advance! :D
Attachments
using a potion.jpg
using a potion
the error.jpg
the error after saving and loading
one of inventory screens.jpg
one of the inv screen
equipping a weapon.jpg
equipping weapon in the inv screen
button that leads to inventory screens.jpg
button that leads to inv screen
trial of stats & invent.rar
the renpy file
(185.5 KiB) Downloaded 7 times
Last edited by felisselita on Tue Mar 19, 2019 9:10 am, edited 1 time in total.
Image
Starstorm by felisselita, a BL visual novel with minigames! Get it here: https://felis-selita.itch.io/starstorm

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

Re: Inventory and Character Stats Screen, __init error when saving and loading?

#2 Post by philat » Mon Mar 18, 2019 7:59 am

You use python variables without declaring them first with default (e.g., character_list and this_place), which is a very common reason for errors in save/load.

User avatar
felisselita
Newbie
Posts: 16
Joined: Thu Jul 21, 2011 12:26 am
Completed: "Starstorm", a BL visual novel game
Tumblr: felisselita
Deviantart: felisselita
itch: felis-selita
Contact:

Re: Inventory and Character Stats Screen, __init error when saving and loading?

#3 Post by felisselita » Tue Mar 19, 2019 9:09 am

philat wrote:
Mon Mar 18, 2019 7:59 am
You use python variables without declaring them first with default (e.g., character_list and this_place), which is a very common reason for errors in save/load.
Thank you very much philat! However... Uh, I'm not sure, but, actually before you replied, I haven't changed anything, upgraded my Ren'py to the newest (at this time it's 7.2.x), and... The error is gone. ^^; It might also have something to do with me using an older ver. of Ren'py before. Or I've subconsciously changed some things... Idk. Anyway thank you, I'll remember it next time. :D
Image
Starstorm by felisselita, a BL visual novel with minigames! Get it here: https://felis-selita.itch.io/starstorm

Post Reply

Who is online

Users browsing this forum: Google [Bot]