arrays in quake?
Moderator: InsideQC Admins
15 posts
• Page 1 of 1
arrays in quake?
from my knowledge this is how your write normal arrays.
is it the same in quake? and can quake use two-dimensional arrays?
if not how do you use arrays in quake? (darkplaces?)
- Code: Select all
islot[0] ="";
islot[1] =x;
eslot[0] ="";
eslot[1] =x;
stat[0] =x;
is it the same in quake? and can quake use two-dimensional arrays?
- Code: Select all
islot[i,0] ="";
islot[i,1] =x;
if not how do you use arrays in quake? (darkplaces?)
-

ceriux - Posts: 2223
- Joined: Sat Sep 06, 2008 3:30 pm
- Location: Indiana, USA
Re: arrays in quake?
Good questions. BTW, what would be an example useage for arrays in QC?
-

Cobalt - Posts: 445
- Joined: Wed Jun 10, 2009 2:58 am
- Location: New England, USA
Re: arrays in quake?
Cobalt wrote:Good questions. BTW, what would be an example useage for arrays in QC?
i think the examples i posted is how they're written . however i may be wrong, that's why i'm asking?
-

ceriux - Posts: 2223
- Joined: Sat Sep 06, 2008 3:30 pm
- Location: Indiana, USA
Re: arrays in quake?
See this FTEQW page:
http://fteqw.com/wiki/index.php?title=FTEQCC_FAQ
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.
http://fteqw.com/wiki/index.php?title=FTEQCC_FAQ
- Code: Select all
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 ..
-

Baker - Posts: 3666
- Joined: Tue Mar 14, 2006 5:15 am
Re: arrays in quake?
Can't you test then and see?
I remember reading something about having to wrap them in round brackets in FTEQCC.
I remember reading something about having to wrap them in round brackets in FTEQCC.
-

Arkage - Posts: 66
- Joined: Thu Nov 19, 2009 4:17 pm
Re: arrays in quake?
Cobalt wrote:Good questions. BTW, what would be an example useage for arrays in QC?
Here's an example of an array in (FTEQW) QuakeC:
viewtopic.php?f=2&t=4251&hilit=payload
While the 'payload' code has (major) flaws, I believe the actual array part of the code is correct, and (IIRC) worked!
- OneManClan
- Posts: 243
- Joined: Sat Feb 28, 2009 2:38 pm
Re: arrays in quake?
Yes it worked. But it didnt do so well with huge functions and stuff like that.
- Jukki
- Posts: 214
- Joined: Wed Apr 07, 2010 4:59 am
Re: arrays in quake?
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).
.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).
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
Re: arrays in quake?
example
- Code: Select all
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;
- r00k
- Posts: 1110
- Joined: Sat Nov 13, 2004 10:39 pm
Re: arrays in quake?
Good example !
Darn, Darkplaces dont like : entity dm_spawns [16];
guess it wont work for an idea I had.
[quote="r00k"]example
[code]
Darn, Darkplaces dont like : entity dm_spawns [16];
guess it wont work for an idea I had.
[quote="r00k"]example
[code]
-

Cobalt - Posts: 445
- Joined: Wed Jun 10, 2009 2:58 am
- Location: New England, USA
Re: arrays in quake?
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?
-

ceriux - Posts: 2223
- Joined: Sat Sep 06, 2008 3:30 pm
- Location: Indiana, USA
Re: arrays in quake?
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 ..
-

Baker - Posts: 3666
- Joined: Tue Mar 14, 2006 5:15 am
Re: arrays in quake?
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.
-

Arkage - Posts: 66
- Joined: Thu Nov 19, 2009 4:17 pm
Re: arrays in quake?
right, but you can't really define player1,player2. it's simply player. unless the engine would handle the difference between players?
baker: so this is how darkplaces would use arrays? e.inv_6_4 = val;
baker: so this is how darkplaces would use arrays? e.inv_6_4 = val;
-

ceriux - Posts: 2223
- Joined: Sat Sep 06, 2008 3:30 pm
- Location: Indiana, USA
Re: arrays in quake?
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?
Unless I misunderstood what you meant?
-

Arkage - Posts: 66
- Joined: Thu Nov 19, 2009 4:17 pm
15 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest