我试着让它每次重复时 ks 的数量增加 1 但这认为 oks 是未定义的我已经尝试添加(ks,1)但是它返回 ks 是未定义的并且如果我将 ks 或 oks 为零它每次返回相同的数字我该怎么做如果有办法?它适用于基于文本的游戏“练级”系统。我用replit
ms,oms,vs,ovs,es,oes 是变量的不同版本,对不同的字符类具有相同的功能。
delprint 是一个用于模拟打字的打印函数。“chartype”是字符类型。
当前代码:
if chartype == ("knight"):
ks = add(oks, 1)
oks = ks
if chartype == ("mage"):
ms = add(oms, 1)
oms = ms
if chartype == ("viking"):
vs = add(ovs, 1)
ovs = vs
if chartype == ("engineer"):
es = add(oes, 1)
oes = es
delprint(f"Level as a {chartype} has increased by one to {ks}!")
我试过了:
if chartype == ("knight"):
ks = add(ks, 1)
if chartype == ("mage"):
ms = add(ms, 1)
if chartype == ("viking"):
vs = add(vs, 1)
if chartype == ("engineer"):
es = add(es, 1)
delprint(f"Level as a {chartype} has increased by one to {ks}!")
我也试过了:
timesrun = 0
if chartype == ("knight"):
ks = add(timesrun, 1)
if chartype == ("mage"):
ms = add(timesrun, 1)
if chartype == ("viking"):
vs = add(timesrun, 1)
if chartype == ("engineer"):
es = add(timesrun, 1)
timesrun = add(timesrun, 1)
delprint(f"Level as a {chartype} has increased by one to {ks}!")
我能想到的最简单的方法就是这个,但是每次函数运行时它都会重复 1
的相同输出 oks=("0")
oms=("0")
ovs=("0")
oes=("0")
if chartype == ("knight"):
ks = add(oks, 1)
oks = ks
if chartype == ("mage"):
ms = add(oms, 1)
oms = ms
if chartype == ("viking"):
vs = add(ovs, 1)
ovs = vs
if chartype == ("engineer"):
es = add(es, 1)
oes = es
delprint(f"Level as a {chartype} has increased by one to {ks}!")
我希望输出是
第一次:1
第二次:2
第三次:3
等
所以我想我想问的是,即使我不止一次调用该函数,我如何将这些变量定义为 0 一次