Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 10-23-2007, 04:27 AM   #1 (permalink)
Forum Expert
 
Alex21's Avatar
 
Join Date: Jul 2007
Location: Australia, Queensland, Sunshine Coast
Age: 16
Posts: 1,259
Send a message via MSN to Alex21
Default Serialize A Array.

I am working on a new more pvp guild like faction system, so far i have begun by trying to create the stone, it compiles but...

On the restart it says this:
Code:
World: Loading...An error was encountered while loading a saved object
 - Type: Server.Items.SunFactionStone
 - Serial: 0x40000215
Delete the object? (y/n)
i guess this mean my serialiaze method is wacked, can some one tell me how to serialize an array?

here is script:
Code:
using System;
using Server;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using System.Collections;
using Server.Network;
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()
            : base(0xEDC)
        {
            Movable = false;
        }

        public override void GetProperties(ObjectPropertyList list)
        {
            base.GetProperties(list);

            if (members != null)
            {
                totalmembers = members.Count;
            }
            else
            {
                totalmembers = 0;
            }

            name = "Faction Stone of Sun";

            //points = GetFactionPoints("Sun");

            list.Add(name);
            list.Add("Members: "+totalmembers);
            list.Add("Points: "+points);
        }

        public override 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 override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0); // version

            if (members != null)
            {
                writer.WriteMobileList(members);
            }

        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();

            if (members != null)
            {
                members = reader.ReadMobileList();
            }

        }

    }
}
serialize problem lines are high lighted red.

thanks for all help.
__________________
Advertise Your Server On JoinUO!
JoinUO @ - joinuo.com
Alex21 is offline   Reply With Quote
Old 10-23-2007, 10:51 AM   #2 (permalink)
Forum Expert
 
TheOutkastDev's Avatar
 
Join Date: Sep 2002
Location: Houston, Texas
Age: 22
Posts: 3,917
Default

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 save/load the array - even if it is empty.
TheOutkastDev is offline   Reply With Quote
Old 10-24-2007, 03:35 AM   #3 (permalink)
Forum Expert
 
Alex21's Avatar
 
Join Date: Jul 2007
Location: Australia, Queensland, Sunshine Coast
Age: 16
Posts: 1,259
Send a message via MSN to Alex21
Default

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

thank you!
__________________
Advertise Your Server On JoinUO!
JoinUO @ - joinuo.com
Alex21 is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5