Ren-py:为什么这行不通?
Ren-py: Why doesn't this work?
我希望根据变量加载图像 "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
%
运算符传递的值必须是字符串类型(或字典,如果您使用 %(val_name)s
而不是 %s
)。
例如:
ImgVal = 1
# some calculation to evaluate Imgval
print "b_neutral_%s.png" % str(ImgVal) # cast ImgVal from int to str
请注意,如果您想使用数组,则需要这样的结构:
ImgVal = [1, 2, 3, 4]
for i in ImgVal:
print "b_neutral_%s.png" % str(i)
编辑:
我从来没有用过 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
我唯一可以肯定的告诉你的是你使用 $
不正确,而且你的第一个例子中的字符串格式是错误的。
我希望根据变量加载图像 "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
%
运算符传递的值必须是字符串类型(或字典,如果您使用 %(val_name)s
而不是 %s
)。
例如:
ImgVal = 1
# some calculation to evaluate Imgval
print "b_neutral_%s.png" % str(ImgVal) # cast ImgVal from int to str
请注意,如果您想使用数组,则需要这样的结构:
ImgVal = [1, 2, 3, 4]
for i in ImgVal:
print "b_neutral_%s.png" % str(i)
编辑:
我从来没有用过 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
我唯一可以肯定的告诉你的是你使用 $
不正确,而且你的第一个例子中的字符串格式是错误的。