Preventing destruction of variables declared in script

Started by
0 comments, last by WitchLord 19 years, 8 months ago
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)
Advertisement
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

This topic is closed to new replies.

Advertisement