Question - How read all character declared for make a drop-down menu on automatic script [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
jaas
Newbie
Posts: 6
Joined: Fri Feb 07, 2020 9:53 am
Contact:

Question - How read all character declared for make a drop-down menu on automatic script [SOLVED]

#1 Post by jaas »

Good morning

Thank you for accepting me into the community.

I'm learning renpy, to help my children (10 and 13 years old) who are learning renpy.

I come to you with the question,
"Ho I can do a reading of the list of variables declared as characters "
, this with the purpose of saving them in a list (NmbList[]), for general a drop-down menu of characters.

So you only have to define the characters when programming, without having to worry about altering the code generated by the drop-down menu.

I am using "microsoft translator" my native lenguage is Spanish
Last edited by jaas on Sat Feb 15, 2020 7:49 am, edited 1 time in total.

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Question - How read all character declared for make a drop-down menu on automatic script

#2 Post by Per K Grok »

jaas wrote: Fri Feb 07, 2020 10:25 am Good morning

Thank you for accepting me into the community.

I'm learning renpy, to help my children (10 and 13 years old) who are learning renpy.

I come to you with the question,
"Ho I can do a reading of the list of variables declared as characters "
, this with the purpose of saving them in a list (NmbList[]), for general a drop-down menu of characters.

So you only have to define the characters when programming, without having to worry about altering the code generated by the drop-down menu.

I am using "microsoft translator" my native lenguage is Spanish
Welcome to the forums. :)

I'm not sure if I understand exactly what it is you want to do. Neither do I know how much python or programming in general that you know. So it is a bit hard to know where to start.

But part of what you want to do seems to be to make a list with the names of characters. You could, before 'label start' define the list of characters names.

default NmbList=["Adam", "Betty","Conny","Debra"]

One thing that can be a bit tricky with Ren'py is that you use slightly different language for different elements in the game. You can also use python for some parts. For handling lists you use python. When you use python in the code you start the line with $ (or you can write python: if you have a block of python code lines).

To add an element to the list you would do

$ NmbList.append("Esteban")

You can then use the elements in the list by referring to them by number of position in the list, beginning with 0.

so if you do this

Code: Select all


default NmbList=["Adam", "Betty","Conny","Debra"]

label start:
 
    $ NmbList.append("Esteban")

    "Hello [NmbList[4]]"


     return

and you run the code the program should say
"Hello Esteban"

Is this helpful to you?
To simple?
To difficult?
Not at all on the subject?

jaas
Newbie
Posts: 6
Joined: Fri Feb 07, 2020 9:53 am
Contact:

Re: Question - How read all character declared for make a drop-down menu on automatic script

#3 Post by jaas »

Thank you for responding so quickly, I will try to explain myself as best I can for using the translator.

I will increase the definition of characters over time :

define Adele = character("Adele", image"adele")
define Andrea = character("Andrea", image-"andrea")
define Anthony= character("Anthony", image"anthony")
......
define Ashley = character("Ashley", image"ashley")

and I want to do a "function" or "script" or "def class", which automatically reads those defined characters and creates a list of names, and then, with that list use it to generate with a frame, a drop-down menu, where each defined character is a button within the menu.

I want to make a script that reads those variables defined as "character", and generate a drop-down menu (frame), and I do not want or desire, that every time I define a character (i want add +/-10 character on each release), I have to go for the script that generates the drop-down menu and alter it or modify the list of characters, but everything is done in automatic, for this I only lack how to go through the variables defined as "characters", that's where I'm stranded, I don't know and I haven't found a way to do that task, I read "help" online renpy, and all advanced items with "store.xxx", "renpy.xxxx", "config.xxxx" but I don't look nothing

theoricately something like this:

for x in character.name:
list[x]-character[x].name

vbox:
for i in list:
textbutton (list) ....


My english is bad for conversation, I am using microsof traslator I hope you can me undertanding

Thank you

In Spanish:

Gracias por responder tan rapido, voy a tratar de explicarme lo mejor que puedo por usar el traductor.

Yo a lo largo del tiempo voy a ir aumentando la definicion de personajes :

define Adele = Character("Adele", image="adele")
define Andrea = Character("Andrea", image="andrea")
define Anthony = Character("Anthony", image="anthony")
......
define Ashley = Character("Ashley", image="ashley")

y quiero hacer una "funcion" o "script" o "def class", que leea automaticamente esos personajes definidos y cree una lista de nombres, para luego, con esa lista usarla para generar con un frame, un menu desplegable, donde cada persojane definido sea un boton dentro del menu.

Quiero hacer un script que leea esas variables definidas como "character", y generar un menu desplegable (frame), y no quiero o deseo, que cada vez que defina un personaje (voy agregar + o - 10 personajes en cada actualizacion), yo tener que ir para el script que genera el menu desplegable y alterarlo o modificar la lista de characters, sino que se haga todo en automatico, para ello solo me falta como recorrer las variables definidas como "characters", alli es donde estoy varado, no se y no he encontrado la manera de hacer esa tarea

teoricamente algo asi:

for x in character.name:
lista[x]=character[x].name

