for loop image creation question [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
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

for loop image creation question [SOLVED]

#1 Post by trooper6 »

Greetings, I was making some code for one of the posters here and noticed a funny thing.

This code works:

Code: Select all

default grid_pos = OrderedDict([('a1', 0), ('a2', 0), ('a3', 0), ('b1', 0), ('b2', 0), ('b3', 0), ('c1', 0), ('c2', 0), ('c3', 0)])
        
init python:
    for x in ["idle", "hover"]:
        for i in ["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]:
            renpy.image("{0}_{1}".format(i, x), ConditionSwitch(
                "grid_pos['{0}'] == 0".format(i), "images/mark_{0}.png".format(x),
                "grid_pos['{0}'] == 1".format(i), "images/wood_{0}.png".format(x),
                "grid_pos['{0}'] == 2".format(i), "images/steel_{0}.png".format(x)))
However, this code doesn't work:

Code: Select all

default grid_pos = OrderedDict([('a1', 0), ('a2', 0), ('a3', 0), ('b1', 0), ('b2', 0), ('b3', 0), ('c1', 0), ('c2', 0), ('c3', 0)])

init python:
    for x in ["_idle", "_hover"]:
        for i in ["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]:
            renpy.image("{0}_{1}".format(i, x), ConditionSwitch(
                "grid_pos['{0}'] == 0".format(i), "images/mark{0}.png".format(x),
                "grid_pos['{0}'] == 1".format(i), "images/wood{0}.png".format(x),
                "grid_pos['{0}'] == 2".format(i), "images/steel{0}.png".format(x)))
Why does the former work but the latter doesn't when the only difference if "idle" vs "_idle"?
Last edited by trooper6 on Thu May 18, 2017 12:46 am, edited 1 time in total.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: for loop image creation question

#2 Post by Ocelot »

How exactly it fails? Notice that in image definition image name would contain two underscores, not one; are you using the right name?
< < insert Rick Cook quote here > >

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: for loop image creation question

#3 Post by trooper6 »

Two underscores! That fixed it. Thanks for pointing out that oversight!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: No registered users