Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

ExecuteString() doesn't work on multiline scripts


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Gyrbo   Members   -  Reputation: 187

Like
0Likes
Like

Posted 19 August 2004 - 02:06 AM

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.

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3370

Like
0Likes
Like

Posted 19 August 2004 - 02:59 AM

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

#3 Andreas Jonsson   Moderators   -  Reputation: 3370

Like
0Likes
Like

Posted 19 August 2004 - 10:21 AM

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

#4 Andreas Jonsson   Moderators   -  Reputation: 3370

Like
0Likes
Like

Posted 19 August 2004 - 10:25 AM

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

#5 Gyrbo   Members   -  Reputation: 187

Like
0Likes
Like

Posted 20 August 2004 - 12:25 AM

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).

#6 Andreas Jonsson   Moderators   -  Reputation: 3370

Like
0Likes
Like

Posted 20 August 2004 - 02:24 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS