Sign in to follow this  
wolfeinstein

Built-in script arrays

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
You may be right about this. I'll look into it as soon as possible.

For now, it might be better to load the script source and compile it instead of using the precompiled code.

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

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