Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now
- - - - -

Referencing and pointers in the script

4: Adsense

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

#1 Ped Xing   Members   

122
Like
0Likes
Like

Posted 05 July 2004 - 07:42 AM

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?

#2 meink   Members   

133
Like
0Likes
Like

Posted 05 July 2004 - 06:29 PM

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

#3 Andreas Jonsson   Moderators   

4629
Like
0Likes
Like

Posted 06 July 2004 - 01:49 AM

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




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.