加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 有丘直方 于 2016-1-19 13:26 编辑
最近刚刚开始学RGSS2……想做个脚本程序试试手……不过很遗憾的是第一个脚本就出现一个错误……帮我看看有什么错误好吗……
#============================================================================== # ■ Calculator #------------------------------------------------------------------------------ # 可以计算算式的程序。 #============================================================================== #-------------------------------------------------------------------------- # ● 输入变量 #-------------------------------------------------------------------------- first_count = 34 second_count = 28.67 symbol = "-" #-------------------------------------------------------------------------- # ● 计算过程 #-------------------------------------------------------------------------- if symbol == "+" # 加法 def results result = first_count + second_count print "#{first_count} + #{second_count} = #{result}" end elsif symbol == "-" # 减法 def results result = first_count - second_count print "#{first_count} - #{second_count} = #{result}" end elsif symbol == "*" # 乘法 def results result = first_count * second_count print "#{first_count} * #{second_count} = #{result}" end elsif symbol == "/" # 除法 def results result = first_count / second_count print "#{first_count} / #{second_count} = #{result}" end elsif symbol == "%" # 取模 def results result = first_count % second_count print "#{first_count} % #{second_count} = #{result}" end elsif symbol == "**" # 乘方 def results result = first_count ** second_count print "#{first_count} ** #{second_count} = #{result}" end else # 错误算式 def results print "ERROR!!!" end end #-------------------------------------------------------------------------- # ● 输出结果 #-------------------------------------------------------------------------- results
#==============================================================================
# ■ Calculator
#------------------------------------------------------------------------------
# 可以计算算式的程序。
#==============================================================================
#--------------------------------------------------------------------------
# ● 输入变量
#--------------------------------------------------------------------------
first_count = 34
second_count = 28.67
symbol = "-"
#--------------------------------------------------------------------------
# ● 计算过程
#--------------------------------------------------------------------------
if symbol == "+" # 加法
def results
result = first_count + second_count
print "#{first_count} + #{second_count} = #{result}"
end
elsif symbol == "-" # 减法
def results
result = first_count - second_count
print "#{first_count} - #{second_count} = #{result}"
end
elsif symbol == "*" # 乘法
def results
result = first_count * second_count
print "#{first_count} * #{second_count} = #{result}"
end
elsif symbol == "/" # 除法
def results
result = first_count / second_count
print "#{first_count} / #{second_count} = #{result}"
end
elsif symbol == "%" # 取模
def results
result = first_count % second_count
print "#{first_count} % #{second_count} = #{result}"
end
elsif symbol == "**" # 乘方
def results
result = first_count ** second_count
print "#{first_count} ** #{second_count} = #{result}"
end
else # 错误算式
def results
print "ERROR!!!"
end
end
#--------------------------------------------------------------------------
# ● 输出结果
#--------------------------------------------------------------------------
results
提示23行有错误。
line 23: NameError occurred.
undefined local variable or method 'first_count' for main:Object
以上是错误信息,谁能看看有没有什么错?抱歉我看不懂英语。 |