using images as variable[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
User avatar
cedes
Regular
Posts: 44
Joined: Fri Aug 04, 2017 3:33 pm
itch: cedes
Contact:

using images as variable[solved]

#1 Post by cedes »

I'm trying to use a random picked image of a scratch to appear, but I can't get the image to show up correctly?

Code: Select all

label scratch_pic:

    $ scratch= "should be image"



    $ scratch6 = 'images/scratch6.png'
    $ scratch5 = 'images/scratch5.png'
    $ scratch4 = 'images/scratch4.png'
    $ scratch3 = 'images/scratch3.png'
    $ scratch2 = 'images/scratch2.png'
    $ scratch1 = 'images/scratch1.png'

    $r = renpy.random.randint(1,6)

    "[scratch] [r]"

    if r == 1:
        $scratch = scratch1
    if r == 2:
        $scratch = scratch2
    if r == 3:
        $scratch = scratch3
    if r == 4:
        $scratch = scratch4
    if r == 5:
        $scratch = scratch5
    if r == 6:
        $scratch = scratch6

    return
This is the code I'm using to try to randomly pick an image, and using this:

Code: Select all

show scratch at ec1
to try to show it at a userdefined location, but it just shows up as a shadow.

The image is in the right location, if i write show scratch4 then it shows up fine but I can't get it down in this way!
Last edited by cedes on Sun Dec 13, 2020 6:13 pm, edited 1 time in total.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: using images as variable

#2 Post by hell_oh_world »

should be...

Code: Select all

show expression scratch at ec1
also might be the shortest and easiest way...

Code: Select all

show expression "images/scratch{}.png".format(renpy.random.randint(1, 6)) at ec1

User avatar
cedes
Regular
Posts: 44
Joined: Fri Aug 04, 2017 3:33 pm
itch: cedes
Contact:

Re: using images as variable[solved]

#3 Post by cedes »

oh perfect thanks! Works perfect now, thanks for the shortcut as well!

User avatar
cedes
Regular
Posts: 44
Joined: Fri Aug 04, 2017 3:33 pm
itch: cedes
Contact:

Re: using images as variable[solved]

#4 Post by cedes »

Question, how do I get to hide the image?

I tried to hide image and it's showing up as invalid!

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: using images as variable[solved]

#5 Post by hell_oh_world »

You tag them then hide them using that tag.

Code: Select all

show expression "something.png" as something
hide something

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Ocelot