Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (VoroneTZ), 1,233 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
ENTITIES into array #342310
09/26/10 14:01
09/26/10 14:01
Joined: Aug 2010
Posts: 26
J
JHA Offline OP
Newbie
JHA  Offline OP
Newbie
J

Joined: Aug 2010
Posts: 26
Hello
Is it possible to put ENTITY(s) to array, something like

ENTITY BULLET[8]

and then have access to them like any array:

BULLET[1]= ent_create("ball2.mdl",BulletP,DestroyBulletIfOutsite);

Or is there some vector where engine keeps the pointers. Because when pressing F11 is possible to see number of entities?
JHA

Re: ENTITIES into array [Re: JHA] #342312
09/26/10 14:10
09/26/10 14:10
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Why don't you just try it?

ENTITY* BULLET[8];


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: ENTITIES into array [Re: Superku] #342485
09/28/10 15:53
09/28/10 15:53
Joined: Aug 2010
Posts: 26
J
JHA Offline OP
Newbie
JHA  Offline OP
Newbie
J

Joined: Aug 2010
Posts: 26
This works ok. But doing coding sometime, I have learned that with pointers and dynamic memory one has to be pretty carefull. Anyway so far so good. Thanks

Re: ENTITIES into array [Re: JHA] #342553
09/29/10 07:31
09/29/10 07:31
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I cant see any dynamic here.

The pointer-array (Superku's example) is a static array, not dynamic.
And entities are static in memory once created.

Just remember to fill your array with NULLs at startup time.
eg
Code:
#define MAX_BULLET 10
ENTITY* BULLET[MAX_BULLET];

void BULLET_startup()
{  int i;   for(i=0; i<MAX_BULLET; i++)   BULLET[i] = NULL;   }




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: ENTITIES into array [Re: EvilSOB] #343011
10/03/10 06:18
10/03/10 06:18
Joined: Aug 2010
Posts: 26
J
JHA Offline OP
Newbie
JHA  Offline OP
Newbie
J

Joined: Aug 2010
Posts: 26
OK, and thanks again, I will add this NULL filling of vector into initilization

Re: ENTITIES into array [Re: EvilSOB] #343187
10/04/10 10:02
10/04/10 10:02
Joined: Nov 2005
Posts: 112
M
miez Offline
Member
miez  Offline
Member
M

Joined: Nov 2005
Posts: 112
What is happening, if the Arrayparts arenīt filled with NULL at the beginning?

Re: ENTITIES into array [Re: miez] #343188
10/04/10 10:06
10/04/10 10:06
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
nothing


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: ENTITIES into array [Re: WretchedSid] #343189
10/04/10 10:20
10/04/10 10:20
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Nothing "happens", but if you dont put null in you get random numbers in them.
That then makes it more difficult to know which ones are used or not.

If you NULL them all, you can then use this to see what elements are in use.
Code:
if(BULLET[idx]) { bullet-IS-being-used     }
else            { bullet-is-NOT-being-used }

//or

if(BULLET[idx]==NULL) { bullet-is-NOT-being-used     }
else                  { bullet-IS-being-used }


Just remember to set them to NULL when youve finished using them...
Code:
ent_remove(BULLET[idx]);
BULLET[idx] = NULL;




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: ENTITIES into array [Re: EvilSOB] #343233
10/04/10 16:42
10/04/10 16:42
Joined: Nov 2005
Posts: 112
M
miez Offline
Member
miez  Offline
Member
M

Joined: Nov 2005
Posts: 112
The array get filled with random Numbers?...
wow...
1. why (would Auto-Null not be more elegant?)
and
2. Didnīt know that. This explains a lot of problems I encountered. Will keep it in Mind for Future things.

Thereīs always quiet a bit to learn, when reading here.

Re: ENTITIES into array [Re: miez] #343236
10/04/10 16:59
10/04/10 16:59
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: miez
The array get filled with random Numbers?...
wow...
1. why (would Auto-Null not be more elegant?)

It would cost more CPU cycles and would be slower. The reason is simple: You just get a random chunk of memory and everything what was before you in this chunk of memory is still there.

But I know of one exception that at least exist on iOS and Mac OS X: When you get a new memory page, it is nulled by the OS for security reasons. However, as long as this page is mapped into your application (or vice versa), this won't happen again.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Page 1 of 2 1 2

Moderated by  HeelX, Spirit 

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