🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Problems building scripts

Started by
4 comments, last by Malmer 20 years ago
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?
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]
I''ve experienced problems like this, but the problems were usually inside the actual script file. Maybe you could post that?
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
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.
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement