bdbodger wrote:For the array thing if I wanted to store values in the $player array I can do it the first element is of course is $player[1] for example but I can add values to that array . Usually I dont do it for a player but it can be done . like I can do
$player[1]["somestring"][1] = 10
$player[1]["somestring"][2] = 20
normally I do it for a level variable like in my strafe script where I number the nodes level.strafenode[set #][node #].origin etc but I am fairly sure that the $player array is like any other array except that the indexing starts at 1 not 0 .
Well I don't see it being that surprising that you could make a variable level.strafenode which is actually a two-dimensional array. I mean, you could easily declare something like that in C:
Code: Select all
typedef struct {
[...]
vector_t origin;
[...]
} node_t;
typedef struct {
[...]
node_t strafenode[MAX_SET_NUM][MAX_NODE_NUM]; // a 2D array of pointers to nodes
[...]
} level_t;
level_t level;
'level.strafenode[x][y].origin' would be a valid thing to reference in that C code.
However, with your $player example, it wouldn't be a simple matter like that because, for any valid player index n, $player[n] is both an object of type Player with a number of fields
and it is a two dimensional array. The only way something like that would make sense in C is if $player[n] was of a 'union' type, but that wouldn't be what you're using here, you're using two separate sets of storage. It's more like this:
Code: Select all
tyepdef struct {
vector_t origin;
int health;
[...]
} player_t;
typedef struct {
player_t the_player;
int the_other_data[MAX_MAJOR_INDEX][MAX_MINOR_INDEX];
} player_wrapper_t;
player_wrapper_t player[MAX_PLAYERS];
In that case, you could use 'player[1].the_player.origin' to get the player's origin and 'player[1].the_other_data[1][2] = 10' to access that array (of course C doesn't allow you to use strings as array indices), but note that you need to distinguish between whether you are accessing 'the_player' or 'the_other_data'.
I can see how your level.strafenode example works, it makes perfect sense, but I don't know how you could make '$player[n]' refer to both the Player object and some other array you made up at the same time. If you replaced '$player[1]["somestring"][1] = 10' with '$player[1].
mydata["somestring"][1] = 10' it'd make a lot more sense to me.
Of course I don't know everything about the language but it just seems weird
Regards,
David