Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Help compiling code


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
11 replies to this topic

#1 Drakkcon   Members   -  Reputation: 612

Like
0Likes
Like

Posted 06 September 2004 - 11:01 AM

Argg, I'm already having trouble. I read on the overview how to write a program that compiles anglescript code, and I wrote a program. The problem is, it crashes when it runs (no compiler or linker errors)!
#include <angelscript.h>

int main(int argc, char *argv[])
{
  asIScriptEngine *engine;
  
  // Load the script
  const char *script = "script.ang";

  // Compile the script
  engine->AddScriptSection("module", "section", script, strlen(script), 0);
  engine->Build("module", 0);
  
  return 0;
}  

That's my C++ code
float global_var = 0;

void DoSomething()
{
  ++global_var;

  if( global_var > 10 )
    global_var = 0;
}

That's the angel script code. I used the library that I created with the Dev-C++ project file. I think it may be a problem with the library I made, but I'm not sure. On a similar note, PLEASE make a downloadable static library!

Sponsor:

#2 desertcube   Members   -  Reputation: 514

Like
0Likes
Like

Posted 06 September 2004 - 11:50 AM

OK, first of all, engine is just pointing to a random bit of memory, you need to call asCreateScriptEngine. You should then release this at the end of your program.
Secondly, AddScriptSection doesn't load the file for you. You need to load the file and get all of it's data and place it in a char array.
So, you should have somehting similar to this:

void RunScript()
{
asIScriptEngine * engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
const char * script = LoadScript("c:\\scriptfil.as"); //Get all the information from the file
engine->AddScriptSection(0, "section", script, strlen(script));
engine->Build(0, NULL);
ret = ExecuteScript();

asIScriptContext * ctx;
engine->CreateContext(&ctx);

//Prepare context

ctx->Execute();

ctx->Release();
engine->Release();
}




You will need to do error checking and I've probably missed a whole lot of stuff out, but you should get a feel for it.

The best examples (and the way I'm learning about angel script) are found in the test framework, you should download it and go through the code.

Hope this is enough to get you started.

EDIT: Changed some of the source code (forgot to add script section!)

#3 Drakkcon   Members   -  Reputation: 612

Like
0Likes
Like

Posted 06 September 2004 - 12:00 PM

Thanks for your help and test framework recommendation! Still, I find it very difficult sorting through all that code. Is there a tutorial anywhere? The dox don't include any examples.

#4 Drakkcon   Members   -  Reputation: 612

Like
0Likes
Like

Posted 06 September 2004 - 01:29 PM

I guess I won't be using angle script then.
[code=auto:0]
../../../Documents and Settings/Grant Williams/Desktop/angelscript/lib/libangelscript.a(as_scriptengine.o)(.text+0x395):as_scriptengine.cpp: undefined reference to `asCModule::~asCModule()'
../../../Documents and Settings/Grant Williams/Desktop/angelscript/lib/libangelscript.a(as_scriptengine.o)(.text+0x427):as_scriptengine.cpp: undefined reference to `asCString::~asCString()'
../../../Documents and Settings/Grant Williams/Desktop/angelscript/lib/libangelscript.a(as_scriptengine.o)(.text+0x5e2):as_scriptengine.cpp: undefined reference to `asCString::~asCString()'
../../../Documents and Settings/Grant Williams/Desktop/angelscript/lib/libangelscript.a(as_scriptengine.o)(.text+0x5f9):as_scriptengine.cpp: undefined reference to `asCString::~asCString()'
etc. (removed the rest of the 300 errors because it was slowing the page loads)

[/source]
That's what happens when I use that engine create function. It's probably a static library problem. Sigh, back to python.

[Edited by - Drakkcon on September 8, 2004 7:29:29 PM]

#5 Andreas Jonsson   Moderators   -  Reputation: 3453

Like
0Likes
Like

Posted 06 September 2004 - 02:15 PM

Please, don't be so hasty to give up on AngelScript. The linker errors you are getting is because the Dev-C++ project file you're using isn't up to date. You'll need to include the files as_string.cpp, as_string_util.cpp, and as_module.cpp for compilation. If you do add the files, could you send me the new project file so that I can update the site?

I'm sorry that I don't have a complete tutorial that tells how to get things working. The overview article, and the test_framework.cpp are the closest thing to a tutorial that I have at the moment. Each test case in the test_framework are working examples on using the library.

If you just have a little patience I will do my best to help you getting everything up and running.

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

#6 lxnyce   Members   -  Reputation: 122

Like
0Likes
Like

Posted 07 September 2004 - 10:42 AM

I realize that he is already past this problem, but how about making a simple function (or class) to automatically load in a script file into an array. Beginners usually don't like to sit there and code this by hand, so I figure it will be helpful. I took 5 minutes and came up with a simple one here. You can do whatever you want with it.

http://www.xl3d.com/angelscript/asLoadFile.h

All they would have to do is include that file above, and the above example would turn into :


asLoadFile file("test.cpp");
engine->AddScriptSection("module", "section", file, file.Size(), 0); /* Note you can test file to see if its NULL. If so, then the file wasn't loaded or empty. */


#7 Lioirc   Members   -  Reputation: 142

Like
0Likes
Like

Posted 07 September 2004 - 11:58 AM

There is a file loader code in the testframework testexecutestring.cpp or something , and if simply need to get the feeling of this library or see how it behaves under different conditions, its simply to paste that code in your project or modify it there.

Sorry to sound a little rude, but a you probably need to get a few tutorials or books on c++ programming first, how you will use c++ and bind c++ code on scripts when you dont know what a pointer is ?


#8 lxnyce   Members   -  Reputation: 122

Like
0Likes
Like

Posted 07 September 2004 - 05:50 PM

Completely understood, but for people just starting off who want to play with scripts, it would be nice to not have to go through and look for it. I wasn't aware this was already in there. Its a pretty simple task like I said, but it should just be made more visible for beginners.

#9 Andreas Jonsson   Moderators   -  Reputation: 3453

Like
0Likes
Like

Posted 08 September 2004 - 05:35 AM

Thanks for the recommendation. I'll update the overview article with a quick implementation for loading a script file.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#10 Drakkcon   Members   -  Reputation: 612

Like
0Likes
Like

Posted 08 September 2004 - 11:56 AM

Thank you very much for all of your help people. It's also very nice to see how involved WitchLord is with his scripting engine. I'll work on getting the correct version of the files linked into a new project file, and send it to witchlord (it may not be today, tons of homework). Thanks again!

Quote:

Sorry to sound a little rude, but a you probably need to get a few tutorials or books on c++ programming first, how you will use c++ and bind c++ code on scripts when you dont know what a pointer is ?

No, you're right. However I DO know C++, it was just a stupid error on my part (declaring a pointer with out giving it something to point to). Sorry, I'm being defensive, it was a pretty dumb mistake.


[Edited by - Drakkcon on September 8, 2004 7:56:36 PM]

#11 Drakkcon   Members   -  Reputation: 612

Like
0Likes
Like

Posted 08 September 2004 - 01:58 PM

YES! I got a working static library! I will be sending the project file and source, and the static library. Thanks for the help everyone.

#12 Andreas Jonsson   Moderators   -  Reputation: 3453

Like
0Likes
Like

Posted 08 September 2004 - 03:23 PM

It's great to hear that you didn't give up on the library.

AngelScript is still very new. It has only been available to the public for about 15 months, and new code is added to it every month. You'll most likely come upon a bug or two during your use of the library, but I ask you to have patience. I'll do my best to fix them as quickly as possible.
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