vbo:
for i in lista:
textbutton (lista) ....








Per K Grok wrote: Fri Feb 07, 2020 4:50 pm
jaas wrote: Fri Feb 07, 2020 10:25 am Good morning

Thank you for accepting me into the community.

I'm learning renpy, to help my children (10 and 13 years old) who are learning renpy.

I come to you with the question,
"Ho I can do a reading of the list of variables declared as characters "
, this with the purpose of saving them in a list (NmbList[]), for general a drop-down menu of characters.

So you only have to define the characters when programming, without having to worry about altering the code generated by the drop-down menu.

I am using "microsoft translator" my native lenguage is Spanish


Welcome to the forums. :)

I'm not sure if I understand exactly what it is you want to do. Neither do I know how much python or programming in general that you know. So it is a bit hard to know where to start.

But part of what you want to do seems to be to make a list with the names of characters. You could, before 'label start' define the list of characters names.

default NmbList=["Adam", "Betty","Conny","Debra"]

One thing that can be a bit tricky with Ren'py is that you use slightly different language for different elements in the game. You can also use python for some parts. For handling lists you use python. When you use python in the code you start the line with $ (or you can write python: if you have a block of python code lines).

To add an element to the list you would do

$ NmbList.append("Esteban")

You can then use the elements in the list by referring to them by number of position in the list, beginning with 0.

so if you do this

Code: Select all


default NmbList=["Adam", "Betty","Conny","Debra"]

label start:
 
    $ NmbList.append("Esteban")

    "Hello [NmbList[4]]"


     return

and you run the code the program should say
"Hello Esteban"

Is this helpful to you?
To simple?
To difficult?
Not at all on the subject?

jaas
Newbie
Posts: 6
Joined: Fri Feb 07, 2020 9:53 am
Contact:

Re: Question - How read all character declared for make a drop-down menu on automatic script

#4 Post by jaas »

The idea also, part of the principle, of creating modular and reusable code, that is, that it can be used or adapted to other games easily.

Again thank you for the time spent

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

Re: Question - How read all character declared for make a drop-down menu on automatic script

#5 Post by philat »

Afaik, there's no easy way to do this out of the box. (I could be wrong obvs.) Other than doing it manually, your best bet is probably rolling some custom function to define characters and append them to a data structure (along the lines of viewtopic.php?t=29409 - note that this is from a while ago and I haven't tested it recently but I'm linking for the general idea). Honestly unclear that that would be less work though. Shrug.

ETA: On second thought, I guess you don't need to go THAT far, possibly something simpler along the lines of the below would work. Depends on what you want though, I guess.

Code: Select all

init python:
    charlist = []
    def char_wrapper(*args, **kwargs):
       global charlist
       temp = Character(*args, **kwargs)
       charlist.append(temp)
       return temp

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Question - How read all character declared for make a drop-down menu on automatic script

#6 Post by Per K Grok »

jaas wrote: Fri Feb 07, 2020 6:47 pm The idea also, part of the principle, of creating modular and reusable code, that is, that it can be used or adapted to other games easily.

Again thank you for the time spent
In case the problem is not yet solved.

I'm still not clear on what you want to do.

This code will make something like a drop-menu where you can chose from a list of characters. It doesn't do anything except open and close the menu at this time. I'm not sure what choosing a character name is supposed to do. Maybe that becomes the player character?

Code: Select all

default cA=Character("Adam")
default cB=Character("Betty")
default cC=Character("Conny")
default cD=Character("Debra")

default NmbList=[cA, cB, cC, cD]

screen pickeropen():
    textbutton "Open picker" action Show("characterpicker"), Hide("pickeropen")


screen characterpicker():
    vbox:
        for i in NmbList:
            textbutton i.name action Hide("characterpicker"), Show("pickeropen")


label start:

    show screen pickeropen

    pause
    return

What I think you might be saying is that you want the

Code: Select all

default NmbList=[cA, cB, cC, cD]
to be generated automatically from

Code: Select all

default cA=Character("Adam")
default cB=Character("Betty")
default cC=Character("Conny")
default cD=Character("Debra")
so that when creating the game you just have to write in the characters and the list will generate itself and can be used for the dopmenu.

I might completely be misunderstanding what you are looking for, but if that is it, I think you are planing to do things in an unnecessarily complicated way.

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: Question - How read all character declared for make a drop-down menu on automatic script

#7 Post by Remix »

As Character() is in the renpy.character namespace, you could just overload that name in the global and then reference the namespace inside it...

Code: Select all

init python:

    def Character(*args, **kwargs):
        char = renpy.character.Character(*args, **kwargs)
        try:
            if not char in store.all_characters:
                store.all_characters.append(char)
        except:
            store.all_characters = [char]
        return char

# Normal defines now use our function instead, add to the list and return the return of the namespace version

define a = Character("Amber")
define b = Character("Brianna")
define c = Character("Catherine")
define d = Character("Dinky")
define e = Character("Eileen")

label start:

    "[all_characters!q]" # Shows all our character objects automatically listed
Frameworks & Scriptlets:

jaas
Newbie
Posts: 6
Joined: Fri Feb 07, 2020 9:53 am
Contact:

