Reputation: 155
I'm making sort of a guessing game using the ruby GUI framework Shoes. I am very, VERY new to it and would like to know if it's possible to generate a random integer. In regular ruby, for example, if you wanted to generate a number from one to ten, the code would be
int = 1+rand(10)
Can I use this same code or is there Shoes syntax for this?
Upvotes: -1
Views: 55
Reputation: 6411
Shoes is a Ruby framework. It adds a GUI to Ruby but the code is still Ruby. You could use your code to generate the number. Are you asking how to use that generated number in a widget?
example:
Shoes.app { alert("Your random number is: #{int = 1+rand(10)}") }
You mention in your comment using if.. then
. You have to specify how you want to use it. Some "if" is built in. So if you what something to happen IF a button is clicked you could:
Shoes.app do
stack {
@button1 = button "Would you like a random number?"
@button1.click { para alert("Your random number is: #{int = 1+rand(10)}") }
}
end
Or if you want to use an if
statement for logic you could do this:
require 'date'
Shoes.app do
stack {
@button1 = button "Would you like a random number?"
@button1.click {
if Date.today.day.odd?
para alert("Your random number is: #{int = 1+rand(10)}")
else
para alert("Today is an even day, I can't do that. Come back tomorrow")
end }
}
end
Upvotes: 1