Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Sign in to follow this  
Foxkit

"End of File reached"

Question

http://pastebin.com/C9PVdaiY

http://pastebin.com/zqB6FCzj

 

Hello, new scripting question. I'm posting this script, to show you what I'm doing that needs a new data file. I understand that it would probably be easier to just add onto $data_weapons after the 1000th object, but I would like to work with this.

 

So first, I write the scripts, giving the basic groundwork for the weapon to bond to characters. I test the game, I get "file not found". Derp moment as I didn't create the file. So I go and create the file with notepad, leaving the file empty. This leads me to "End of File reached" whenever I run the game....

The error explains its self, but I need suggestions on how to get around this.The file really should only get entries whenever a weapon is bonded to a character. I'm "assuming" that the file is missing the necessary support to add in those objects because it's empty. It's like trying to cram books into a non existing bookcase. Or it could be because there is just nothing there.

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

what exactly are you trying to do? im a lil confused. as for EoF, that means that it reaches the end of the file without pulling the info needed.

Share this post


Link to post
Share on other sites
  • 0

It's my own approach to equipment bonding. IE, when a character equips an item, only that character will be able to equip that item from that moment on. I do this by copying the item, and adding it to a new data file. I'm looking for a way to make that error go away, I need to know what to put into the file to make it not spit out that error.

Edited by Foxkit

Share this post


Link to post
Share on other sites
  • 0

there is a very important thing that you have to do when getting information from files, take this for example:

filename = "data_files/weapon_data.rxdata"
if FileTest.exist?(filename)
    File.open(filename, "rb") {|file|
    line1 = Marshal.load(file)
    line2 = Marshal.load(file)
    line3 = Marshal.load(file)
    #ect
}
else
    print "#{filename} not found:
    exit
end

so basically what that is doing checking if the file exists, if it does it opens it with ";file: as its key, the you notice how I named the variables to "line1" ect. that is because every time you set a variable to the value of the file it progresses itself, if you try to set a variable to the value of the file once it has gone through all the lines, you will get your said error, so the best way to make sure you don't get any errors is to make sure your file has all the data your trying to access, also note with my example you don't have to add the code to close the file, it does that itself, an example of having to manually close the file:

file = File.open(filename, "rb")
line1 = file
line2 = file
file.close

now ill show you an example of writing to a file, on a side note I would advise creating a GUI program for making your data files, it will just make it so much easier, a good one in ruby, if that is the only language you are familiar with, is WXruby or "iron ruby" I think is also one, but bear in mind you will also need to install the ruby interpreter to your system to use these.
note you can save any sort of data to a line in a file, whether it be a class, array, hash, string or integer, you can set any line to these types, but note when reading them you have to know which one is which obviously, so in this example ill show all these in use:

#if the file does not exist then it will be created
#note for writing files I use 'wb' instead of 'rb'
class = Weapon.new
hash = {
    1 => 1
    2 => class
    3 => [1, 2, 3]
}
array = [class, hash, 1, "string"]
string = "string"
integer = 1
File.open(filename, "wb") {|file|
    #line 1
    Marshal.dump(class)
    #line 2
    Marshal.dump(hash)
    #line 3
    Marshal.dump(array)
    #line 4
    Marshal.dump(string)
    #line 5
    Marshal.dump(integer)
}

so that is basically how you would create your files, note that it is five lines long, and I know what line is what so I could load that file like this:

File.open(filename, "rb") {|file|
    class = Marshal.load(file)
    hash = Marshal.load(file)
    array = Marshal.load(file)
    string = Marshal.load(file)
    integer = Marshal.load(file)

    #error would occur if you continued loading from it
    error = Marshal.load(file)
}

and there we have it, I loaded the file exactly how I created it, also note for text files you could load them like this, as there size is constantly adjustable:

IO.readlines(filename)

what that sexy piece of code does if you don't know, is it will load the whole file and store it into an array, so say our text file is 10 lines long, we end up with an array with 10 strings stored inside it, I haven't actually ever tried using this with other files, it might give the same result but I am not sure.

hope these examples are of some use to you, if you need anymore help just ask! :D

edit:
also note that the rpgmaker stores each item in an array, where is item is a class, that is why we can use the following to get an items name:

name = $data_items[ID].name

so an example of how you could do this sort of thing:

class Weapon
    attr_accessor :name

    def initialize(name)
        @name = name
    end
end

