Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Preventing destruction of variables declared in script


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
1 reply to this topic

#1 Miracle Dog   Members   -  Reputation: 122

Like
0Likes
Like

Posted 22 August 2004 - 05:09 AM

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)

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3288

Like
0Likes
Like

Posted 22 August 2004 - 05:29 AM

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.
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.



PARTNERS