Forum: Ruby Undefined method and i need some help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3681234a4a6353a9eb8f3dd8efaba25e?d=identicon&s=25 Jerome Jeje (chocoopanda)
on 2016-09-22 14:33
Hi, i'm a beginner in Ruby and i'm doing a really easy "game".

My problem is that i want to test if the user press 1 then roll some
dices but i can't use my method ><'

I join you the code and thank you for hepling

 tot = 0
    def rollDice
        tot = 0
        puts "You roll the dices"
        d1 = rand(1..6)
        puts "Dice 1: #{d1}"
        d2 = rand(1..6)
        puts "Dice 2: #{d2}"
        d3 = rand(1..6)
        puts "Dice #{d3}"
        tot = d1 + d2 + d3
        puts "Your score is  #{tot}"
        return tot
    end

[some puts but not important for the coding ]

puts "Press 1 to play or 2 to leave"
value = gets.chomp
    if value == "1"
        s1 = self.rollDice
        puts "Why it doesnt work :C #{s1}"

[i have a player class but its not important for the moment]
        #player1 = Joueur.new(j1)
        #player2 = Joueur.new(j2)

        #player1.score
        #player2.score
    elsif value== "2"
        exit
    end
3681234a4a6353a9eb8f3dd8efaba25e?d=identicon&s=25 Jerome Jeje (chocoopanda)
on 2016-09-22 15:09
up please
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2016-09-22 16:47
s1 = self.rollDice   >>>>    s1 = rollDice

I am 'up' enough  ?
3681234a4a6353a9eb8f3dd8efaba25e?d=identicon&s=25 Jerome Jeje (chocoopanda)
on 2016-09-23 09:18
Regis d'Aubarede wrote in post #1185066:
> s1 = self.rollDice   >>>>    s1 = rollDice
>
> I am 'up' enough  ?

It change nothing i still have the error with the method :/
But thank you for helping me
3681234a4a6353a9eb8f3dd8efaba25e?d=identicon&s=25 Jerome Jeje (chocoopanda)
on 2016-09-23 10:27
Jerome Jeje wrote in post #1185069:
> Regis d'Aubarede wrote in post #1185066:
>> s1 = self.rollDice   >>>>    s1 = rollDice
>>
>> I am 'up' enough  ?
>
> It change nothing i still have the error with the method :/
> But thank you for helping me

http://pastebin.com/DiGV4nHC this is all my code
3681234a4a6353a9eb8f3dd8efaba25e?d=identicon&s=25 Jerome Jeje (chocoopanda)
on 2016-09-23 11:18
I have found the solution, the problem was i didn't do a "static" method
but now i have modified my code and all work on purpose :D
This topic is locked and can not be replied to.