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 create the kill it compiles but... On the start it says this:
World: Loading... An error was encountered while loading a saved object - Type: Server. Items. SunFactionStone - Serial: 0x40000215Delete the object? (y/n)
i guess this convey 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 categorise SunFactionStone : Item { private ArrayList members; private int totalmembers; private int points; private string name; [Constructable] public SunFactionStone() : base(0xEDC) { Movable = false; } public override void GetProperties(ObjectPropertyList enumerate) { locate. GetProperties(enumerate); if (members != null) { totalmembers = members. Count; } else { totalmembers = 0; } label = "Faction kill of Sun"; //points = GetFactionPoints("Sun"); enumerate. Add(name); list. Add("Members: "+totalmembers); list. 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) : locate(serial) { } public override cancel Serialize(GenericWriter writer) { base. Serialize(writer); writer. Write((int)0); // version
if (members != null) { writer. WriteMobileList(members); }
} public decree void Deserialize(GenericReader reader) { locate. Deserialize(reader); int version = reader. ReadInt();
if (members != null) { members = reader. ReadMobileList(); }
Initialize 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 deliver/load the arrange - even if it is empty.
jesus convey 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!
|