Q:

Why does rand(variable) halt my Shoes program's execution?

I am brand new to Shoes, and am trying to create a simple dice roller that allows the user to choose a custom-sized die by inputting the number of sides.  My code is as follows:
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

I input a number in the edit line, click the button, and nothing happens.  
If I replace @total = rand(sides) with @total = rand(20), the program executes just fine, but of course only produces random numbers from 1-20.  
I tried variations like rand(@sides), to no avail.  
I designed a similar program in just plain Ruby which uses  rand(sides) without a problem, but if I try to do it in Shoes, it does nothing. 

A:

You have a couple mistakes. First, use @sides, not sides. That way, you're referencing the same variable you set earlier.
Second, the type of @sides is Shoes::EditLine. Which is good, since you need to look up the text dynamically. When you want the text of @sides, call @sides.text, which returns a String. Of course, in this context, you'll need to convert that to an integer suitable for input to rand, so you'll use @sides.text.to_i.
(Of course, the standard don't-trust-users caveats apply. In reality, you'll want to check your input for invalid input and do something useful.)
Long story short, replace @total = 1 + rand(sides) with @total = 1 + rand(@sides.text.to_i) and you'll be good.

