0
我试图从附加到字符串的方法得到的整数串随机整数,我已尝试多种不同的事情:<<
和.concat
(虽然相同)+=
以及 我所选择以使该方法由于我的工作将要在 后来加了功能与此代码的问题是不是在等回my string + firstrandomnumber + secondrandomnumber
所以它只返回my string + latestrandomnumber
附加到使用.concat
def machineSlot()
tal1= rand(0..10)
return tal1
end
#makes the a random number
if startBool == true
#game startof
gameRunner=true
puts 'pull the lever with x'
leverPullTry =gets.chomp
while gameRunner
#keeps game running
i=1
slotThread='Your numbers are:'
#initialise game rollcount i and string that keeps the numbers
if leverPullTry=='x'
slotThread.concat(machineSlot.to_s)
#if x was entered the slotThread appends a random number
puts slotThread
#slotThreads current process
puts 'pull the lever with x again'
i+=1
#number of rolls increased
leverPullTry =gets.chomp
else
puts 'try again use type x to pull'
leverPullTry =gets.chomp
#user didnt manage to input anything correct
end
end
end
也许你应该移动'slotThread ='你的号码是:'while循环之外? – August 2014-09-19 00:13:02
好吧,这是尴尬.. 谢谢你的意见tho – user2010884 2014-09-19 00:16:59
嗨@ user2010884是我的回答有帮助吗? – Anthony 2014-09-19 14:16:29