[solved] How to use "SetDict" (screen language)

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
korova
Veteran
Posts: 215
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

[solved] How to use "SetDict" (screen language)

#1 Post by korova » Tue Feb 27, 2018 7:59 pm

Hello ! I'm trying to use the action SetDict in a screen, but I bump on an error each time I'm trying to use it.

What is my code supposed to do ?
It displays a 3 x 3 grid that at first show "0" in every cell.
When I click on a cell, I want the number to be increased by 1.
Cell values are saved in a dictionary, default values are defined in the beginning of the script. I'm trying to change the values of the dictionary, therefore the values shown on screen.

Here is my code :

Code: Select all

default cases = {
    1:0,
    2:0,
    3:0,
    4:0,
    5:0,
    6:0,
    7:0,
    8:0,
    9:0
    }

screen jeu_couleur():

    add Solid("#666")

    #default couleur = 0

    grid 3 3:
        xsize 150
        ysize 150
        align (0.5,0.5)
        spacing 25

        for i in range(1,10):
            button:
                text str(cases[i]) align (0.5,0.5)
                action SetDict("cases" , i , cases[i]+1)


label code_couleur:

    show screen jeu_couleur
    "Hi !"

    return
Here is the error message :

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/jeu_couleurs..rpy", line 54, in script
    
  File "renpy/common/000window.rpy", line 98, in _window_auto_callback
    _window_show()
  File "renpy/common/000window.rpy", line 60, in _window_show
    renpy.with_statement(trans)
  File "renpy/common/00action_data.rpy", line 83, in get_selected
    if self.key not in self.dict:
TypeError: coercing to Unicode: need string or buffer, int found

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

Full traceback:
  File "game/jeu_couleurs..rpy", line 54, in script
    
  File "/usr/share/games/renpy/renpy/ast.py", line 609, in execute
    statement_name("say")
  File "/usr/share/games/renpy/renpy/ast.py", line 43, in statement_name
    i(name)
  File "renpy/common/000window.rpy", line 98, in _window_auto_callback
    _window_show()
  File "renpy/common/000window.rpy", line 60, in _window_show
    renpy.with_statement(trans)
  File "/usr/share/games/renpy/renpy/exports.py", line 1409, in with_statement
    return renpy.game.interface.do_with(trans, paired, clear=clear)
  File "/usr/share/games/renpy/renpy/display/core.py", line 2190, in do_with
    clear=clear)
  File "/usr/share/games/renpy/renpy/display/core.py", line 2624, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "/usr/share/games/renpy/renpy/display/core.py", line 2999, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "/usr/share/games/renpy/renpy/display/core.py", line 511, in visit_all
    d.visit_all(callback)
  File "/usr/share/games/renpy/renpy/display/core.py", line 511, in visit_all
    d.visit_all(callback)
  File "/usr/share/games/renpy/renpy/display/core.py", line 511, in visit_all
    d.visit_all(callback)
  File "/usr/share/games/renpy/renpy/display/core.py", line 511, in visit_all
    d.visit_all(callback)
  File "/usr/share/games/renpy/renpy/display/screen.py", line 405, in visit_all
    self.child.visit_all(callback)
  File "/usr/share/games/renpy/renpy/display/core.py", line 511, in visit_all
    d.visit_all(callback)
  File "/usr/share/games/renpy/renpy/display/core.py", line 511, in visit_all
    d.visit_all(callback)
  File "/usr/share/games/renpy/renpy/display/core.py", line 513, in visit_all
    callback(self)
  File "/usr/share/games/renpy/renpy/display/core.py", line 2999, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "/usr/share/games/renpy/renpy/display/behavior.py", line 796, in per_interact
    if self.is_selected():
  File "/usr/share/games/renpy/renpy/display/behavior.py", line 786, in is_selected
    return is_selected(self.action)
  File "/usr/share/games/renpy/renpy/display/behavior.py", line 359, in is_selected
    return action.get_selected()
  File "renpy/common/00action_data.rpy", line 83, in get_selected
    if self.key not in self.dict:
TypeError: coercing to Unicode: need string or buffer, int found

Linux-4.14.0-3-amd64-x86_64-with-debian-buster-sid
Ren'Py 6.99.14.1.3218
Essais 1.0
Wed Feb 28 00:57:42 2018
What am I doing wrong ?
Last edited by korova on Tue Feb 27, 2018 9:12 pm, edited 1 time in total.

irredeemable
Regular
Posts: 78
Joined: Thu Feb 08, 2018 7:57 am
Contact:

Re: How to use "SetDict" (screen language)

#2 Post by irredeemable » Tue Feb 27, 2018 8:20 pm

Remove the quotes from around "cases":

Code: Select all

action SetDict(cases , i , cases[i]+1)

User avatar
korova
Veteran
Posts: 215
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: How to use "SetDict" (screen language)

#3 Post by korova » Tue Feb 27, 2018 9:11 pm

OK, thanks a lot, it works now.
(I'm a bit ashamed that I wasted two hours for such a simple mistake. By the way, can someone explain me why SetVariable needs quotes when SetDict doesn't ?)

Post Reply

Who is online

Users browsing this forum: senisanti