Dungeons와 Dragons를위한 전투 조수 인 나 자신과 몇 명의 친구들을 만들고 있습니다. 대부분의 유지 트랙이 꽤 반복적이어서 Ruby를 할 수 있다고 생각했습니다. 그것은 잘 가고 있었지만 지금은 장애물을 맞았습니다. 정의되지 않은 메소드 : 변수?
이
내 코드`
def party8
party7
puts "Last one! What's your eighth player's name?"
player8name = gets.chomp
puts "What's their AC?"
player8ac = gets.chomp.to_i
puts "Got it. What's their max HP?"
player8maxhp = gets.chomp.to_i
end
def partysetup
puts "hi"
if 8 == playercount
party8
else
party1
end
end
#intro----------------------------------------------------------------------
puts "-Hello. I am l1fecount, the DM's combat assistant."
puts "-Before we begin, would you like to see in-depth information about me?"
infoq = gets.chomp
infoq.downcase!
if infoq == "yes"
puts "-Very well, I'm glad to explain. I am l1fecount, a program designed to keep track of up to 5 types of mobs, with up to 10
of each. I can also keep track of up to 8 players. I keep track of turn order, current HP vs max HP, CR, and armor
class. I am still very young, so please be patient with me. ^^; "
else
puts "-Right then."
end
puts "-So, let's begin."
#intro end----------------------------------------------------------------
#party---------------------------------------------------------------------
loop do
puts "How many players today?"
playercount = gets.chomp.to_i
if 0 >= playercount
puts "You can't have no players in a party. That's not D&D, that's you having no friends."
redo
elsif 8 < playercount
puts "Hey now, that's a huge party. I can only handle eight players at once."
redo
elsif 8 >= playercount
break
else
puts "A number between 1 and 8, please."
redo
end
end
partysetup
(party1-7가 존재하지만 8 파티를 동일합니다, 그래서 간결함을 위하여 그것을 포함하지 않았다.)
그것은이다 partysetup을 실행할 때까지 잘 돌아갑니다.
-Hello. I am l1fecount, the DM's combat assistant.
-Before we begin, would you like to see in-depth information about me?
no
-Right then.
-So, let's begin.
How many players today?
8
hi
Error: undefined method `playercount' for main:Object
내가 문자열이나에 playercount 변환, 간단한 맞춤법 오류를 찾고 시도했다 : 나는 메소드가 호출되는 경우 볼 수 있도록 문을두고, 그것은,하지만 난이가 계속 추가 기호가 있지만이 문제는 해결되지 않았습니다. 도와주세요?
'playercount = nil'을 루프 앞에 놓으십시오. 그렇지 않으면 루프 내에서 변수를 정의 할 때 참조는 루프에만 국한됩니다. –
링크 된 페이지를 포함하여 "[mcve]"를 읽으십시오. 문제를 설명하기 위해 코드가 실행되지 않으며 수정해야 할 수도 있습니다. 코드를 최소한으로 제거하여 도움을 필요로합니다. http://ericlippert.com/2014/03/05/how-to-debug-small-programs/ 도움을 받으실 수 있습니다. –
[차이점 - 다양한 변수 - 스코프 - 인 - 루비] 참조 (http://stackoverflow.com/questions/11495098/difference-between-various-variables-scopes-in-ruby) –