Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Malmer

Problems building scripts

This topic is 5121 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

When compiling any script I get this type of error. Building... Parsing: "data/ai/ship.script" Error : (17, 1) Unexpected token '''' Completed. (errors: 1, warnings: 0) Row 17 is the last row of that script, so apparently there is something wrong with the ending of the script code. This is how I load the script:
// Load the file
FILE * File = fopen( CUtil::GetPath( filename ), "rb" );
if ( File == NULL )
{
	...
}

// Get file size
int size = _filelength(_fileno( File ));
	
// Get file contents
char * scriptcode = new char[ size + 1 ];
fread( scriptcode, size, 1, File );
fclose (File);
scriptcode[ size ] = NULL;

// Load into scriptengine
int result = m_ScriptEngine->AddScriptSection( filename, scriptcode, strlen( scriptcode )+1 );
	
// Free memory
delete [] scriptcode;
 
As you can see I properly make sure the string is null-terminated. Some other comments: * If I do AddScriptSection and don''t do the +1 on strlen then the entire app crashes. * I''ve tried with using acCString in exactly the same way as in the downloadable sample, no luck. And a difference there also is that while it worked with just using "len" for strlen, I had to use len+1 or else it would crash. The difference with mine and the sample is that the sample uses 1.6.1, while I use 1.7.1. It also uses an external dll, while I don''t. * I''ve tried with different encodings of my script. Both DOS and UNIX. Also tried with the sample script. No luck. * Outputting the string data to my debug window shows nothing strange in the end of the file data stream. What is wrong?

Share this post


Link to post
Share on other sites
Advertisement
The bug appears when compiling with the Visual C++ Toolkit 2003 compiler, which is the same as in new versions of VC++. Available free.

Think it has something to do with different memory handling.

[edited by - malmer on June 10, 2004 11:49:57 AM]

Share this post


Link to post
Share on other sites
I''ve experienced problems like this, but the problems were usually inside the actual script file. Maybe you could post that?

Share this post


Link to post
Share on other sites
It works perfectly when I compile the same application with the VS6 compiler, so it has to be something with compiler differences.

Lib author: If you want to add a check for the VC7 compiler you can do like this:

#if (_MSC_VER >= 1300) // Visual Studio .NET

#endif

Share this post


Link to post
Share on other sites
To fix the bug change:


int asCBuilder::AddCode(const char *name, const char *code, int codeLength)
{
asCScriptCode *script = new asCScriptCode;
script->name = name;
script->code.SetLength(codeLength);
memcpy(script->code.AddressOf(), code, codeLength);

scripts.PushLast(script);

return 0;
}


into:


int asCBuilder::AddCode(const char *name, const char *code, int codeLength)
{
asCScriptCode *script = new asCScriptCode;
script->SetCode( name, code );
scripts.PushLast(script);

return 0;
}


The last code sample also works in the old compiler. The old code didn''t nullterminate the string put into script->code. That, by luck, worked ok in the old compilator. Did not in the new. The SetCode method that allready exists in the lib does it correctly, by adding a nullterminate to the script->code buffer.

Share this post


Link to post
Share on other sites
Well, it seems you found the bug already I''ll add the fix to the library as soon as possible. Thanks letting us know.

Regards,
Andreas



__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!