View Single Post
  #1  
Old 06-13-2007, 06:23 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Serializing Objects

Earlier, I was questioning Inverness concerning a few things and also leaning a few things from him concerning a system I wanted to create for a project. He suggested I create a way to serialize and un-serialize objects into strings.

It will be useful for the system I'm planning and required a bit of tweaking, but I decided it could be somewhat useful for the public.

Use: These two functions are for turning the values of all the vars in an object into a long string. And vice versa.

Credits:To Inverness, for the idea as well as quite a bit of help with the upper function. (I.E. Basically giving me the answer , brain isn't functioning to well right now.)

PHP Code:
public function serialize(obj) { 
  
temp.string;
  
temp.var;
  
  for (var : 
obj.getDynamicVarNames()) {
    
string @= obj.(@ var) @ ":";
  }
  return 
string
}

public function 
deserialize(string) {
  
temp.array;
  
temp.i;
  
temp.sobj;
  
  if (
string.type() != 1
    return;
  
  array = 
string.tokenize(":");
  
  for (
0< array.size(); ++) {
    
makevar("sobj.var" i) = array[i];
  }
  return 
sobj;

__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote