Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Can't read data on RMXP startup

I have an interesting problem here.

Some of you might know of this error when you want to open your project and RMXP pops up an error saying "Can't read data", which often means your data is corrupted or something like that.
Well, I have this problem. But in my case, I know exactly what's causing it but I don't know how to fix it.

I am adding new variables and child classes to the RPG::Class class. It now looks something like that:
[ruby] 
module RPG
  class Class
    attr_accessor :battle_commands
    # Aliasing the initialize method seems useless since RMXP overwrites everything when you save
    alias my_new_rpg_class initialize initialize
    def initialize
      my_new_rpg_class initialize
      @battle_commands = [RPG::Class::BattleCommand.new]
    end
    # Created a new method to make sure my new variable is initialized
    def init_var
      @battle_commands = [RPG::Class::BattleCommand.new]
    end
    # New child class
    class BattleCommand
      # my stuff here...
    end
  end
end
 
[/ruby]

I then run a small script in game to save the data with my own new stuff like that:
[ruby] 
for classes in $data_classes.compact
  classes.init_var
end
save_data($data_classes, "Data/Classes.rxdata")
 
[/ruby]

Up to now, everything seems to work fine. But, when I close RMXP (without saving because it would overwrite the changes I made to the Classes data), and I reopen it, I get the error.
"Can't read classes data."

It's obvious that the problem is caused by the modifications I made. But the strange thing is that I tried that with more than half of the other RPG Data (actor, troop, enemy, etc.) and it worked very well. Only RPG::Class gives me trouble like that. I also tried to do that externally, with a little program I made using wxRuby but the results are the same.

Any idea on what's going on?


EDIT:
I tried to put integers and string into my @battle_commands array and it worked. SO it must be related to my new child class. I tried to make a new independent class with it but I still get the error.

Thanks in advance
-Dargor
 
Are you sure this has nothing to do with the Class class name itself? Could it be possible that it's a reserved Constant name found in Ruby (and obviously in RGSS, too)? That might explain why the other scripts for enemies, items, weapons and so on work as expected.

I guess you might have already seen example scripts that calls their class name Klass not Class just to avoid any conflicts with the main Class class found in Ruby, base of all classes in Ruby (just after Object and now BasicObject in Ruby 1.9)... I mean, maybe if you also create a module Module, even inside the RPG module, it could generate the same error messages...
 
kyonides":25xlxmd0 said:
I guess you might have already seen example scripts that calls their class name Klass not Class just to avoid any conflicts with the main Class class found in Ruby, base of all classes in Ruby (just after Object and now BasicObject in Ruby 1.9)... I mean, maybe if you also create a module Module, even inside the RPG module, it could generate the same error messages...

Take a look at the help file. It will have the code for several of the hidden classes, including RPG::Class.
 
Maybe the solution would be to create the class like this...

class RPG::Class
# your code
end

instead of...

module RPG
class Class
# your code
end
end

I think the problem is that the Ruby part of the RGSS really thinks you're including the Class class inside the RPG module and it might not allow it... I know it might look stupid, but even small changes in code can impact its normal behavior...
 
kyonides":vs8w2vpy said:
I think the problem is that the Ruby part of the RGSS really thinks you're including the Class class inside the RPG module and it might not allow it... I know it might look stupid, but even small changes in code can impact its normal behavior...

My point was that there already was a class Class within the module RPG. It's part of the default coding for RMXP, and holds all of the data you add when editing classes in the database. Incidentally, I'm pretty sure that : is a forbidden character in a class name.
 
Using "module RPG; class Class" or "class RPG::Class" would give the same results. This error only happens when I put a new class in my newly created array.

@battle_commands = [1,2,3,'String',nil] works fine but

@battle_commands = [RPG::Class::BattleCommand.new] doesn't work, which is odd, seeing that it works with the Page classes in RPG::Event and RPG::Troop
 
Dargor":2zr85oik said:
Using "module RPG; class Class" or "class RPG::Class" would give the same results. This error only happens when I put a new class in my newly created array.

@battle_commands = [1,2,3,'String',nil] works fine but

@battle_commands = [RPG::Class::BattleCommand.new] doesn't work, which is odd, seeing that it works with the Page classes in RPG::Event and RPG::Troop

I'll have to look this up, but it could be a problem with defining a class within a class. I'm not entirely certain, but I seem to recall having issues with that kind of work in the past, even if it is technically allowed in Ruby.
 
That's exactly what I thougth but it still crash even if it's not a class within a class; Like RPG::ClassBattleCommand instead of RPG::Class::BattleCommand. I haven't tried with an actual existing class like RPG::Event::Page, but I doubt it would change something.
 
It's weird, I tried this using irb on my console window (Konsole not CommandPrompt) and it worked... Of course, the "class inside a class" didn't include anything but the initialize method...

[rgss]module This
  class Is
    def initialize
      puts 'This is a simple class...'
    end
    class SomeThing
      def initialize
        puts 'Yeah, this is something... I guess...'
      end
    end
  end
  class Was
    def initialize
      puts 'This is another simple class...'
    end
    class SomeThingElse
      def initialize
        puts 'Yeah, this is something else... I\'m pretty sure.'
        @var = [This::Is::SomeThing.new]
      end
    end
  end
end
[/rgss]
And this was the output...

Code:
=> nil

>> @this = This::Is::SomeThing.new

Yeah, this is something... I guess...

=> #<This::Is::Something:0x9317eec>

>> @this = This::Was::SomeThingElse.new

Yeah, this is something else... I'm pretty sure.

Yeah, this is something... I guess...

=> #<This::Was::SomeThingElse:0xb75f7a00 @var=[#<This::Is::SomeThing:0xb75f79b0>]

So this should discard any possibility of getting errors due to defining a class inside a class...
 
The problem is that the editor doesn't have the new BattleCommand class declared when loading the rxdata files. The RPG classes are stored in the RGSS102E.dll, but they don't include your new class, and without the new BattleCommand class declared, Ruby don't know how to load it from the serialized data and fails. That's why it throws that error. In other words Marshal.load can't load an object if it's not declared.

You should edit the RGSS102E.dll and add the new class or save the new data on other file.
 
Which means that the data created with my editor won't be compatible with rmxp, unless I rewrite RGSS202E.dll (RGSS2).

Or, instead of pointing directly to this new class, I could make this class independent of the RPG::Class class and create an array containing IDs, instead of my new RPG class... The only problem with is that RMXP will overwrite everything each time you save.
 
The best thing would be to create a new file, like Classes2.rxdata, and write the new data there, so RMXP won't rewrite it. You may also combine the data after loading it, and have it all in the same $data_ variable.
 
Create a file with a set of BattleCommand instances and store on your RPG::Class instances the index of the Battle Command.

If you have this array of battle commands on some other file:
[ "Swordplay",
"Steal",
"Heal",
"Skill",
"Cast",
"Summon" ]

A Class that has Swordplay and Skill would have:
@battlecommands = [0, 3]

This should work even when using RPG::Class::BattleCommand because it's never actually loaded by the editor.


Take care, and good luck!
SEE YA!!!!!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top