Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, The_Judge, Grant), 898 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 3 1 2 3
Re: Function called by Entity is terminated after Entity is removed? [Re: Bunsen] #260267
04/09/09 20:46
04/09/09 20:46
Joined: Jan 2005
Posts: 605
Deutschland, NRW
G
garv3 Offline OP
User
garv3  Offline OP
User
G

Joined: Jan 2005
Posts: 605
Deutschland, NRW
Please use a code block when posting lite-c code. I really don't want to try to understand this...


GameStudio Version: A7 Pro v7.86
Re: Function called by Entity is terminated after Entity is removed? [Re: garv3] #260275
04/09/09 22:26
04/09/09 22:26
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
KDuke, I apologise, you have been proven correct by our guest Bunsen.
Thanks bunsen, wroks right, but still a little over-complex.
Ive simplified the action down to this, and it still works fine.
Code:
function doSomeStuff(ENTITY **ent)
{ 
   while( *ent )
   {
      // do something as long as the entity exists:
      (**ent).pan += time_step * 6;
      wait(1);
   }
   // do something else:
   printf("I'll be back!"); // signal NORMAL termination 
}

But still, needing to use (**ent)to access the entity all the time is messy.
A built in function testing the validity of the entity pointer is easier,
or, as the developers are now looking into, we can dump our entity pointer into
the ME pointer, and the engine will set it to NULL if the entity is removed
in ANY other function.

But thanks again Bunsen for your contribution that proves that I am only human,
and not a machine AI...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Function called by Entity is terminated after Entity is removed? [Re: EvilSOB] #260319
04/10/09 06:45
04/10/09 06:45
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline
Member
KDuke  Offline
Member
K

Joined: Mar 2009
Posts: 112
Germany
That's only half the truth! You have been right as well. It is not working if the pointer-pointer is pointing to a pointer (omg!) which has not been declared globally.

In case this might not be as comprehensive as I think it is here two code examples considering doSomeStuff is the function posted by EvilSOB one post above me.
Code:
ENTITY* anEntity;

function testing()
{
  anEntity = ent_create(NULL, NULL, NULL);
  //whatever has to be done
  doSomeStuff(&anEntity);
  ent_remove(anEntity);
  anEntity = NULL;
}

The above example works.

Code:
function testing()
{
  ENTITY* anEntity = ent_create(NULL, NULL, NULL);
  //whatever has to be done
  doSomeStuff(&anEntity);
  ent_remove(anEntity);
  anEntity = NULL;
}

This one doesn't.

greetings
K-Duke


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: Function called by Entity is terminated after Entity is removed? [Re: KDuke] #260325
04/10/09 08:20
04/10/09 08:20
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Originally Posted By: KDuke
It is not working if the pointer-pointer is pointing to a pointer (omg!) which has not been declared globally.
And thats what I was doing most of my testing, because that how "I" usually use entities.
I tend to stick to local pointers, and avoid globals, because Im a bit un-imaginative with names.
And I like my functions/actions to be very portable between projects, and so I avoid using external resources
like globals of any type, unless they a built-in engine ones.

Id say I probably fumbled the test when it WAS a global, because of sloppiness as I was expecting it to fail.
Not a very scientific approach. And looking back I can see I was trying to access the entities properties badly when I was testing.
(I was trying to use (*ent).pan+= instead of (**ent).pan+= to make it rotate.)

Ah well, live and learn, if I remember. Thats the hard part. grin


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Function called by Entity is terminated after Entity is removed? [Re: EvilSOB] #260889
04/14/09 13:16
04/14/09 13:16
Joined: Apr 2009
Posts: 33
Germany
B
Bunsen Offline
Newbie
Bunsen  Offline
Newbie
B

Joined: Apr 2009
Posts: 33
Germany
Sorry this comes a little late but I spent the last days
searching for Easter eggs.

Local version (avoiding globals):



Code:
//-------------------------------------------------------------------
function doSomeStuff(ENTITY **ent)
{  
   while (*ent)
   {
      // do something as long as the entity exists:
      (**ent).pan += time_step * 6;
      wait (1);
   }
   // do something else:
   // ...
   
   printf("I'll be back!"); // signal NORMAL termination  
}

//-------------------------------------------------------------------
function main()
{
   level_load(NULL);
   wait(2);
	
   ENTITY **cubeObj = malloc(sizeof(void*));
   *cubeObj = ent_create("cube.mdl", vector(122,0,0), NULL);
	
   doSomeStuff(cubeObj);
	
   while (*cubeObj != NULL)
   {
      if (key_x)
      {
         ent_remove(*cubeObj);
	 *cubeObj = NULL;
      }
      wait(1);
    }
	
    free (cubeObj);
}


Page 3 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1