|
||
|
|||||||
| Script Support Get support for modifying RunUO Scripts, or writing your own! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#26 (permalink) | |
|
Account Terminated
|
Quote:
Its not easy, so if you don't know C# you might not be able to do it. |
|
|
|
|
|
|
#27 (permalink) |
|
Guest
Posts: n/a
|
Ok...I finally choose to read through this because im always having troubles having to restart my playerbase whe i add a new seralize desearlize. So..i must not be doing it correctly. How exactly are you suppose to do it for the playermobile.cs what i read here looks like for items...
|
|
|
|
#28 (permalink) | |
|
Forum Expert
|
I have a Item that once equiped by a Mobile, starts a timer to do a check of the lightlevels.
so, how do i serialize this? do i have to serialize the mobile, the item, and the timer? or just one or two of them? and other than string and number fields how would you serialize and deserialize your data? ie... if i have to serialize the timer how do i do it? would i just simply add the timer start to serialize and deserialize, like so [code:1] m_DrowLightCheckTimer = new DrowLightCheckTimer( m, this ); m_DrowLightCheckTimer.Start(); [/code:1] or is there something more complicated to it? I tried to serialize my item but it threw a compile error that i "used a class where a variable was expected". [code:1] writer.Write(DrowShadowTunic); [/code:1] so i instead tried a reference to that item: [code:1] writer.Write(m_DrowShadowTunic); [/code:1] it compiled fine but crashed and threw an exception Due to Bad Serialize. Maybe the bad serialize is due to the fact that the variable m_DrowShadowTunic is not in the Deserialize method, my question there would be how would you deserialize a reference to an item? or can you serialize and deserialize a reference to an item. I tried using: [code:1] m_DrowShadowTunic = reader.ReadItem(); [/code:1] but it shot me the error Quote:
I appreciate any help that anyone may give. roadmaster ![]() |
|
|
|
|
|
|
#29 (permalink) |
|
maybe it would help i you understood what serialize does in low level...
as far as i understand serializing converts something into a series of 0s and 1s, so for example if you serialize the int 3 you would get something like 00000000000000000000000000000011 in memory/hard disk (wich is 3 in binary in 32 bit form). when u serialize a 3 and a 1 u get: 00000000000000000000000000000011 (3) 00000000000000000000000000000001 (1) etc. Now, we give the writer the int parameter so he knows in how many bytes it should write the info (integers have 32 bits i believe, thats why theres so many 0s), if instead of writer.write((int) 3). we put writer.write((byte) 3) (bytes have 8 bits instead of 32) you would get something like: 00000011 (3 in binary format in 8 bits) thats for the writer. the problem for the reader is that it doesnt really knows if with: 00000000000000000000000000000011 you meant 1 32 bit integer value of 3, or 4 8 bit "byte" values (0,0,0,3). Thats why we specify the type when we read. trying to write or read directly a deathshroud for example is a problem because the writer doent knows how to convert it to binary, and the reader doenst knows how to read it. you need to serialize each property 1 at a time making sure u read the same type of info in the same order, after all for the server your worldfile looks like: 10010100100010101101001001011101001001001000100001 001100100100 :D theres another way that involves letting c# convert the WHOLE object to memory in binary format and retrieve it and put it in memory "as it is" when deserialized... thats how its done mostly on normal programming, but for some reason its not used a lot for scripts. Hope it helps! if any of that is wrong i apologize, thats how i understand it. |
|
|
|
|
|
|
#30 (permalink) | |
|
Newbie
Join Date: Nov 2007
Posts: 52
|
Quote:
Some more things that should perhaps be noted: object refences are done by serial, serialization methods called for ancestors, type-handling in saves, and saving for custom [static/non-static] non-mobile non-item non-guild objects. |
|
|
|
|
|
|
#31 (permalink) |
|
Newbie
|
Since I haven't found it explained thoroughly in here and it might be really useful for new scripters...
If you just add some variables in the serialize and deserialize methods, the server still might not see the variables' values on existing mobiles / items / whatever and might want to delete them. There's a simple solution to that. If you have added new variables in the Serialize and Deserialize methods eg. Code:
(...)
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch ( version )
{
#region MyRegion
case 26:
{
var1 = reader.ReadLong();
var2 = reader.ReadInt();
var3 = reader.ReadString();
gotocase 25;
}
#endregion
(...)
public override void Serialize( GenericWriter writer )
{
(...)
writer.Write( (int) 26 ); // VERSION!
#region MyRegion
writer.Write( (long)var1 );
writer.Write( (int)var2 );
writer.Write( (string)var3 );
#endregion
(...)
An easy way to do that supposing you increased the version number when adding the new properties would be to those lines: Code:
#region MyRegion
if (version < 26)
{
var1 = [value 1];
var2 = [value 2];
var3 = "[value3]";
}
#endregion
Code:
case 0:
{
break;
}
}
[Post inspired by Ki Frost] Last edited by i_am_neo; 04-16-2008 at 05:23 PM. |
|
|
|
|
|
#32 (permalink) |
|
Newbie
Join Date: Mar 2008
Age: 23
Posts: 36
|
I've seen this issue time and time again. The solution that most people respond with is, "You have to wipe your server or old items". Well here is a very simple method to update items, that never included a "version" variable.
This will work anytime you need to update a script that does not already have a "Version Variable". In this example, we will also demonstrate adding a "Version Variable" for easier future updates. So, lets take a look at the code. Serialize = "Writes the data" Deserialize = "Reads the data" Code:
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
}
So How do we fix this? Simple, we update the data it's trying to "load" before it loads the new format. How is this done? - Create the Serialize method that you want to "upgrade to". Code:
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int)1 ); // Version
writer.Write( ContainerName );
}
- Launch/Restart your server. - It should load fine, once it's up - Shutdown w/save - Make the changes to the Deserialize method, to support your new data structure. Code:
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch (version)
{
case 1: { ContainerName = reader.ReadString(); } goto case 0;
case 0: { } break;
}
}
- Done You now have a working upgrade to your script.Last edited by Moroth; 07-27-2008 at 01:40 PM. |
|
|
|
|
|
#33 (permalink) |
|
Forum Expert
|
TIP: Where-ever possible, you should use the 'switch' statement to control your versions.
Code:
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch (version)
{
case 1: { ContainerName = reader.ReadString(); } goto case 0;
case 0: { } break;
}
}
__________________
![]() RPK.VORSPIRE.COM - The WoW-UO Cross-Over Shard |
|
|
|
|
|
#34 (permalink) |
|
Lurker
|
Hahaha... I go tru this thread and feel like in a movie. I knew what gonna appen... Hahaha... I had the response for this and keep chalenging me to not write the response before i'd read all the thread... Hahaha I like it.
Moroth you got it ... hahaha . That is simple. I've been using this tecnic for a while. And after try some other way... This is the right one ... the only problem whit this is you have to restart the server two time instead of once but... is that realy matter? No |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|