How to call for a variable within a factor scale

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.
Message
Author
jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

How to call for a variable within a factor scale

#1 Post by jac600 »

Question:

How do I get [test_image] to read as "test'?

In essence, I want im.FactorScale("[test_image]/head_1.png", 0.3) to read as im.FactorScale("test/head_1.png", 0.3)

Simplified Sample Of The Problem:

default test_image = "test"
default test_file = im.FactorScale("[test_image]/head_1.png", 0.3)

label issue_test:
show image test_file
return

Error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While loading <'FactorScale' <'Image' u'[test_image]/head_1.png'> 0.3 0.3 True>:
  File "game/script.rpy", line 260, in script call
    call unlockable_menu
  File "game/script.rpy", line 386, in script
    ""
  File "renpy/common/000window.rpy", line 98, in _window_auto_callback
    _window_show()
  File "renpy/common/000window.rpy", line 60, in _window_show
    renpy.with_statement(trans)
IOError: Couldn't find file '[test_image]/head_1.png'.

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to call for a variable within a factor scale

#2 Post by Alex »


jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

Re: How to call for a variable within a factor scale

#3 Post by jac600 »

Here's a response back from him.

Works: default test_file = "[test_image]/head_1.png"
Doesn't Work: default test_file = im.FactorScale("[test_image]/head_1.png", 0.3)

Within I'm.FactorScale it doesn't seem to be picking up the interpolation.
See original error.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: How to call for a variable within a factor scale

#4 Post by xavimat »

Have you tried this?:

Code: Select all

default test_file = im.FactorScale(test_image + "/head_1.png", 0.3)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

Re: How to call for a variable within a factor scale

#5 Post by jac600 »

Yep worked! You're the best.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to call for a variable within a factor scale

#6 Post by kivik »

Will that work when test_image changes value?

jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

Re: How to call for a variable within a factor scale

#7 Post by jac600 »

Sorry, further development. This is the example he gave.

So this is sort of an extension of the problem stated prior.
default test_image_ = ["test_1","test_2","test_3"]
image test_file = im.FactorScale(test_image_[1] + "/head_1.png", 0.3)

label issue_test:
show image test_file
return

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 167, in script
    image test_file = im.FactorScale(test_image_[1] + "/head_1.png", 0.3)
  File "game/script.rpy", line 167, in <module>
    image test_file = im.FactorScale(test_image_[1] + "/head_1.png", 0.3)
NameError: name 'test_image_' is not defined

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to call for a variable within a factor scale

#8 Post by kivik »

If I'm not mistaken, image declaration happens during init, so your default test_image line actually happens after image and therefore test_image_ hasn't been defined yet.


Not sure if an alternative solution would work reading back to your original question. I just had a look and it seems you're just trying to scale the image, if that's the case, you may be able to achieve the same thing with dynamic images with a zoom: https://www.renpy.org/doc/html/changelo ... mic-images

So I'd try something like this:

Code: Select all

image test_file:
    "[test_image]/head_1.png"
    zoom 0.3
