Module building error

Started by
12 comments, last by luizribeiro 18 years, 8 months ago
Hello... This is my first try with AngelScript, I'm using the following code:
// AngelScript
void Update() {
        float x = 1.333;
        return x;
}

// C++
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);;
FILE *f = NULL;
char *script = NULL;
int length = 0;
int functionID;

// Load the script
f = fopen("myscriptfile.as", "r");
fseek(f, 0, SEEK_END);
length = int(ftell(f));
fseek(f, 0, SEEK_SET);
script = new char[length];
fread(script, length, 1, f);
fclose(f); f = NULL;

// Compile the script
if(engine->AddScriptSection("module", "section", script, length) < 0) {
	printf("Error on AddScriptSession.\n");
	return 1;
}
int err = engine->Build("module");
if(err < 0) {
	printf("Error building the module: %d\n", err);
	return 1;
}
	
// ...
It's returning "Error building the module: -1"... I really don't know what to do... I think it's a stupid thing, but I'm starting... hehe Thanks anyway... Luiz Ribeiro
Advertisement
Your function is declared void but you are returning a float.
Olá, Luiz! Seja bem vindo. [smile]

Rain Dog is correct.

You can use the output stream in order to receive the compiler messages, including warnings and errors. Example:

class COutStream : public asIOutputStream{public:	void Write(const char *text) { printf(text); }};COutStream out;	int err = engine->Build("module", &out);


Regards,
Andreas

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

Duh for me. hah. Sorry for the stupid topic hahahaha ;)
Thanks for the fast replies too :D

WitchLord, thanks for the tip, I'll give it a try right now...

Thanks again,
Luiz Ribeiro
Hello... I have some more questions, can I post them here so I don't flood the topic list? heh
1st: Can I export a C++ enum or #define to AngelScript? Something like:
#define PI 3.14enum { A, B, C, D ... }


And use these constants on AngelScript?

The second question is: how can I pass objects pointers as arguments to a AngelScript function? So I can pass a Particle object to an AngelScript void Update(Particle p) function (that will Update the particle properties via the pointer)... Using this instead returning a Particle object from the Update function (and getting a Particle as argument) can speed up the application? (it will execute many times by second, it's a particle engine)

I think that's it for now... Thanks ;)
Luiz Ribeiro
A define, no. Change it to a const double or something similar, and you can register that value with AS..

As for the enum, I don't believe so, but it would be a nice feature.
What about compiling my script? So I won't need to distribute my application with the scripts source codes, I will distribute the bytecode compiled script... Like the `luac` does...
Angelscript can save compiled bytecode and load it again later. Just keep in mind that if your configuration changes, the saved bytecode becomes invalidated. Therefore, it is a good idea to work only with script source files during development, and switch to compiled bytecode after the engine is stabilized.

For defines, you can always use my Preprocessor addon. It's on the angelcode addon page. It will work, but defines are NOT the prefered solution for constants anymore. You could, however, have a script header that defines these constants, and use the preprocessor to #include it. Enumerations can be done with constants as well. Since enum members share the same scope as their enum-type-name in C++ (That is; the value of 'a' in enum foo { a = 0; }; is accessed with the identifier 'a', not 'foo::a'.) the results are exactly the same.

And for your final question; no. Pointers were removed from AngelScript as of 2.0, and replaced with Handles that behave like smart pointers. Autohandles remove almost all of the grunt work associated with using the handle mechanism. If speed is more of an issue than safety (which I suspect it would be in a particle engine) you can use pointers in the 1.10.1d distrobution. I'm not certain how much of a speed difference there is between pointers and handles. Handles insert a few extra calls to reference count management functions. I'm still using 1.10.1d myself; since players of my game can't access the scripts at all (It's all server side) safety is less of a concern for me.
I tried the following to create a constant for the PI number:
float pi = float(M_PI);engine->RegisterGlobalProperty("const float PI", π);


It works. But then it's not a constant on the engine and someone can edit it when working on the engine hehe... If I use const float pi = float(M_PI)... Walla! It doesn't work.

Isn't there anyway to simply:
engine->RegisterGlobalProperty("const float PI", float(M_PI));// (converting to float since M_PI is a double)


Thanks again and sorry for the lots of questions,
Luiz Ribeiro
Your second example: No. You are registering a temporary. That's bad, to say the least.

This topic is closed to new replies.

Advertisement