Jump to content
  • Advertisement
Sign in to follow this  
Gyrbo

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!