DeadEd.com
IRC Bots, Java Game Query and Control Libraries, and More ...
Sign Up!
Login
Welcome to DeadEd.com
Monday, September 25 2017 @ 01:19 AM CDT

 Forum Index > Jibble.org > Other Jibble
 JMegaHal and saving Brain
 |  Printable Version
By: DeadEd (offline) on Friday, November 19 2004 @ 03:07 AM CST  
DeadEd

Forum Moderator
Moderator

Status: offline

Registered: 06/01/04
Posts: 602

Profile Email Website  
   
By: Anonymous: kipton () on Wednesday, December 08 2004 @ 01:15 PM CST  
Anonymous: kipton

I've read this topic and tried to apply the pieces of code mentioned here. I've also read the documentation about serialization. However, there seems to be something wrong, and I don't understand what. I can get the bot to save the code in the file brain.ser, but loading it doesn't seem to have any effect. Here's the code I'm using:

public void onMessage(String channel, String sender,
String login, String hostname, String message) {

if (message.equalsIgnoreCase("!save&quotWink && sender.equalsIgnoreCase("kipton&quotWink) {
try {
ObjectOutput out = new ObjectOutputStream(new FileOutputStream("brain.ser&quotWink);
out.writeObject(hal);
out.close();
} catch (Exception e) {
System.out.println(e);
System.exit(1);
}
String sentence = "brain saved!";
sendMessage(channel, sentence);
}

if (message.equalsIgnoreCase("!load&quotWink && sender.equalsIgnoreCase("kipton&quotWink) {
try {
File file = new File("brain.ser&quotWink;
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
JMegaHal hal = (JMegaHal) in.readObject();
in.close();
} catch (Exception e) {
System.out.println(e);
System.exit(1);
}
String sentence = "brain loaded!";
sendMessage(channel, sentence);
}
}

Any help would be greatly appreciated.





       
   
By: Anonymous: kipton () on Wednesday, December 08 2004 @ 02:06 PM CST  
Anonymous: kipton

Alas, the downside of being anonymous, not being able to edit my own post. Anyway, I really should have waited with posting that message - removing the first "JMegaHal" from the line: JMegaHal hal = (JMegaHal) in.readObject(); seemed to do the trick.





       
   
By: spheric (offline) on Tuesday, February 08 2005 @ 05:17 AM CST  
spheric

yeah.. before you were creating a new local variable, where what you wanted to do was assign the loaded object to an existing global one


Forum Junior
Junior

Status: offline

Registered: 10/26/04
Posts: 22

Profile Email    
   
By: Anonymous: aquarat () on Friday, June 10 2005 @ 04:31 PM CDT  
Anonymous: aquarat

I built jMegaHal into the PircBot API and landed up with the same problem. I solved it (at least I think I solved it) by writing everything that was added to jMegaHal's brain to a file on the drive.

When the program was restarted, it simply added everything from the text file back into the brain.

I quickly built a simple programme to read previous IRC logs into a format that could easily be read from the file that the jMegaHal add-on reads when PircBot starts... only problem was that Java ran out of memory. I haven't got past that problem yet.

The memory issue is a bit strange because the machine has 1GB of RAM and the JRE doesn't seem to have a memory size argument. My logs aren't capable of using 1GB, or even 20MB of RAM.

Oh well.






       
   
By: DeadEd (offline) on Thursday, June 16 2005 @ 06:02 AM CDT  
DeadEd

Doesn't a JVM have a default size of memory usage unless you specify otherwise?

Also, (j)megahal is a memory pig.


Forum Moderator
Moderator

Status: offline

Registered: 06/01/04
Posts: 602

Profile Email Website  
   
By: siddmax (offline) on Wednesday, March 10 2010 @ 08:47 AM CST  
siddmax

I also want to save my JMegaHal brain, but I'm confused where to put the code in as well.


Forum Newbie
Newbie

Status: offline

Registered: 03/10/10
Posts: 2

Profile Email    
   
By: DeadEd (offline) on Wednesday, March 10 2010 @ 12:06 PM CST  
DeadEd

Take a look at the ChatBackBot from the PircBot Demos


Forum Moderator
Moderator

Status: offline

Registered: 06/01/04
Posts: 602

Profile Email Website  
   



 All times are CDT. The time is now 01:19 AM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

My Account





Sign up as a New User
Lost your password?

What's New

Stories

No new stories

Comments last 2 days

No new comments

Files last 14 days

No new files
No new comments

Links last 2 weeks

No new links