Layeredimage dynamic image name. NameError

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
sinezub
Newbie
Posts: 3
Joined: Wed Apr 07, 2021 3:38 pm
Contact:

Layeredimage dynamic image name. NameError

#1 Post by sinezub »

this code worked before:

Code: Select all

layeredimage player:
    zoom 0.75
    yalign -0.25

    always "player_base_front"

    group emotion auto:
        attribute neutral default

    if pc.cloth["pants"]:
        "player_[pc.cloth[pants].id]"

    if pc.cloth["shirt"]:
        "player_[pc.cloth[shirt].id]"
but as i switched the os and probably update the renpy to last version, i have a troubles like:

Code: Select all

Exception: In DynamicImage 'player_[pc.cloth[shirt].id]': NameError("Name 'shirt' is not defined.")
my images organized like:

images/characters/player/shirt/basic_shirt.webp
images/characters/player/pants/basic_pants.webp

is there any new rules for that? can't find anything in changelogs

update: error happens because of 8.2.1 update :s just updated the renpy on another device to 8.2.1 and error appears.

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

Re: Layeredimage dynamic image name. NameError

#2 Post by Ocelot »

sinezub wrote: Thu Mar 07, 2024 6:04 pm is there any new rules for that? can't find anything in changelogs
https://www.renpy.org/dev-doc/html/inco ... ible-7-7-0
Interpolation Changes Interpolations in strings are now treated as Python expressions, this results in mostly equivelent behaviour when interpreting fields except when item getters are in use. For example:

Code: Select all

# Previously
e "[player[money]]" #=> player['money']
# But now
e "[player[money]]" #=> player[money]
You need to change "player_[pc.cloth[pants].id]""player_[pc.cloth['pants'].id]" and similar lines.
< < insert Rick Cook quote here > >

sinezub
Newbie
Posts: 3
Joined: Wed Apr 07, 2021 3:38 pm
Contact:

Re: Layeredimage dynamic image name. NameError

#3 Post by sinezub »

Oh, I see. Thanks!
Interpolation Changes Interpolations in strings are now treated as Python expressions, this results in mostly equivelent behaviour when interpreting fields except when item getters are in use. For example:

Code: Select all

# Previously
e "[player[money]]" #=> player['money']
# But now
e "[player[money]]" #=> player[money]
You need to change "player_[pc.cloth[pants].id]""player_[pc.cloth['pants'].id]" and similar lines.
yea, I tried it, but get attribute error. NoneType have no attribute 'style'. looks like it's cant find right image or something like that.

I'm actually curious now about how to refactor the class to make getters for every field in dictionary.

for example, I have a class like:

Code: Select all

class SomeClass:
	def __init__(self):
		self.dictionary = {
			"a": "foo",
			"b": "bar",
			"c": "baz"
		}
	
	#How to make this automatically for every field inside self.dictionary ?
	@property
	def a(self):
		return self.dictionary["a"]

#So i could call everything like
default class = SomeClass()
print(class.a) # "foo" 

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

Re: Layeredimage dynamic image name. NameError

#4 Post by Ocelot »

sinezub wrote: Fri Mar 08, 2024 6:06 am yea, I tried it, but get attribute error. NoneType have no attribute 'style'. looks like it's cant find right image or something like that.
That is another problem and is likely one you should be solving instead.

sinezub wrote: Fri Mar 08, 2024 6:06 am I'm actually curious now about how to refactor the class to make getters for every field in dictionary.

for example, I have a class like:

Code: Select all

class SomeClass:
	def __init__(self):
		self.dictionary = {
			"a": "foo",
			"b": "bar",
			"c": "baz"
		}
	
	#How to make this automatically for every field inside self.dictionary ?
	@property
	def a(self):
		return self.dictionary["a"]

#So i could call everything like
default class = SomeClass()
print(class.a) # "foo" 
Look into __getattr__ Python magic method.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Google [Bot]