Then whatever is in test_image will be interpolated into your test_file image (although I'd have thought you want test_image to be the image name and test_file to be the folder name :P)

I actually use dynamic images a lot and I've used that type of image declaration myself and it works :)

jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

Re: How to call for a variable within a factor scale

#9 Post by jac600 »

Essentially what we're trying to achieve is an extension of such.

image test_file:
test_image_[1] + "/head_1.png"
zoom 0.3

This doesn't work because the images are loaded before the code that defines test_image_[1]. Is there any way to work around this?

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to call for a variable within a factor scale

#10 Post by kivik »

Yes, don't use test_image_[1] as a variable outside the double quotes, use it as interpolated variable inside the double quotes, like my example :)

"[variable_name]" is renpy's way of interpolating variables at runtime, so whatever the variable_name contains when the image is displayed, that's what gets interpolated. Here's the documentation about it: https://www.renpy.org/doc/html/text.htm ... ating-data

I'd ditch the indexing as well as you weren't using an index in your original example, I'm under the impression you guys will just change the variable to what you need it to be.

jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

Re: How to call for a variable within a factor scale

#11 Post by jac600 »

Greetings Kivik,

Such interpolation works when done with text, however it isn't loading properly when used inside of an image declaration, hints the original issue. Likewise the indexing is relevant as this system will be applied to multiple characters within the game.

Is there any way that such indexes can be used within interpolation?

Thanks for all the help so far, you all are absolutely amazing!

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to call for a variable within a factor scale

#12 Post by Alex »

There was a post about how things work in Ren'Py - viewtopic.php?f=51&t=39572

And for your main question, I'm not quite understand what you try to achieve - declare lots of images in a loop using variable for the part of their names or create an image that will change its appearence acorrding to variable value?
If the last, then try to use dynamic images (example in a link in my previouse post) or ConditionSwitch
https://www.renpy.org/doc/html/displaya ... splayables

viewtopic.php?f=51&t=19063
viewtopic.php?f=51&t=26612

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to call for a variable within a factor scale

#13 Post by kivik »

jac600 wrote: Fri May 11, 2018 8:01 pm Greetings Kivik,

Such interpolation works when done with text, however it isn't loading properly when used inside of an image declaration, hints the original issue. Likewise the indexing is relevant as this system will be applied to multiple characters within the game.

Is there any way that such indexes can be used within interpolation?

Thanks for all the help so far, you all are absolutely amazing!
My understanding is that Interpolation doesn't work in im.FactorScale, but it works in Dynamic Images, unless you guys are using an older version of Renpy? https://www.renpy.org/doc/html/changelo ... mic-images

Your first post doesn't include indexes so I assume that requirement has changed? Or you just weren't showing the indexing?

Code: Select all

default test_image = "test"
default test_file = im.FactorScale("[test_image]/head_1.png", 0.3)
Either way, I believe indexing is allowed in text interpolation: https://www.renpy.org/doc/html/text.htm ... ating-data

So it should work if you just declare it as an image. Since interpolation happens at the point of render / runtime, the variable doesn't have to be declared at that point. Here're a couple of examples of my image declarations:

Code: Select all

image catherine:
    At("portrait/catherine/[catherine.makeup]-[catherine.outfit]-[catherine.Contentment.state].png", darken)
    zoom 0.9
image catherine speaking:
    "portrait/catherine/[catherine.makeup]-[catherine.outfit]-[catherine.Contentment.state].png"
    zoom 1.0
My catherine object is declared at label level after init, and my images work fine :)

jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

Re: How to call for a variable within a factor scale

#14 Post by jac600 »

Greetings Kivik,

We had always needed indexing, we just tried to simplify the original problem and didn't expect indexing to cause any errors outside the scope of the issue at hand.

So from what you're saying interpolation won't work within a Im.FactorScale which we're currently using to reduce image dimensions within our dynamic images. While we can get rid of the FactorScale this does create two new problems. Is there an alternative way to zoom an entire dynamic image? And is it feasible to have the program read an index when performing interpolation?

Again, we appreciate all of the help thus far! Sorry for being an issue.

Alternatively with what Alex posted, is it possible to create a dynamic image that implements condition switches for each piece? This may be able to substitute for the indexes.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to call for a variable within a factor scale

#15 Post by kivik »

jac600 wrote: Sat May 12, 2018 4:16 pm Greetings Kivik,

We had always needed indexing, we just tried to simplify the original problem and didn't expect indexing to cause any errors outside the scope of the issue at hand.

So from what you're saying interpolation won't work within a Im.FactorScale which we're currently using to reduce image dimensions within our dynamic images. While we can get rid of the FactorScale this does create two new problems. Is there an alternative way to zoom an entire dynamic image? And is it feasible to have the program read an index when performing interpolation?

Again, we appreciate all of the help thus far! Sorry for being an issue.

Alternatively with what Alex posted, is it possible to create a dynamic image that implements condition switches for each piece? This may be able to substitute for the indexes.
Hey jac600, I'm not sure if I'm missing something here, but the solution I'm proposing (with sample code from my own game) is a dynamic image that zooms the entire image. Have you actually tried implementing it?

Post Reply

Who is online

Users browsing this forum: Andredron