Sign in to follow this  

Built-in script arrays

This topic is 4475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Beside I the sensation that I run into on some mistake in engine. Though possible, I exactly not understand. Here's script code causing error struct troops { bool enemy; bool dead; }; troops[] fighters(5); All works fine. Except one moment, when i'm trying to save and load binary code. (Version 2.3.0a) I'm found this in as_scriptengine.cpp (GetArrayTypeFromSubType) Array type creates from default one without name and "troops" becomes array sub-type. When WriteObjectType() on this array called. Only Array type saved. Without any information about it's sub-type. And so can't be restored. This how it looks for me. I'm not sure if i'm not miss something. If it so, then this one becomes a bug.

Share this post


Link to post
Share on other sites
I've been able to fix this problem with a couple of changes to the as_restore.cpp module.


// CHANGE: Add this include
#include "as_arrayobject.h"

// CHANGE: Exchange the WriteObjectType() method
void asCRestore::WriteObjectType(asCObjectType* ot)
{
char ch;

// Only write the object type name
if( ot )
{
if( ot->flags & asOBJ_SCRIPT_ARRAY && ot->name != asDEFAULT_ARRAY )
{
ch = 'a';
WRITE_NUM(ch);

if( ot->subType )
{
ch = 's';
WRITE_NUM(ch);
WriteObjectType(ot->subType);

ch = ot->arrayType & 1 ? 'h' : 'o';
WRITE_NUM(ch);
}
else
{
ch = 't';
WRITE_NUM(ch);
WRITE_NUM(ot->tokenType);
}
}
else
{
ch = 'o';
WRITE_NUM(ch);
WriteString(&ot->name);
}
}
else
{
ch = '\0';
WRITE_NUM(ch);
// Write a null string
asDWORD null = 0;
WRITE_NUM(null);
}
}

// CHANGE: Exchange the ReadObjectType() method
asCObjectType* asCRestore::ReadObjectType()
{
asCObjectType *ot;
char ch;
READ_NUM(ch);
if( ch == 'a' )
{
READ_NUM(ch);
if( ch == 's' )
{
ot = ReadObjectType();
asCDataType dt = asCDataType::CreateObject(ot, false);

READ_NUM(ch);
if( ch == 'h' )
dt.MakeHandle(true);

dt.MakeArray(engine);
ot = dt.GetObjectType();
}
else
{
eTokenType tokenType;
READ_NUM(tokenType);
asCDataType dt = asCDataType::CreatePrimitive(tokenType, false);
dt.MakeArray(engine);
ot = dt.GetObjectType();
}
}
else
{
// Read the object type name
asCString typeName;
ReadString(&typeName);

// Find the object type
ot = module->GetObjectType(typeName);
if( !ot )
ot = engine->GetObjectType(typeName);
}

return ot;
}





These fixes will also be available in the next release.

Thanks for notifying me about this bug.

Regards,
Andreas

Share this post


Link to post
Share on other sites

This topic is 4475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this