伦比:为什么这个不管用?

2024-09-26 17:45:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我想根据变量“ImgVal”加载图像

$ ImgVal = []
$ image bob = "b_neutral_%s.png" % ImgVal
$ image bob_sad = "b_sad_%s.png" % ImgVal
$ image bob_happy = "b_happy_%s.png" % ImgVal

Tags: 图像imagepngbobhappyneutralsadimgval
1条回答
网友
1楼 · 发布于 2024-09-26 17:45:05

%运算符传递的值必须是string类型(如果使用%(val_name)s而不是%s,则为字典类型)。在

例如:

ImgVal = 1
# some calculation to evaluate Imgval
print "b_neutral_%s.png" % str(ImgVal) # cast ImgVal from int to str

请注意,如果要使用数组,则需要以下结构:

^{pr2}$

编辑:

我从来没有使用过renpy,但是在有关using python的文档中,您错误地使用了$符号,应该只将其用于原始python代码。%运算符只是python,因此必须使用它并计算字符串,然后将其传递给renpy。这可能可能起作用:

$ ImgVal = "h1c1"
$ img_str = "b_neutral_%s.png" % ImgVal
image bob = img_str
$ img_str = "b_sad_%s.png" % ImgVal
image bob_sad = img_str
$ img_str = "b_happy_%s.png" % ImgVal
image bob_happy = img_str

我唯一可以肯定地告诉您的是,您错误地使用了$,并且您的字符串格式在第一个示例中是错误的。在

相关问题 更多 >

    热门问题