我正在尝试在基于 QB64 Txt 的冒险中创建一个调平系统
Posted
技术标签:
【中文标题】我正在尝试在基于 QB64 Txt 的冒险中创建一个调平系统【英文标题】:I'm trying to create a leveling system in QB64 Txt Based Adventure 【发布时间】:2019-01-15 19:59:23 【问题描述】:我想要发生的是每当expertotal%
等于levelup%
时,我想将1
添加到level%
。我试过level% + 1
,但出现语法错误。
然后每当level%
上升时,我想将levelup%
和experience%
乘以1.25
。
这是我的代码:
do
sub lvl
level% = 1
levelup% = 50
experience% = 5
ExperTotal% = 0
if Expertotal% = levelup% then 'something here to add 1 to level%
while Expertotal% = levelup%
' multiply them both by 1.25
wend
loop
end sub
【问题讨论】:
level% = level% + 1
有什么问题?
抱歉,在我输入“if Expertotal% = levelup% then level% + 1”之前回复晚了,但一位朋友告诉我,我必须把那一行写下来,不过谢谢你的帮助
不,如果if
语句写在一行上,您可以将同一行用于完成该语句的指令。问题是由于level% + 1
确实没有任何基本指令。要增加level%
,您必须使用level% = level% + 1
。
【参考方案1】:
稍微重写你的代码我是这样的:
REM What I want to happen is whenever expertotal% is equal to levelup%,
REM I want to add 1 to level%.
REM I've tried level% + 1, but I get a syntax error.
REM Then whenever level% goes up,
REM I want to multiply levelup% and experience% to be multiplied by 1.25.
level% = 1
levelup% = 50
experience% = 48
ExperTotal% = 48
DO
COLOR 15
PRINT "Increase exp(y/n)";: INPUT x$
IF LCASE$(x$) = "y" THEN
GOSUB lvl
COLOR 14
PRINT "level="; level%
PRINT "experience="; experience%
ELSE
EXIT DO
END IF
LOOP
COLOR 7
END
lvl:
' increase experience total
ExperTotal% = ExperTotal% + 1
' compare experience to levelup
IF ExperTotal% = levelup% THEN
' add 1 to level when experience equal
level% = level% + 1%
' multiply levelup and experience
levelup% = levelup% * 1.25
experience% = experience% * 1.25
COLOR 12
PRINT "level increased.."
END IF
RETURN
END
【讨论】:
虽然因为你要乘以 1.25,你可能想要将一些变量更改为单精度.. 所以这将是一种更精确的练级方式?我目前拥有的是SUB
`SUB lvl level% = 1 levelup% = 50 experience% = 5`experiencetotal% = 0 IF experiencetotal% = levelup% THEN level% = level% + 1`END IF END SUB`跨度>
我只是为了更简单的测试调整了变量;您可以将它们恢复为原始值。以上是关于我正在尝试在基于 QB64 Txt 的冒险中创建一个调平系统的主要内容,如果未能解决你的问题,请参考以下文章