Advertisement

Passing struct to script

Started by January 27, 2005 02:53 AM
4 comments, last by LE 19 years, 10 months ago
Hi I am trying to do this test.as void func(obj &testObj) { testObj.a = 5; } I am using the testexecutescript.cpp from the 2.0.0 SDK as base for this. Load is ok compile fails

// Execute script
	struct testObj
	{
		int a;
		float b;
	};

	testObj obj;

	ctx->SetArgObject(0, &obj);
	r = ctx->Execute();
	if( r < 0 )
	{
		printf("%s: Unexpected error during script execution\n", TESTNAME);
		return true;
	}
A suggestion would be to add explaining code to the register class page from the documentation on the angelscript site since I have a hard time figuring out what to pass.

There are quite a few examples with angelscript too. But none that I have found that show passing a struct or class to the script and then call a method and alter a property. I guess there should be one of those examples so if someone could tell me which example I should look at I will try to take it from there :)
Advertisement
It would help if you tell me what the error codes/messages that you receive are.

You've forgotten to specify the in/out/inout for the parameter reference in the script. This would cause the build to fail.

void func(obj &out testObj){  testObj.a = 5;}


In the application code you don't show how you register the testObj structure, also from your what you show you don't call ctx->Prepare() before setting the argument. Otherwise you are correct in the way you pass the argument to the script function.

---

Yes, the documentation needs to improve a lot. I'll try to add the code samples as you mentioned.

The test applications that come with the SDK aren't very good for teaching, as they take a few shortcuts, especially in error checking etc. I only use them for verifying that everything works.

I need to write some dedicated samples/tutorials to do teach how to use the library. I think I have a good idea for a simple sample that will show much of what is needed.

In the meantime I suggest you take a look at test_vector3.cpp in the test_feature project. It shows how to register a simple structure, and how to pass this to the script functions.



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

Ah that seems to be an excellent example of what I want to achieve.

I can probably get that working.

Which is the best example for getting class methods called? I guess you are not writing the new class tutorial tonight :)
You might look at these:

test_object.cpp
teststdstring.cpp / stdstring.cpp
testvirtualmethod.cpp

I'm not sure when I will get the time to write the sample. But I will try to do it as soon as possible, as I know many people would benefit from 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

I hope you get the time.

It looks like the perfect thing for my RPG that I just have started to work on.

This topic is closed to new replies.

Advertisement