我正在調試程序,並且它在加載的文件中未執行新的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
你可以發佈一些代碼,以及如何運行該程序的例子嗎? – mgrant