2024-09-26 17:45:05 发布
网友
我想根据变量“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
%运算符传递的值必须是string类型(如果使用%(val_name)s而不是%s,则为字典类型)。在
%
%(val_name)s
%s
例如:
ImgVal = 1 # some calculation to evaluate Imgval print "b_neutral_%s.png" % str(ImgVal) # cast ImgVal from int to str
请注意,如果要使用数组,则需要以下结构:
编辑:
我从来没有使用过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
我唯一可以肯定地告诉您的是,您错误地使用了$,并且您的字符串格式在第一个示例中是错误的。在
%
运算符传递的值必须是string类型(如果使用%(val_name)s
而不是%s
,则为字典类型)。在例如:
请注意,如果要使用数组,则需要以下结构:
^{pr2}$编辑:
我从来没有使用过renpy,但是在有关using python的文档中,您错误地使用了
$
符号,应该只将其用于原始python代码。%
运算符只是python,因此必须使用它并计算字符串,然后将其传递给renpy。这可能可能起作用:我唯一可以肯定地告诉您的是,您错误地使用了
$
,并且您的字符串格式在第一个示例中是错误的。在相关问题 更多 >
编程相关推荐