Re: Automatic character, background, etc. image defining scr
Posted: Sun Aug 02, 2015 3:18 pm
Supporting creators of visual novels and story-based games since 2003.
https://lemmasoft.renai.us/forums/
The answer is simple.
Code: Select all
init python:
import os
def define_characters(characterImageFolder, excludeFirstXFolders=0, flip=True):
for path in renpy.list_files():
if path.startswith(characterImageFolder + "/"):
path_list = path.split("/")
path_list[-1] = os.path.splitext(path_list[-1])[0]
path_list = tuple(path_list[excludeFirstXFolders:])
renpy.image(path_list, path)
if flip:
renpy.image(path_list + ("flip", ), im.Flip(path, horizontal=True))
define_characters("images", 1)
Code: Select all
init python:
import os
def define_characters(characterImageFolder, excludeFirstXFolders=0, flip=True):
for path in renpy.list_files():
if path.startswith(characterImageFolder + "/"):
path_list = path.split("/")
path_list[-1] = os.path.splitext(path_list[-1])[0]
path_list = tuple(path_list[excludeFirstXFolders:])
renpy.image(path_list, path)
if flip:
renpy.image(path_list + ("flip", ), im.Flip(path, horizontal=True))
init:
image bg testing1 = "images/bg 0001.jpg"
define_characters("images", 1, False)
Code: Select all
init python:
import os
def define_characters(images, excludeFirstXFolders=0, flip=True):
for path in renpy.list_files():
if path.startswith(images + "/"):
path_list = path.split("/")
path_list[-1] = os.path.splitext(path_list[-1])[0]
path_list = tuple(path_list[excludeFirstXFolders:])
renpy.image(path_list, path)
if flip:
renpy.image(path_list + ("flip", ), im.Flip(path, horizontal=True))
define_characters("sprites", 1)
init:
$ k = Character("Kaiba")
image base = "base.jpg"
label start:
scene base
show kaiba smile
k "A puppy die everytime I smile."
return
Code: Select all
define_characters("sprites", 1)
Code: Select all
define_characters("images/sprites", 1)
Code: Select all
[game]
[images]
[bg]
washington.png
[characters]
[sara]
happy.png
[uniform]
concerned.png
Code: Select all
init python:
def define_images(imageFolder, excludeFirstXFolders=0, flip=True):
for path in renpy.list_files():
if path.startswith(imageFolder + "/"):
path_list = path.split("/")
path_list[-1] = os.path.splitext(path_list[-1])[0]
path_list = tuple(path_list[excludeFirstXFolders:])
renpy.image(path_list, path)
if flip:
renpy.image(path_list + ("flip", ), im.Flip(path, horizontal=True))
define_images('images/bg/', 1, False) # set to 1 to allow "bg" in the scene declaration?
define_images('images/characters/', 2) # set to 2 to remove images/characters/ from the show declaration?
#Another example: let's say we wanted to define some backgrounds as well.
#We have a folder game/bg/, and in it there's the image "school.png".
#We could use the function:
#define_images('bg/', 0, False)
#after which we'd be able to call the image with
#scene bg school
define s = Character("Sara")
# Game start
label start:
scene bg washington
show sara happy
s "You've created a new Ren'Py game."
show sara uniform concerned
Code: Select all
game/script.rpy:32 The image named 'bg washington' was not declared.
game/script.rpy:38 The image named 'sara happy' was not declared.
game/script.rpy:44 The image named 'sara uniform concerned' was not declared.
Yeah... I was leaning that way for the backgrounds, that should be no problem.Zetsubou wrote: ↑Fri Jan 19, 2018 8:01 pm For your backgrounds (eg. "bg washington"), I'd recommend not using this script. Images in the "images" directory are automatically defined by Renpy itself nowadays anyway. So you'd be better off having something like "game/images/bg/bg washington.png". Renpy would see the file "bg washington.png" and define it, so you could call "scene bg washington". It's faster and easier than using a script like this.
Unfortunately, it looks like some of the built in Ren'Py stuff is conflicting with using define-characters-livecomposite.rpy with regard to the character/image definitions:Zetsubou wrote: ↑Fri Jan 19, 2018 8:01 pm For character sprites, you don't need this script if you're going to use the livecomposite one. Using both would just wind up leading to images being defined twice.
So it might be better to ditch this script completely. Try the livecomposite script for sprites, and use Renpy's own image defining for everything else.
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/define-characters-livecomposite.rpy", line 145, in <module>
define_chars("images/characters/")
File "game/define-characters-livecomposite.rpy", line 97, in define_chars
define_extra(size, side, character, None, outfit, cKey, oKey, None)
File "game/define-characters-livecomposite.rpy", line 120, in define_extra
define_image(size, side, nameList, args)
File "game/define-characters-livecomposite.rpy", line 36, in define_image
renpy.image(path_tuple, LiveComposite(size, *args))
Exception: Style 'image_placement' does not exist.
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/bootstrap.py", line 306, in bootstrap
renpy.main.main()
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/main.py", line 367, in main
renpy.game.script.load_script() # sets renpy.game.script.
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/script.py", line 266, in load_script
self.load_appropriate_file(".rpyc", ".rpy", dir, fn, initcode)
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/script.py", line 757, in load_appropriate_file
self.finish_load(stmts, initcode, filename=lastfn)
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/script.py", line 449, in finish_load
node.early_execute()
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/ast.py", line 900, in early_execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/python.py", line 1804, in py_exec_bytecode
exec bytecode in globals, locals
File "game/define-characters-livecomposite.rpy", line 145, in <module>
define_chars("images/characters/")
File "game/define-characters-livecomposite.rpy", line 97, in define_chars
define_extra(size, side, character, None, outfit, cKey, oKey, None)
File "game/define-characters-livecomposite.rpy", line 120, in define_extra
define_image(size, side, nameList, args)
File "game/define-characters-livecomposite.rpy", line 36, in define_image
renpy.image(path_tuple, LiveComposite(size, *args))
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/display/layout.py", line 290, in LiveComposite
rv = Fixed(xmaximum=width, ymaximum=height, xminimum=width, yminimum=height, **properties)
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/display/layout.py", line 1000, in Fixed
return MultiBox(layout='fixed', **properties)
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/display/layout.py", line 513, in __init__
self._clipping = self.style.clipping
File "gen/styleclass.pxi", line 181, in renpy.styledata.styleclass.Style.clipping.__get__
File "style.pyx", line 486, in renpy.style.StyleCore._get
File "style.pyx", line 672, in renpy.style.build_style
File "style.pyx", line 140, in renpy.style.get_full_style
File "style.pyx", line 96, in renpy.style.get_style
Exception: Style 'image_placement' does not exist.
Darwin-15.6.0-x86_64-i386-64bit
Ren'Py 6.99.14.3135
Code: Select all
File "game/define-characters-livecomposite.rpy", line 36, in define_image
renpy.image(path_tuple, LiveComposite(size, *args))
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/display/layout.py", line 290, in LiveComposite
rv = Fixed(xmaximum=width, ymaximum=height, xminimum=width, yminimum=height, **properties)
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/display/layout.py", line 1000, in Fixed
return MultiBox(layout='fixed', **properties)
Yep, I was running the script as you had written (it was in a "init python early" block).Zetsubou wrote: ↑Sun Jan 21, 2018 4:00 pm Maybe try changing the priority of the init python block? eg. "init +1 python:"
I'm guessing the script is running before some other part of Renpy is initialized.
...
Which makes me think it's to do with the new multiple textboxes feature. (I haven't tested this code with Renpy 6.99.14)
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/define-characters-livecomposite.rpy", line 1, in script
init +1 python:
File "game/define-characters-livecomposite.rpy", line 145, in <module>
define_chars("images/characters/")
File "game/define-characters-livecomposite.rpy", line 95, in define_chars
define_extra(size, side, character, pose, outfit, cKey, oKey, pKey)
File "game/define-characters-livecomposite.rpy", line 120, in define_extra
define_image(size, side, nameList, args)
File "game/define-characters-livecomposite.rpy", line 36, in define_image
renpy.image(path_tuple, LiveComposite(size, *args))
Exception: Not a displayable: {}
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/define-characters-livecomposite.rpy", line 1, in script
init +1 python:
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/ast.py", line 848, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/python.py", line 1804, in py_exec_bytecode
exec bytecode in globals, locals
File "game/define-characters-livecomposite.rpy", line 145, in <module>
define_chars("images/characters/")
File "game/define-characters-livecomposite.rpy", line 95, in define_chars
define_extra(size, side, character, pose, outfit, cKey, oKey, pKey)
File "game/define-characters-livecomposite.rpy", line 120, in define_extra
define_image(size, side, nameList, args)
File "game/define-characters-livecomposite.rpy", line 36, in define_image
renpy.image(path_tuple, LiveComposite(size, *args))
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/display/layout.py", line 297, in LiveComposite
rv.add(Position(widget, xpos=xpos, xanchor=0, ypos=ypos, yanchor=0))
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/display/layout.py", line 321, in __init__
self.add(child)
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/display/layout.py", line 167, in add
child = renpy.easy.displayable(d)
File "/Users/thrashneon/Development/Ren'Py Dev/Ren'Py/renpy/easy.py", line 108, in displayable
raise Exception("Not a displayable: %r" % (d,))
Exception: Not a displayable: {}
Darwin-15.6.0-x86_64-i386-64bit
Ren'Py 6.99.14.3135
BlankClean 1.0