Jump to content
Asharonapaul

cant find file error

Recommended Posts

class Scene_Book < Scene_Base
  def start
    super
    @book_title = Window_Base.new(0,0,Graphics.width, Graphics.height)
    @page = []
    @page = retrieve("Book1.txt")
    @ind = 0;
    refresh
  end
  
  def refresh
    @book_title.contents.clear
    #@book_title.contents.font.name = "Courier New"
   # @book_title.contents.font.size = 24
  #  @book_title.contents.font.color = Color.new(255,255,255)
    case @ind
    when 0
      @book_title.draw_text(0,0,Graphics.width,48,@page[@ind],1)
    else
      @book_title.draw_text_ex(0,0,@page[@ind])
    end
    
  end
  
  def update
    super
    if Input.trigger?(:LEFT)
      if @ind > 0
        @ind -= 1;
      refresh
      end
    elsif Input.trigger?(:RIGHT)
      if @ind < @page.size
        @ind += 1;
        refresh
        end
    end
  end
  
  def retrieve(name)
    page = Array.new
    somefile = File.open("Data/Book1.rb", "r+")
      somefile.each do |line|
        eval(line)
      end
    return page
    puts "Done"
    somefile.close
  end
end

so this works, but it can't find Book1.rb. I've tried naming it Book1.txt and its the same issue. it is in Data folder of the project in documents.

book1 contains this :

@page[0] = 
"Sun Champion- Kalvgv: The Woes of Birth \n Leon Sandcastle"
    @page[1] = 
"Dedicated to my great uncle, brother to 
my grandfather, and teacher to his nephews. 
One of the three Legendary Ginseng hunters of
his generations."

any help is appreciated

 

 

Solution Below:

 

 

ok. the file was named improperly, windows automatically attaches .txt even if you change it to .rb

and the file operation needed changed to require to just use the file as a library.

 

def retrieve(name)
    require 'Data/Book1.rb'
    return $page
    puts "Done"
    end

also the contents of the included file needed altered. @ local variables would not allow what I needed/wanted

 

$page = Array.new
$page[0] = "Sun Champion- Kalvgv: The Woes of Birth \\n Leon Sandcastle"
$page[1] = "Dedicated to my great uncle, brother to 
my grandfather, and teacher to his nephews. 
One of the three Legendary Ginseng hunters of
his generations."

with some finangling this could be used for making patches to a game. or in my case, allowing the user to download formatted books for their reading leisure.

Edited by Asharonapaul

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×