CREATE and FUCK your own AI GIRLFRIEND TRY FOR FREE
x

Ren'Py characters at certain time and locations

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,120
3,181
characters at certain time and locations

images name would like so

with minutes mom_12_0_livingroom.png
without minutes mom_12_livingroom.png

this fully working code anyone can use it if they want too
class.rpy (you can remove the minutes so the character stay in that location longer)
Python:
class NPC(object):
    def __init__(self, name, nicename, location, hours, minutes, lbt=""):
        self.name = name
        self.nicename = nicename
        self.location = location
        self.hours = hours
        self.minutes = minutes
        self.lbt = lbt


    @property
    def avatar(self):     
        #If you remove the minutes remove one of the {} and remove str(minutes),
        avtr = "images/avatar/{}/{}_{}_{}_{}.png".format(self.name, self.nicename, str(hours), str(minutes), location)


    if renpy.loadable(avtr):
        return avtr
    else:
        return "images/avatar/empty.png"

character_screen.rpy
Python:
screen charcater_screen():
   # remove and q.minutes == minutes if you are planning to remove minutes
    for q in NPCS:
         if q.location == location and q.hours == hours and q.minutes == minutes:

            imagebutton:
                idle q.avatar
                hover q.avatar
                focus_mask True
                action Call(q.lbt)
default.rpy
Python:
default lbt = ""
default NPCS = []
default hours = 0
default minutes = 0

#make sure you use call InitialiseVariables
label InitialiseVariables:
    #If you remove minutes just remove the minutes out
    $ NPCS.append(NPC("mom", "mom", "livingroom", 12, 0, lbt="test"))
    #$ NPCS.append(NPC("character_name", "folders name", location", hour, minutes, lbt="label"))



    return
 
Last edited:

peterppp

Active Member
Mar 5, 2020
738
1,304
from a glance, the capitalization of livingroom differs. should be fixed even if it works on windows
 

gojira667

Member
Sep 9, 2019
297
284
What does NPC.avatar return?
Python:
default lbt = ""
default NPCS = []

label InitialiseVariables:

    $ NPCS.append(NPC("mom", "Mom", "livingroom", 12, 0, lbt="test"))
    $ hours, minutes, location = (12, 0, 'livingroom') #lowercase
    $ print(NPCS[0].avatar)

    return
Or put a temporary print in avatar():
Python:
class NPC(object):

        @property
        def avatar(self):
            avtr = "avatar/{}_{}_{}_{}.png".format(self.name, str(hours), str(minutes), location)
            print(avtr)


            if renpy.loadable(avtr):
                return avtr
            else:
                return "avatar/empty.png"
The global is pointless and unneeded in that def.
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,120
3,181
What does NPC.avatar return?
Python:
default lbt = ""
default NPCS = []

label InitialiseVariables:

    $ NPCS.append(NPC("mom", "Mom", "livingroom", 12, 0, lbt="test"))
    $ hours, minutes, location = (12, 0, 'livingroom') #lowercase
    $ print(NPCS[0].avatar)

    return
Or put a temporary print in avatar():
Python:
class NPC(object):

        @property
        def avatar(self):
            avtr = "avatar/{}_{}_{}_{}.png".format(self.name, str(hours), str(minutes), location)
            print(avtr)


            if renpy.loadable(avtr):
                return avtr
            else:
                return "avatar/empty.png"
The global is pointless and unneeded in that def.
thanks tried what you put and it showed

Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 17, in script call
    call InitialiseVariables
  File "game/defaults.rpy", line 15, in script
    $ NPCS.append(NPC("mom", "Mom", "livingroom", 12, 0, lbt="test"))
  File "game/defaults.rpy", line 15, in <module>
    $ NPCS.append(NPC("mom", "Mom", "livingroom", 12, 0, lbt="test"))
TypeError: __init__() got multiple values for argument 'lbt'

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

Full traceback:
  File "game/script.rpy", line 17, in script call
    call InitialiseVariables
  File "game/defaults.rpy", line 15, in script
    $ NPCS.append(NPC("mom", "Mom", "livingroom", 12, 0, lbt="test"))
  File "C:\Users\raymi\renpy-8.1.3-sdk\renpy\ast.py", line 821, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\raymi\renpy-8.1.3-sdk\renpy\python.py", line 1178, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/defaults.rpy", line 15, in <module>
    $ NPCS.append(NPC("mom", "Mom", "livingroom", 12, 0, lbt="test"))
TypeError: __init__() got multiple values for argument 'lbt'

