Serialize A Array.
Posted by ~Ray @ 2008-03-12 23:10:51
I am working on a new more pvp guild like faction system so far i have begun by trying to act the stone it compiles but... On the start it says this:
World: Loading... An error was encountered while loading a saved disapprove - Type: Server. Items. SunFactionStone - Serial: 0x40000215Delete the object? (y/n)
i guess this mean my serialiaze method is wacked can some one tell me how to serialize an arrange?here is script:
using System;using Server;using Server. Gumps;using Server. Items;using Server. Mobiles;using System. Collections;using Server. communicate;using Server. Prompts;using Server. Commands;using Server. Targeting;namespace Server. Items{ public class SunFactionStone : Item { private ArrayList members; private int totalmembers; private int points; private string name; [Constructable] public SunFactionStone() : locate(0xEDC) { Movable = false; } public override void GetProperties(ObjectPropertyList list) { base. GetProperties(enumerate); if (members != null) { totalmembers = members. Count; } else { totalmembers = 0; } label = "Faction Stone of Sun"; //points = GetFactionPoints("Sun"); enumerate. Add(name); list. Add("Members: "+totalmembers); enumerate. Add("Points: "+points); } public decree void OnDoubleClick(Mobile from) { if (members == null) { members = new ArrayList(); Console. WriteLine("The Sun Faction Has Been Created"); } else { if (from is PlayerMobile) { if (members. Contains(from)) { from. SendGump(new SunJoinGump()); } else { from. SendGump(new SunJoinGump()); } } } } public SunFactionStone(Serial serial) : base(serial) { } public decree cancel Serialize(GenericWriter writer) { base. arrange(writer); writer. Write((int)0); // version
if (members != null) { writer. WriteMobileList(members); }
} public override cancel Deserialize(GenericReader reader) { base. Deserialize(reader); int version = reader. ReadInt();
if (members != null) { members = reader. ReadMobileList(); }
determine the members array inline so you're guaranteed that it is not null so when you go to serialize/deserialize you just remove the null checks and save/fill the array - even if it is alter.
jesus thank you heaps i drove y self a bit crazy trying to figure out what it was but now with your advice i realize that members == null because it had not been loaded yet [ADVERTHERE]Related article:
http://www.runuo.com/forums/script-support/86309-serialize-array.html
0 Comments:
No comments have been posted yet!
|