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: Gnome (offline) on Saturday, October 30 2004 @ 02:27 PM CDT (Read 18257 times)  
Gnome

I have been playing with JMegaHal and have created an IRC bot with pircbot and got it all working OK. My question is how do I get JMegaHal to save its brain (i.e. learnt text etc.) Question

Regards

Gnome


Forum Newbie
Newbie

Status: offline

Registered: 10/30/04
Posts: 1

Profile Email    
   
By: Anonymous: spheric () on Sunday, October 31 2004 @ 04:36 AM CST  
Anonymous: spheric

Although I dont have experience with JMegahal the basic idea is to make whatever object you want to save serializable. You do this by adding

implements java.io.serializable

to the end (before the { ) of your opening class statement. For example:

class myclass implements java.io.serializable {

Then, you need to add the code to actually save it

You need to create 2 objects. The first is a FileOutputStream (in java.io again)

java.io.FileOutputStream ostream = new java.io.FileOutputStream("words.dat");

and next an ObjectOutputStream

java.io.ObjectOutputStream p = new java.io.ObjectOutputStream(ostream);

Then you need to write your object: - which MUST be serializable, otherwise an exception will be thrown

p.writeObject(myobject);

and finally close the file

p.close();

Because I havent really used JMegaHal, I dont know whether paul has included its own save method, or even whether the data structure is even serializable. If it isnt you'll need to edit the source to make it so.

Hope this helps

Kris





       
   
By: spheric (offline) on Sunday, October 31 2004 @ 04:37 AM CST  
spheric

apologies, that post was by me, not anonymous Smile


Forum Junior
Junior

Status: offline

Registered: 10/26/04
Posts: 22

Profile Email    
   
By: Anonymous: Gene () on Thursday, November 04 2004 @ 04:14 AM CST  
Anonymous: Gene

Í would like to know more about this too.

Sorry I'm total beginner on area and would like to see more explanation.. I have made with help of my friend pircbot with jmegahal feature on it. But I would like to save those learned phrases somewhere.

regards,

gene





       
   
By: DeadEd (offline) on Friday, November 05 2004 @ 03:16 AM CST  
DeadEd

Simple example on how to save to "brain.ser" ...

PHP Formatted Code

   ObjectOutput out = new ObjectOutputStream(new FileOutputStream("brain.ser"));
   out.writeObject(hal);
   out.close();


... and to create from "brain.ser" (previously serialized JMegaHal object) ...

PHP Formatted Code

   File file = new File("brain.ser");
   ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
   JMegaHal hal = (JMegaHal) in.readObject();
   in.close();



Forum Moderator
Moderator

Status: offline

Registered: 06/01/04
Posts: 602

Profile Email Website  
   
By: Anonymous: gene () on Sunday, November 07 2004 @ 07:37 AM CST  
Anonymous: gene

Thanks. It did work great.





       
   
By: Anonymous: tipx () on Wednesday, November 10 2004 @ 12:12 PM CST  
Anonymous: tipx

where did you include this, and how?





       
   
By: Anonymous: Zacksta () on Sunday, November 14 2004 @ 10:52 AM CST  
Anonymous: Zacksta

Um where do you put the code for the memory..... does it have to go in a certin place or something?






       
   
By: spheric (offline) on Tuesday, November 16 2004 @ 10:10 AM CST  
spheric

you can put it wherever you want it, although reason dictates that you'll want the loading to be done when the bot starts, and the saving done either when the bot quits, or with a special command, or on a timer


Forum Junior
Junior

Status: offline

Registered: 10/26/04
Posts: 22

Profile Email    
   
By: Anonymous: waitsa () on Tuesday, November 16 2004 @ 10:44 AM CST  
Anonymous: waitsa

example of the java?





       
   



 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