我是Shoes的新品牌,我正在嘗試創建一個簡單的骰子滾輪,允許用戶通過輸入側面數量來選擇自定義尺寸的模具。我的代碼如下:爲什麼rand(變量)暫停我的Shoes程序的執行?
Shoes.app :width => 500, :height => 300 do
flow do
para "Sides: "
@sides = edit_line
end
flow do
button "Roll!" do
@total = 1 + rand(sides)
alert @total
end
end
end
我在編輯行中輸入一個數字,點擊按鈕,沒有任何反應。
如果我用@total = rand(20)
代替@total = rand(sides)
,程序執行得很好,但是當然只產生1-20的隨機數。
我嘗試了像rand(@sides)
這樣的變化,無濟於事。
我設計了一個類似的程序,只是在普通的Ruby中使用rand(sides)
而沒有問題,但是如果我嘗試在鞋上做它,它什麼也不做。
它應該是@sides? – AShelly 2011-05-18 01:23:17
+1 @helper:'@total = 1 + rand(sides)'應該是@total = 1 + rand(@sides)' – 2011-05-18 02:30:24