float anarray[64];
for (i = 0; i < 64; i++)
anarray[i] = somecomplexfunction(i);
blah = anarray[floor(random()*64)];
As far as I know, only using FTEQCC will you have arrays. FrikQCC or other non-fteqcc do not have arrays.
Note: It might insane to add something like .float something[<ARRAYSIZE>] in defs.qc ... remember that every entity will have that field. Might consume a rather large chunk of memory.
Last edited by Baker on Thu Jan 26, 2012 4:17 am, edited 1 time in total.
The night is young. How else can I annoy the world before sunsrise? Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
with fteqcc:
.float foo[64];
defines a field array with 64 elements.
self.foo[y] = 5;
sets element 'y' in that array to 5.
As Arkage said, older versions of fteqcc require extra brackets for field arrays: self.(foo[y]) = 5; (which kinda illustrates how fields work internally). The current version doesn't need that, but does accepts the extra brackets if you want to be paranoid.
FTEQCC's arrays are single-dimension only, thus you need to do: [x+y*width] to get 2d functionality.
As Baker said, remember that this creates 64 fields and will increase your entity size and memory footprint by quite a bit, so if you're on an embedded system you may need to be more cautious.
If you're not using any opcode extensions (ie: no -TFTE) then both reading and writing arrays will be emulated with a function call, containing a binary search to get the element, which can be somewhat slow to access.
This means that you cannot define arrays inside another function (you also cannot pass an array from one function to another).
entity dm_spawns[16]; //plenty, i dont think many maps have more than 8 spawns
entity() SelectSpawnPoint =
{
local entity spot;
local entity thing;
local float pcount;
local float r;
if (deathmatch)
{
spot = lastspawn;
while (1)
{
r = rint ((random ()) * num_dm_spawns); // choose a random % based on total number of spawns
spot = dm_spawns[r]; // pick that one
if (spot != world) // Now scan in a 32 radius circle for anyone nearby.
{
if (spot == lastspawn)
return lastspawn;
so if i were to use arrays to define stats and inventory it would mean in a multiplayer game since all entities share these fields that each player would carry the same items and have the same stats? if so it seem's arrays would be okay for single player, but what if i wanted to do multiplayer ? how does prydon do these things?
The night is young. How else can I annoy the world before sunsrise? Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
ceriux wrote:so if i were to use arrays to define stats and inventory it would mean in a multiplayer game since all entities share these fields that each player would carry the same items and have the same stats? if so it seem's arrays would be okay for single player, but what if i wanted to do multiplayer ? how does prydon do these things?
it should be the same as any other var that is unique to an entity.
So if you declare .string derp[4];
Then every entity should have a string array of 4 elements (not the same array).
So:
Player1.derp[0] = "Herp";
and
Player2.derp[0] = "not herp";
Don't hold the same thing.
I just used player1 and 2 as an example. All players are entity's and so every entity has that .herp array. You just have to find the entity for that player.
Unless I misunderstood what you meant?