-1

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?

Donoru
  • 115
  • 1
  • 15

1 Answers1

1

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
Beartech
  • 6,173
  • 1
  • 18
  • 41
  • I'm asking if you can use it an if/else statement, and I don't think you can. I've already tried it. – Donoru May 02 '20 at 19:27
  • You need to be more specific. "it can't seem to work" doesn't tell me what's going on. What platform are you on (Mac, PC, etc?). In the shoes menu there is a choice for "console". Make sure the console is open and try again. Then edit your original question and paste in the messages from the console. – Beartech May 02 '20 at 19:30
  • You need to post exactly what code you tried in your original question. – Beartech May 02 '20 at 19:32