Advertisement

ExecuteString() doesn't work on multiline scripts

Started by August 19, 2004 08:06 AM
4 comments, last by WitchLord 20 years, 3 months ago
The following script fails to run correctly:

cfg.FullScreen = false;
cfg.OpenGL = true;

The error is:
ExecuteString (2, 19) : Error   : Expected expression value
If I place the two commands on one line it works correctly. I'm aware that this isn't exactly how ExecuteString() was meant to be used, but it provides a quick method of executing small scripts. Some more info: "cfg" is a global object of type "Config" with two members, "FullScreen" and "OpenGL" which are both bools. The script is placed in an external file and is used as a configuration file.
ExecuteString() should be able to execute more than one statement, even on multiple lines. What happens is that the string you pass to it is wrapped inside a function like so:

script = "void ExecuteString() {" + string + ";}";

Then that script is compiled and executed.

I'll try to verify why your script doesn't work. It seems that it is a bug when there are ;; (the library adds one extra ;) at the end.

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

Advertisement
I ran the following test without problem with 1.9.1 WIP 2 (not yet released). Either you are doing something differently from me, or I've already managed to fix the bug you found without knowing it.

//// Tests ExecuteString() with multiple lines of code//// Test author: Andreas Jonsson//#include "angelscript.h"#include <stdio.h>#include <stddef.h>#define TESTNAME "TestExecuteString"struct Obj{	bool a;	bool b;} g_Obj;class COutStream : public asIOutputStream{public:	void AS_CALL Write(const char *text) { printf(text); }};bool TestExecuteString(){	bool fail = false; 	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);	engine->RegisterObjectType("Obj", sizeof(Obj), asOBJ_CLASS);	engine->RegisterObjectProperty("Obj", "bool a", offsetof(Obj,a));	engine->RegisterObjectProperty("Obj", "bool b", offsetof(Obj,b));	engine->RegisterGlobalProperty("Obj g_Obj", &g_Obj);	g_Obj.a = false;	g_Obj.b = true;	COutStream out;	engine->ExecuteString(0, "g_Obj.a = true;\n"		                     "g_Obj.b = false;\n", &out, 0);	engine->Release();	if( !g_Obj.a || g_Obj.b )	{		printf("%s: ExecuteString() didn't execute correctly\n", TESTNAME);		fail = true;	}		// Success	return fail;}

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

Wait, you say you load the script from file and then execute it? Could you check the string you are sending to ExecuteString() to see if there are no strange characters going in?

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

I've made a couple of changes to the config file loader, and the error doesn't occur anymore. I was using some non-standard stuff, so that would probably be the problem (registering an array as an object).
Ok. I'll ignore this potential bug for now. If it troubles you again let me know and I'll take a closer look at it.

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