Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:37 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.