Ren'Py 6.99- How to save image via CDD? (renpygame gone now)

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
morte111
Newbie
Posts: 4
Joined: Tue Mar 31, 2015 8:31 pm
Projects: AnimeGen
Location: Australia
Contact:

Ren'Py 6.99- How to save image via CDD? (renpygame gone now)

#1 Post by morte111 »

Thanks to anyone who can assist -
By way of intro, I have posted this
http://lemmasoft.renai.us/forums/viewto ... it=surface
in a separate subforum just to self-track my progress on Ren'Py 6.99 and the need to use Creator Defined Displayables (CDD)
now that renpygame has been made incompatible/obsolete with implementation of pygame_SDL2.

I accept the need to use CDD and break away from renpygame,
and have successfully used a cutdown version of Appearing class from the doco
http://www.renpy.org/doc/html/udd.html
with the logo.png file as a test case to save a Surface as a PNG file
using a combination of:
- defining an image in Ren'Py ,
- instantiating my custom CDD with that image as a parameter,
- calling renpy.load_surface within a CDD custom method with self.child parameter,
- and the pygame_SDL2.image.save method with that Surface and a path/filename as parameters to output a PNG file.

That's great for "logo.png".
However, I cannot get my own generated image to save as PNG.
The image I need to save is a LiveComposite of eight paperdoll layered images,
which I am guessing I need to flatten to a single texture before my CDD will accept it as an 'image' per se.

So I have done that using the renpy Flatten method, using the output image as a parameter for the CDD.

However that image is not being accepted as an image, it is being rejected either as:
NameError: global name 'charflat' is not defined
or
Exception: Expected an image, but got a general displayable.

I will update this with full tracebacks and animegen.rpy code attachment for clarity.

So firstly, I have my LiveComposite image which my custom screen language definition successfully uses (see code attachment for draw_char definition & screen),
and another image declaration to Flatten that LiveComposite.
image char = DynamicDisplayable(draw_char)
image charflat=Flatten("char")


In testing, I tried three ways to instantiate the CDD class which I have named PNG
before calling the CDD method to save the image as a PNG via python statement: myPNG.imagesave(pngpath)

1. myPNG=PNG("logo.png")
This works perfectly, outputting a file named test.png to my saves subdirectory, which matches logo.png
- so the image is presumably being loaded from disk to image cache and from there into the CDD self.child, to a load_surface, and to the image.save.

2. myPNG=PNG("charflat")
This gets me the "Exception: Expected an image, but got a general displayable."

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/animegen.rpy", line 372, in script
    $myPNG.imagesave(pngpath)
  File "game/animegen.rpy", line 372, in <module>
    $myPNG.imagesave(pngpath)
  File "game/animegen.rpy", line 27, in imagesave
    surf=renpy.load_surface(self.child)
Exception: Expected an image, but got a general displayable.

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

Full traceback:
  File "game/animegen.rpy", line 372, in script
    $myPNG.imagesave(pngpath)
  File "E:\dev\renpy\renpy-6.99.3-sdk\renpy\ast.py", line 785, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "E:\dev\renpy\renpy-6.99.3-sdk\renpy\python.py", line 1445, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/animegen.rpy", line 372, in <module>
    $myPNG.imagesave(pngpath)
  File "game/animegen.rpy", line 27, in imagesave
    surf=renpy.load_surface(self.child)
  File "E:\dev\renpy\renpy-6.99.3-sdk\renpy\display\im.py", line 1601, in load_surface
    return cache.get(image(im))
  File "E:\dev\renpy\renpy-6.99.3-sdk\renpy\display\im.py", line 1564, in image
    return image(arg.target, loose=loose, **properties)
  File "E:\dev\renpy\renpy-6.99.3-sdk\renpy\display\im.py", line 1579, in image
    raise Exception("Expected an image, but got a general displayable.")
Exception: Expected an image, but got a general displayable.

Windows-7-6.1.7601-SP1
Ren'Py 6.99.3.404
AnimeGen 0.0
3. myPNG=PNG(charflat)
This gets me the "NameError: global name 'charflat' is not defined":

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/animegen.rpy", line 370, in script
    $myPNG=PNG(charflat)
  File "game/animegen.rpy", line 370, in <module>
    $myPNG=PNG(charflat)
NameError: name 'charflat' is not defined

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

Full traceback:
  File "game/animegen.rpy", line 370, in script
    $myPNG=PNG(charflat)
  File "E:\dev\renpy\renpy-6.99.3-sdk\renpy\ast.py", line 785, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "E:\dev\renpy\renpy-6.99.3-sdk\renpy\python.py", line 1445, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/animegen.rpy", line 370, in <module>
    $myPNG=PNG(charflat)
NameError: name 'charflat' is not defined

Windows-7-6.1.7601-SP1
Ren'Py 6.99.3.404
AnimeGen 0.0
So, I will keep testing and crossing fingers for a response, but as that initial link shows, I have already jumped a lot of hurdles just to get this far, I expect many more to come.

Thanks again for reading, I really appreciate your time!
Attachments
animegen.rpy
AnimeGen - paper doll generator/PNG file saver
(13.23 KiB) Downloaded 170 times

Post Reply

Who is online

Users browsing this forum: No registered users