Sign in to follow this  

using pointer access

This topic is 4723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have the following function in angelscript. cannot pass the address of an object over to the function, the compiler keep complaining about accessing error. how to do it correctly? void main() { Point3 p; p.x = 123; p.y = 456; p.z = 789; SC_Main_Point (&p); //cannot work!! } void SC_Main_Point (Point3 *po) { Console ("#####################"); ConsoleF (po->x); ConsoleF (po->y); ConsoleF (po->z); }

Share this post


Link to post
Share on other sites
AngelScript don't allow the manipulation of pointers, nor taking the address of variables, due to security reasons.

You can however pass parameters by reference, so doing the following would work:


void main()
{
Point3 p;

p.x = 123;
p.y = 456;
p.z = 789;

SC_Main_Point (p); // The point is passed by reference

}



void SC_Main_Point (Point3 &po)
{
Console ("#####################");
ConsoleF (po.x);
ConsoleF (po.y);
ConsoleF (po.z);
}

Share this post


Link to post
Share on other sites
that works gracefully!!

btw, how to compare whether a pointer is null in angelscript ?


i tried to no valid:

float *p;

if (p == NULL) //does not work
{

}

Share this post


Link to post
Share on other sites
NULL doesn't exist in AS 1.10.1, but you should be able to use 0.


if( p == 0 )
...


In AS 2.0.0 pointers don't exist as they do in C++, but there you have handles, which are basically smart pointers. With these you can compare with 'null' to verify if they are set or not.

Share this post


Link to post
Share on other sites

This topic is 4723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this