zerodowned

Moderator
Let's say I make a new class

Code:
namespace Server
{
        public class NewClass       
                 {

That has serialize and deserialize within itself working just fine.

But then I try to add it to PlayerMobile and serialize / deserialize it there.
Since the new class isn't inheriting another class, how would I do this?

NewClass = reader.Read();
NewClass = reader.ReadNewClass();
NewClass = reader.ReadNewClass() as NewClass;

The compile error I keep getting is
'Server.GenericReader' does not contain a definition for
'Read' and no extension method 'Read' accepting a first argument of type 'Server
.GenericReader' could be found (are you missing a using directive or an assembly
reference?)
 
I realize I could just set it to inherit Item and that solves my problem but doesn't seem like the right way to do it
 
The issue is that Serialize and Deserialize are not default c# classes but are classes that are included in ServUO and expect certain patterns when writing the save binary.

For the longest time developers had to create an item or mobile in game that contained the data they wished to save which was not the nicest way of doing this (As you have have found yourself). ServUO gets around this with the persistence system which allows you to save generic data without having to adhere to the expected patterns of the serialization system.

Here is an example of the persistence system. https://github.com/ServUO/ServUO/blob/master/Scripts/Services/Help/HelpPersistence.cs

Or, you could serialize each property of your object in playermobile serialize method and then create a new object at deserialize with that saved data, either would work.
 
What is your other class for?
Is it absolutely linked to playermobile?
Would you like it to be saving it independantly?
 
What is your other class for?
Is it absolutely linked to playermobile?
Would you like it to be saving it independantly?

The newclass is so I can combine a timer, strings, and int into one thing that I can then add to a List
It's tied to playermobile because I need to serialize and desearilize the list that is part of Playermobile
I have everything working except trying to deserialize the list and add the newclass back to it

I don't have the code accessible at the moment but it was this part of deserializing and adding things back to the list that gave me a problem.
reader.Read...what?

NewClass = reader.Read();
NewClass = reader.ReadNewClass();
NewClass = reader.ReadNewClass() as NewClass;
 
You could fake the serializing process, and even making custom versions in those other classes if you do something like:

Code:
Serialize(SerializerClassIDK serializer)
{
	serializer.WriteInt(int);
	serializer.WriteBool(int);
}

then in your playermobile,
thatclass.Serialize(serializer);

Basically, you derivate the serialize and deserialize to the other class itself, and send the serializer through (so it writes and reads using the same instance).
 
You could fake the serializing process, and even making custom versions in those other classes if you do something like:

Code:
Serialize(SerializerClassIDK serializer)
{
	serializer.WriteInt(int);
	serializer.WriteBool(int);
}

then in your playermobile,
thatclass.Serialize(serializer);

Basically, you derivate the serialize and deserialize to the other class itself, and send the serializer through (so it writes and reads using the same instance).
that looks perfect, thank you
 
The issue is that Serialize and Deserialize are not default c# classes but are classes that are included in ServUO and expect certain patterns when writing the save binary.

For the longest time developers had to create an item or mobile in game that contained the data they wished to save which was not the nicest way of doing this (As you have have found yourself). ServUO gets around this with the persistence system which allows you to save generic data without having to adhere to the expected patterns of the serialization system.

Here is an example of the persistence system. https://github.com/ServUO/ServUO/blob/master/Scripts/Services/Help/HelpPersistence.cs

Or, you could serialize each property of your object in playermobile serialize method and then create a new object at deserialize with that saved data, either would work.
I think you've mentioned this to me before but I forgot about it
An awesome way to do things, gives me a few ideas :)

Thank you again
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back