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