Sign in to follow this  

Preventing destruction of variables declared in script

This topic is 4895 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

Hi, I've exposed my game_entity class to angelscript. in the constructor it adds the pointer of itself to a linked list of all game_entities. So how can I have something like this:
int main(game_entity *this)
{
if(whatever = true)
{
  game_entity bullet;
  bullet.set_position = 3;
  bullet.set_velocity = vector3d(0, 1, 0);
}
}
And then still have the "bullet" entity available by the linked list afterwards? (it seems to delete any script-declared variables once the script finishes)

Share this post


Link to post
Share on other sites
Since the object is created locally in the script it will be stored on the script stack, which when the function exists is released. You'll have to create the object dynamically by calling some system function.

I suggest you do something like this:


int main(game_entity *this)
{
if(whatever == true)
{
game_entity *bullet = CreateEntity("bullet");
bullet->set_position = 3;
bullet->set_velocity = vector3d(0, 1, 0);
}
}


This will also allow you to have more than one variable referencing the same object, instead of having a new objected created for each variable declared.

Share this post


Link to post
Share on other sites

This topic is 4895 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