Advertisement

Referencing and pointers in the script

Started by July 05, 2004 01:42 PM
1 comment, last by WitchLord 20 years, 4 months ago
I'm not sure how this works. I want to make a struct in angelscript that I already registered. Then I want to call a function in angelscript to initialize the struct. So here is what I want to do:

void initObjTable(ObjTable *&t)
{
	t->img = 0; t->frames = 0;
	t->AI = 0; t->dir = 0; t->freq = 0;
	t->downTimeMax = 0; t->downTime = 0;
	t->depthAdjust = 0; t->bubbleAlways = 0;
	t->lightSource = 0; t->lightStrength = 0;
	t->sucktion = 0; t->anchorWall = 0;
	t->anchorWallDir = 0; t->dieScript = 0; t->visibleScript = 0;
	return;
}

bool setObjTable()
{
	ObjTable t;
	initObjTable(&t);
	t.img = 0; 
	t.frames = GetFrames(t.img);
	return false;
}
The building fails when I call initObjTable(&t); But, if I take out the &t or the *&t in the objTable function, it works fine, so I know it isn't anything else causing the problem. I'm wondering if doing this kind of thing is possible in the scripts, but if not, how can I do it by passing a struct to the host app and then having the host app pass back the struct to angelscript?
You are asking for a pointer to a reference, which I don't think makes much sense and probably wouldn't work (or at least not be what you want) in regular C. Try changing your first function to:

void initObjTable(ObjTable *t)

in the line initObjTable(&t), &t returns a pointer to the object T, which is what the function requires.

- Xavier
Advertisement
AngelScript doesn't have an explicit operator for taking the pointer of an object, nor the reference. This was design decision made for security reasons.

When you pass an object as parameter defined to be sent by reference the language will implicitly take the reference. Thus you should write your code like this:

void initObjTable(ObjTable &t){	t.img = 0; t.frames = 0;	t.AI = 0; t.dir = 0; t.freq = 0;	t.downTimeMax = 0; t.downTime = 0;	t.depthAdjust = 0; t.bubbleAlways = 0;	t.lightSource = 0; t.lightStrength = 0;	t.sucktion = 0; t.anchorWall = 0;	t.anchorWallDir = 0; t.dieScript = 0; t.visibleScript = 0;	return;}bool setObjTable(){	ObjTable t;	initObjTable(t);	t.img = 0; 	t.frames = GetFrames(t.img);	return false;}


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

This topic is closed to new replies.

Advertisement