Windows-10-10.0.22631 AMD64
Ren'Py 8.3.2.24090902

Sat Oct  5 02:50:02 2024
 

gojira667

Member
Sep 9, 2019
297
284
thanks tried what you put and it showed

Code:
...
    $ NPCS.append(NPC("mom", "Mom", "livingroom", 12, 0, lbt="test"))
TypeError: __init__() got multiple values for argument 'lbt'
I copied your NPC line and didn't check the constructor. You can only have one [mM]om. E.G. NPC("mom", "livingroom", 12, 0, lbt="test").
 
  • Like
Reactions: rayminator

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,120
3,181
here the image that I'm using as a test mom_12_0_livingroom.png it's not showing

mom_12_0_livingroom.png
 

Ashira13

Active Member
Jan 31, 2024
907
1,658
read the main I've mentioned what version
renpy version 8.3.2
and what does the tracelog say?
File "C:\Users\raymi\renpy-8.1.3-sdk\renpy\ast.py", line 821, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\raymi\renpy-8.1.3-sdk\renpy\python.py", line 1178, in py_exec_bytecode
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,120
3,181
and what does the tracelog say?
File "C:\Users\raymi\renpy-8.1.3-sdk\renpy\ast.py", line 821, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\raymi\renpy-8.1.3-sdk\renpy\python.py", line 1178, in py_exec_bytecode

there is no error so there no tracelog for it.
it's just not showing the image

this old forgot to take out call InitialiseVariables when I have removed it from game

Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 17, in script call
    call InitialiseVariables
  File "game/defaults.rpy", line 15, in script
    $ NPCS.append(NPC("mom", "livingroom", 12, lbt="test"))
  File "game/defaults.rpy", line 15, in <module>
    $ NPCS.append(NPC("mom", "livingroom", 12, lbt="test"))
NameError: name 'NPC' is not defined

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

Full traceback:
  File "game/script.rpy", line 17, in script call
    call InitialiseVariables
  File "game/defaults.rpy", line 15, in script
    $ NPCS.append(NPC("mom", "livingroom", 12, lbt="test"))
  File "C:\Users\raymi\renpy-8.1.3-sdk\renpy\ast.py", line 821, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\raymi\renpy-8.1.3-sdk\renpy\python.py", line 1178, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/defaults.rpy", line 15, in <module>
    $ NPCS.append(NPC("mom", "livingroom", 12, lbt="test"))
NameError: name 'NPC' is not defined

Windows-10-10.0.22631 AMD64
Ren'Py 8.3.2.24090902

Sat Oct  5 07:55:09 2024
 

guest1492

Member
Apr 28, 2018
346
284
Your latest errors say that NPC is not defined, which means you must have removed the definition for the class somehow.

Also, you are trying to initialize the class with NPC("mom", "livingroom", 12, lbt="test") when it should be NPC("mom", "livingroom", 12, 0, lbt="test").

Not sure about this, but shouldn't format(self.name, str(hours), str(minutes), location) be format(self.name, str(self.hours), str(self.minutes), self.location)?
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,120
3,181
Your latest errors say that NPC is not defined, which means you must have removed the definition for the class somehow.

Also, you are trying to initialize the class with NPC("mom", "livingroom", 12, lbt="test") when it should be NPC("mom", "livingroom", 12, 0, lbt="test").

Not sure about this, but shouldn't format(self.name, str(hours), str(minutes), location) be format(self.name, str(self.hours), str(self.minutes), self.location)?
thanks but still no go
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,120
3,181
I got it to work again I just had to edit

Python:
class NPC(object):

        @property
        def avatar(self):
            avtr = "avatar/{}_{}_{}_{}.png".format(self.name, str(hours), str(minutes), location)
            print(avtr)


            if renpy.loadable(avtr):
                return avtr
            else:
                return "avatar/empty.png"
to

Python:
class NPC(object):

        @property
        def avatar(self):
            avtr = "images/avatar/{}_{}_{}_{}.png".format(self.name, str(hours), str(minutes), location)
            print(avtr)


            if renpy.loadable(avtr):
                return avtr
            else:
                return "images/avatar/empty.png"
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,120
3,181
now they show up but now they won't disappear when I change the hour
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,120
3,181
I have update the main post with a some what working
they show up now but they won't disappear when the time changed

I think it has something to do with this

Python:
if renpy.loadable(avtr):
                return avtr
            else:
                return "images/avatar/empty.png"
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,120
3,181
I finally got it to work

thanks everyone for helping me
if anyone wants to use it you can
 
Last edited: