0
I’m having trouble in methods with passing parameter, the code runs, but it moves when I pass var within one method and receives as parameter in another. I’m new to Ruby.
def player_welcome
puts "Seja bem vindo ao Jogo de Adivinhação !!"
puts "Criado por Thiago De Bonis Carvalho Saad Saud"
end
def generate_number_raffled
number_raffled = 100
number_raffled.to_i
end
def player_choice_name
puts "Qual seu nome jogador?"
player_name = gets
player_name.to_s
end
def player_choice_attempts(player_name)
puts "Quantas tentativas gostaria de ter " + player_name + "?"
number_attempts = gets
number_attempts.to_i
end
def play_the_game(player_name,number_attempts)
puts " " + player_name + "você tem " + number_attempts + "."
for player_attempts in 1..number_attempts
puts "Adivinhe um número entre 0 e 200..."
player_kick = gets
if check_number_raffled(player_kick,number_raffled)
break
end
end
player_kick.to_i
end
def check_number_raffled(player_kick,number_raffled)
if player_kick == number_raffled
puts "Você Acertou !!"
return true
end
if player_kick > number_raffled
puts "Você errou!!"
puts "Você digitou um número maior que o do Sorteado, tente novamente.."
else
puts "Você errou!!"
puts "Você digitou um número menor que o do Sorteado, tente novamente.."
end
end
player_welcome
player_choice_name
player_choice_attempts(player_name)
play_the_game(player_name,number_attempts)
I still haven’t learned this part of using @, only the #{nameVar} inside some String, would have another more practical way for those who are beginner, pass these variable parameters of functions for other functions? I added the following line of code, but it keeps repeating the code now, as if inside a While or calling the function all the time. '-'
– user50860
Image: https://scontent.fsdu5-1.fna.fbcdn.net/v/t1.0-9/14713772_206737486415009_961632780851287076_n.jpg?oh=e484d87d21d415e4ddae82a9b1505bd2&oe=58A030DB
– user50860