AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   What's difference between... (https://forums.alliedmods.net/showthread.php?t=313146)

ByPass 12-29-2018 17:27

What's difference between...
 
What's the difference between this:

PHP Code:

new a[32];

public 
some_func()
{
    
a[id] = create_entity("info_target");


And this:

PHP Code:

new a[32][1];

public 
some_func()
{
    
a[id][0] = create_entity("info_target");


Could you explain it to me?

NOTE: It should be noted that from where I see it, there is no difference, but I may be wrong...

Bacardi 12-29-2018 17:35

Re: What's difference between...
 
1 Attachment(s)
You create array and 2d array.

*edit
Ok, I misread, it should be new a[32][2];
Because if you create [array], you set array size. Array index start from 0.



Code:

new a[32];

a[0]
a[1]
a[2]
a[3]
a[4]
a[5]
...

Code:

new a[32][2];

a[0][0]
a[0][1]
a[1][0]
a[1][1]
a[2][0]
a[2][1]
a[3][0]
a[3][1]
...




here picture 3D
g_variable[1][3][0] = 1337
https://forums.alliedmods.net/attach...1&d=1546123151

ByPass 12-29-2018 18:09

Re: What's difference between...
 
That means that for each player of the 32 players can be created 2 different entities or just one?

PHP Code:


#define MAX_PLAYERS 32
#define MAX_ENTITIES_PER_PLAYER 2

new a[MAX_PLAYERS][MAX_ENTITIES_PER_PLAYER];

a[id][0] = create_entity("info_target"); // entity 1
a[id][1] = create_entity("info_target"); // entity 2 

And those two entities do not affect each other?

The thing is that I want to create an array for each player where I can store an undetermined number of entities.

edon1337 12-29-2018 18:11

Re: What's difference between...
 
Quote:

Originally Posted by ByPass (Post 2631694)
That means that for each player of the 32 players can be created 2 different entities or just one?

PHP Code:


new a[32][2];

a[id][0] = create_entity("info_target"); // entity 1
a[id][1] = create_entity("info_target"); // entity 2 

And those two entities do not affect each other?

In your case, two.

fysiks 12-29-2018 21:00

Re: What's difference between...
 
Quote:

Originally Posted by ByPass (Post 2631694)
The thing is that I want to create an array for each player where I can store an undetermined number of entities.

Either you have to set MAX_ENTITIES_PER_PLAYER to a large number and make sure you have code to deal with the situation where you run out or you have to get tricky with a bunch of dynamic arrays. I'd recommend former.

ByPass 12-29-2018 22:27

Re: What's difference between...
 
Quote:

Originally Posted by fysiks (Post 2631708)
Either you have to set MAX_ENTITIES_PER_PLAYER to a large number and make sure you have code to deal with the situation where you run out or you have to get tricky with a bunch of dynamic arrays. I'd recommend former.

Sure, I've the concept well established, what I would like to know is if it's appropriate to do it that way:

Create an array of each player, where for each player at least 4 entities (of any kind or nature) can be created.

PHP Code:

// Something like this:

new entities[32][4];

public 
some_func(id)
{
     
entities[id][0] = create_entity("env_model");
     
entities[id][1] = create_entity("info_target");
     
entities[id][2] = create_entity("env_sprite");
     
entities[id][3] = create_entity("func_breakable");


I would also like to know if doing it in this way the configuration of the entities will affect each other.

That is, I want to know if they could "mix" or "affect" each other ...

fysiks 12-30-2018 01:32

Re: What's difference between...
 
Quote:

Originally Posted by ByPass (Post 2631711)
I would also like to know if doing it in this way the configuration of the entities will affect each other.

That is, I want to know if they could "mix" or "affect" each other ...

That has nothing to do with how you store the entity number. It will depend on how the entities them selves behave and what you do with them.

Natsheh 12-30-2018 06:12

Re: What's difference between...
 
There is a bit diffs which is you can achieve it using 1dArray, making it 2d array is just useless by adding one cell to each row.


If you have another question start a new thread...


All times are GMT -4. The time now is 07:29.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.