2015-08-20 118 views
0

我正在調試程序,並且它在加載的文件中未執行新的puts。主文件正在運行,並執行該文件的更改。所以我懷疑加載的任何更改。對已加載文件的更改未執行

我會做什麼錯?

第一個文件正常工作。它的第二個文件... newmods.rb文件提示在運行時不會改變,並且任何新的「puts」語句都不會執行。 我正在使用load而不是require_relative。該文件不會與require_relative一起編譯。

文件1

#!/usr/bin/env ruby 
load "/Users/abcde/Ruby/learning/shorterZork/monsters.rb" 
load "/Users/abcde/Ruby/learning/shorterZork/room.rb" 
load "/Users/abcde/Ruby/learning/shorterZork/avatar.rb" 
load "/Users/abcde/Ruby/learning/shorterZork/newmods.rb" 
load "/Users/abcde/Ruby/learning/shorterZork/items.rb" 

def main() 

    game_loop(avatar) 

end 

def game_loop(avatar) 

puts "You are in the: #{@room_name}" 
puts "#{avatar.name} has #{avatar.life}!"  
health_bar(avatar) 
# Check for avatar's life. 
#avatar_life(avatar) 
#puts @room_monsters.to_s 
monster = @room_monsters 
test_encounter(avatar, monster) 
# need to put the meat of the game here. 
# puts "I need something here." 
#puts "--------------------------------------------This is the main loop." 

prompt; action = gets.chomp 

    if action.downcase == "help" 
    help() 

..etc...etc. 

end 

main() 

文件2 newmods.rb

# This includes any modules that might be nice to use. 

load "/Users/abcde/Ruby/learning/shorterZork/monsters.rb" 
load "/Users/abcde/Ruby/learning/shorterZork/room.rb" 
load "/Users/abcde/Ruby/learning/shorterZork/avatar.rb" 
load "/Users/abcde/Ruby/learning/shorterZork/items.rb" 

#require 'items' 
#require 'monsters' 
#require 'avatar' 
#require 'room' 
#require 'shortZork' 

def prompt() 
    print ">> " 
end 
+0

你可以發佈一些代碼,以及如何運行該程序的例子嗎? – mgrant

回答

0

從我的經驗,在這種情況下,常犯的錯誤是

  • 在編輯器中顯示的編輯/ IDE是沒有保存到文件。
  • 文件有不同版本,並且編輯是在未使用的版本上進行的。
0

喜悅。正當你伸手尋求幫助時,答案就會讓你面對面。

紅寶石加載正在從不同於當前期望路徑的路徑加載文件。用戶名是不同的,所以...

相關問題