#then inside whatever method saves the data
    weapons = []

    #just a quick way of me creating dummy data
    for i in 0..5
        weapons.push(Weapon.new("name #{i}"))
    end

    File.open(filename, "wb") {|file|
        Marshal.dump(weapons)
    }

    #then we would load and read information like this:

    File.open(filename, "rb") {|file|
        weapons = file
    end

    for i in 0..5
        print weapons[i].name
    end
Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

My issue is more like trying to load something that doesn't exist. I have no idea how the data is stored in Data_Weapons because it's all in gibberish :/
 

At the beginning of the game, there should be no weapons stored in Data_b_weapons.rxdata does that mean that I should be storing the weapons when the game saves? And only loading them if the file exists?

 

I'll get the interpreter and open up the files if I have too :/ I just didn't want to.

 

Also would just like to point out that in rpgmaker xp,

 

$data_actors = load_data("Data/Actors.rxdata")

Is functionally the same as:

File.open(filename, "rb" { |f|
  obj = Marshal.load(f)
}

and ditto for the save data.


Here, better question. Can I just save the array of $data_b_weapons straight to a file such as Data/bweapons.rxdata, and then be able to load them on startup?

Edited by Foxkit

Share this post


Link to post
Share on other sites
  • 0

oh wow my last edit screwed up my post, I posted at the end there how rpgmaker stores the weapon data, what you should do is create a dummy file with an empty array, so for example just run this code to make your dummy file:

weapons = [] File.open("Data/Data_b_weapons.rxdata", "wb") {|file|
Marshal.dump(weapons)
}

 

 

and when you come around to storing information to it just create each weapon as a class, just like rpgmaker does, note getting the ruby interpreter wont remove to gobbledygook you see when you print the weapons array, thats because they are classes, here is an example of the class that each weapon is based of in rpg maker xp:

module RPG
  class Weapon
    def initialize
      @id = 0
      @name = ""
      @icon_name = ""
      @description = ""
      @animation1_id = 0
      @animation2_id = 0
      @price = 0
      @atk = 0
      @pdef = 0
      @mdef = 0
      @str_plus = 0
      @dex_plus = 0
      @agi_plus = 0
      @int_plus = 0
      @element_set = []
      @plus_state_set = []
      @minus_state_set = []
    end
    attr_accessor :id
    attr_accessor :name
    attr_accessor :icon_name
    attr_accessor :description
    attr_accessor :animation1_id
    attr_accessor :animation2_id
    attr_accessor :price
    attr_accessor :atk
    attr_accessor :pdef
    attr_accessor :mdef
    attr_accessor :str_plus
    attr_accessor :dex_plus
    attr_accessor :agi_plus
    attr_accessor :int_plus
    attr_accessor :element_set
    attr_accessor :plus_state_set
    attr_accessor :minus_state_set
  end
end

 

all the data structures can be found in the help manual, so when you create a weapon you could do this:

weapon = RPG.Weapon.new
weapon.id = #some id, probably the size of your array + 1, or the weapon id it will replace
weapon.name = "new name"
#ect
#then add it to your array of weapons
$my_data_weapons[weapon.id] = weapon

#then we save the weapons to the file
File.open(filename, "wb") {|file|
    Marshal.dump($my_data_weapons)
}

 

one question, what is this intended to do in the long run? 

is this some sort of weapon creation system?

just note it is not practice to save the data after every small edit, rpgmakers database only saves the data once apply or ok is pressed, so say you did this inside a custom window or something, you would have an apply and a cancel button, once the apply button is pressed, save the updated weapons to the file, if cancel is pressed reload the data as you have edited information on the currently loaded data but dont want to apply it

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

In the long run it's to be intended as a weapon customization system :3

 

As for the info about Data_weapons being a class, That is exactly what I was looking for :3 ty ty

 

if you look in the first link you can see exactly what I've edited, I just copy the base weapon, and give it an atribute based on the actor's id, then change it's name and put it in the new array of weapons. It should be saved when the player saves, so that way all the information is just simply stored once. So question, is the short answer "I need to create an empty array to store everything in?"

Share this post


Link to post
Share on other sites
  • 0

well thats a bit hard to say really, as i can see a problem arising from this, the problem that i see is that if a player creates multiple saves, all the data is stored in one place, although there is an easy way around this, you just need to look into how the data is loaded normally, in scene_title on the choice of new game, make it create a global variable, like $my_data_weapons, and just make that an empty array: $my_data_weapons = [], then every time you make a new weapon just add the classes to the array, now as for saving the data, i would attach the data to the end of the save file, then in scene_title, where it loads the data, make it also load your data, so there will be three things you must do:

 

edit the new game command to initialize your data

edit the save command to save your data

edit the load command to load your data

 

if you do it this way it will be apart of each save rather than a global file all the saves use

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0
well thats a bit hard to say really, as i can see a problem arising from this, the problem that i see is that if a player creates multiple saves, all the data is stored in one place, although there is an easy way around this, you just need to look into how the data is loaded normally, in scene_title on the choice of new game, make it create a global variable, like $my_data_weapons, and just make that an empty array: $my_data_weapons = [], then every time you make a new weapon just add the classes to the array, now as for saving the data, i would attach the data to the end of the save file, then in scene_title, where it loads the data, make it also load your data, so there will be three things you must do:

 

edit the new game command to initialize your data

edit the save command to save your data

edit the load command to load your data

 

if you do it this way it will be apart of each save rather than a global file all the saves use

 

Edit: I hadn't thought of that D: ... I was only hoping for one save file.

Though having multiple saves IS an issue, and I can see exactly why .. :/

 

So your proposing something similar to this... When the new game loads marshal data, just have it load the empty array.

Any new unique weapons will be stored in that empty array.

when the game is saved, append the weapons data onto the save.

when the game is loaded, store the weapon data into the now empty array.

 

Edited by Foxkit

Share this post


Link to post
Share on other sites
  • 0

yes thats exactly what im saying, i mean, on the option of a new game you dont even need it to load you only have to set it equal to an empty array, the major part is adding the data to each save so its saved and loaded accordingly, to do that you will just need to tweek Scene_Save and Scene_Load

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

I may be able to help you extend the database of weapons without need of an outside file... Next time I see you online, we can talk. ^_~

Share this post


Link to post
Share on other sites
  • 0
I may be able to help you extend the database of weapons without need of an outside file... Next time I see you online, we can talk. ^_~

 

Kellessdee already gave me a way to do that, I just wanted to do it this way for kicks ^^. I wasn't expecting it to take me on this big wrabbit hunt through I/O land :3

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...