如何在lua中添加技能点限制器?
好吧,所以我正在用 lua 构建一个基于文本的冒险...如果有人认为这是一个坏主意,我是坏主意的大师,但问题是关于升级功能...所以这里是
function lvl()
if xp >= xpr then
level = level + 1
xpr = xpr * 1.5
xp = 0
io.write("Congrats! Somehow you didn't die and lose everything!", "\n")
io.write("Your level is now:" .. level .. "\n")
sp = sp + 6
io.write("Do you want to allocate your " .. sp .. " skill points?", "\n")
sac = io.read()
if sac == "yes" then
io.write("How much do you want to put into strength?", "\n")
strsp = io.read()
if sp == 0 then
io.write("You don't have any skill points!", "\n")
else
str = str + strsp
io.write("Strength: ", str, "\n")
end
io.write("How much do you want to put into dexterity?", "\n")
dexsp = io.read()
if sp == 0 then
io.write("You don't have any skill points!", "\n")
else
dex = dex + dexsp
io.write("Dexterity: ", dex, "\n")
end
io.write("How much do you want to put into constitution?", "\n")
consp = io.read()
if sp == 0 then
io.write("You don't have any skill points!", "\n")
else
con = con + consp
io.write("Constitution: ", str, "\n")
end
io.write("How much do you want to put into intelligence?", "\n")
intsp = io.read()
if sp <= 0 then
io.write("You don't have any skill points!", "\n")
else
int = int + intsp
end
io.write("How much do you want to put into wisdom?", "\n")
wissp = io.read()
if sp <= 0 then
io.write("You don't have any skill points!", "\n")
else
wis = wis + wissp
end
io.write("How much do you want to put into charisma", "\n")
chasp = io.read()
if sp <= 0 then
io.write("You don't have any skill points!", "\n")
else
cha = cha + chasp
end
elseif xp < xpr then
io.write("You didn't level up!", "\n")
end
end
和问题出在技能分配制度上。我不知道如何限制您花费的技能点数量...提前谢谢您!
附: 我对lua很陌生。
Ok so I'm building a Text-based adventure in lua... If anyone thinks that is a bad idea well I am the master of bad ideas but the question is about the level up function... So here it is
function lvl()
if xp >= xpr then
level = level + 1
xpr = xpr * 1.5
xp = 0
io.write("Congrats! Somehow you didn't die and lose everything!", "\n")
io.write("Your level is now:" .. level .. "\n")
sp = sp + 6
io.write("Do you want to allocate your " .. sp .. " skill points?", "\n")
sac = io.read()
if sac == "yes" then
io.write("How much do you want to put into strength?", "\n")
strsp = io.read()
if sp == 0 then
io.write("You don't have any skill points!", "\n")
else
str = str + strsp
io.write("Strength: ", str, "\n")
end
io.write("How much do you want to put into dexterity?", "\n")
dexsp = io.read()
if sp == 0 then
io.write("You don't have any skill points!", "\n")
else
dex = dex + dexsp
io.write("Dexterity: ", dex, "\n")
end
io.write("How much do you want to put into constitution?", "\n")
consp = io.read()
if sp == 0 then
io.write("You don't have any skill points!", "\n")
else
con = con + consp
io.write("Constitution: ", str, "\n")
end
io.write("How much do you want to put into intelligence?", "\n")
intsp = io.read()
if sp <= 0 then
io.write("You don't have any skill points!", "\n")
else
int = int + intsp
end
io.write("How much do you want to put into wisdom?", "\n")
wissp = io.read()
if sp <= 0 then
io.write("You don't have any skill points!", "\n")
else
wis = wis + wissp
end
io.write("How much do you want to put into charisma", "\n")
chasp = io.read()
if sp <= 0 then
io.write("You don't have any skill points!", "\n")
else
cha = cha + chasp
end
elseif xp < xpr then
io.write("You didn't level up!", "\n")
end
end
and the problem lies within the skill allocation system. I cannot figure out how to limit the amount of skill points you spend... Thank you in advance!
PS:
I'm very new to lua.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将字符串从
io.read()
转换为数字...PS: 向用户提供有关
sp
数量和当前str
的信息。< br>例如使用
format()
方法...Convert the string from
io.read()
to a number...PS: Give user info about amount of
sp
and currentstr
.For example with
format()
method...