Re: Question - How read all character declared for make a drop-down menu on automatic script

#8 Post by jaas »

Thank you very much to Everyone, for answering and helping me with this issue, In My country (venezuela) there are power failures and for this reason it fails in internet access. I'm going to try the ideas raised here and I'll be notifying you.

As I said, forgive my English, I use the translator

Spanish:

Muchas gracias a Todos, por responder y ayudarme con este tema, En Mi pais (venezuela) hay fallas de energia electrica y por tal causa falla en el acceso a internet. Voy a probar las ideas aqui planteadas y les estare notificando.

Como he dicho , perdonen mi ingles , uso el traductor

jaas
Newbie
Posts: 6
Joined: Fri Feb 07, 2020 9:53 am
Contact:

Re: Question - How read all character declared for make a drop-down menu on automatic script

#9 Post by jaas »

Thank you very much, especially by REMIX, your solution is perfect,

Now and excuse my insistence, How do I read that in the form of a "FOR" cycle?

(I just need to know how I read the text string it generates)

My example:

Code: Select all

init python:

    def Character(*args, **kwargs):
        char = renpy.character.Character(*args, **kwargs)
        try:
            if not char in store.all_characters:
                store.all_characters.append(char)
        except:
            store.all_characters = [char]
        return char

# Normal defines now use our function instead, add to the list and return the return of the namespace version
define a = Character("Amber")
define b = Character("Brianna")
define c = Character("Catherine")
define d = Character("Dinky")
define e = Character("Eileen")

label start:

    "[all_characters!q]" # Shows all our character objects automatically listed

    $ lstGirls=[]
    python:
        for Clv, Vlr in all_characters.iteritems:
            lstGirls[k] = Vlr
            k+=1
            
          
    scene bg room

    show eileen happy

    
    return

But I don't work , I don't know that to do...??

I don't know how to read the string that generates all_characters, try as a tuple, as a list as dict, but I have not managed to do it or wrongly imheated something,
the list that generates "all_characters" is this:

"[<Character: u'Amber'>,<Character: u'Brianna'>,<Character: u'Catherine'>,<Character: u'Dinky'>,<Character: u'Eileen'>,<Character: u'Remix'>]"

The message error is this:

Full traceback:
File "game/script.rpy", line 28, in script
python:
File "C:\00 Portables\renpy-7.3.5-sdk\renpy\ast.py", line 914, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\00 Portables\renpy-7.3.5-sdk\renpy\python.py", line 2028, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 29, in <module>
for Clv, Vlr in iter(all_characters):
TypeError: 'ADVCharacter' object is not iterable



Remix wrote: Sat Feb 08, 2020 7:26 am As Character() is in the renpy.character namespace, you could just overload that name in the global and then reference the namespace inside it...

Code: Select all

init python:
    def Character(*args, **kwargs):
        char = renpy.character.Character(*args, **kwargs)
        try:
            if not char in store.all_characters:
                store.all_characters.append(char)
        except:
            store.all_characters = [char]
        return char

# Normal defines now use our function instead, add to the list and return the return of the namespace version

define a = Character("Amber")
define b = Character("Brianna")
define c = Character("Catherine")
define d = Character("Dinky")
define e = Character("Eileen")

label start:

    "[all_characters!q]" # Shows all our character objects automatically listed

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: Question - How read all character declared for make a drop-down menu on automatic script

#10 Post by Remix »

iteritems is BAD

It is Python < 3 only (even though 2.7 etc supports .items() ) and it is a method, not an attribute and it is a method of dictionaries not lists...

The drop-in Character function internally creates a list named 'all_character'
Much like adding a line saying 'default all_characters = [mc, e, l]' or whatever, just automagically

We could iterate that list and access attributes of each object it contains...

Code: Select all

    for char in all_characters:
        "[char.name] signing in for duty"
If you wanted that list to be a dict, first read a little about dictionaries in python then tweak the function so it builds a dictionary keyed by char.name (sub-note:: You will hit issues with dynamic characters though, hence I just left it as a list)
Frameworks & Scriptlets:

jaas
Newbie
Posts: 6
Joined: Fri Feb 07, 2020 9:53 am
Contact:

Re: Question - How read all character declared for make a drop-down menu on automatic script

#11 Post by jaas »

Thank you very much Remix,

I've followed your advice to the letter and it worked out for me.

I'm going to follow your constituency.

Again thank you very much

Remix wrote: Fri Feb 14, 2020 10:40 pm iteritems is BAD

It is Python < 3 only (even though 2.7 etc supports .items() ) and it is a method, not an attribute and it is a method of dictionaries not lists...

The drop-in Character function internally creates a list named 'all_character'
Much like adding a line saying 'default all_characters = [mc, e, l]' or whatever, just automagically

We could iterate that list and access attributes of each object it contains...

Code: Select all

    for char in all_characters:
        "[char.name] signing in for duty"
If you wanted that list to be a dict, first read a little about dictionaries in python then tweak the function so it builds a dictionary keyed by char.name (sub-note:: You will hit issues with dynamic characters though, hence I just left it as a list)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]