# ExecuteString() doesn't work on multiline scripts

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

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
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;}

##### Share on other sites
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?

##### Share on other sites
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).

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632630
• Total Posts
3007525
• ### Who's Online (See full list)

There are no registered users currently online

×