View Single Post
Old 06-20-2013, 08:42 PM   #1
ddm999
worst ff player eu
 
Join Date: Jun 2012
Location: South Yorks., England
Class/Position: o - no, d - scout
Gametype: IvDZ
Posts Rated Helpful 18 Times
Boo, I suck with C++ D:

Gah.

How do I access something inside a table inside a table?

Table:
Code:
static struct classstats { int speed, weapon1, weapon2, class_maxhealth; const char *name; } classstats[]=
{
    { 1.3, 6, 0, 70, "Scout" },
    { 1, 4, 0, 80, "Sniper" },
    { 0.7, 3, 1, 120, "Soldier" },
    { 0.9, 5, 6, 90, "Demoman" },
    { 1.1, 1, 6, 90, "Medic" },
    { 0.65, 2, 1, 140, "Heavy Weapons" },
    { 1, 1, 6, 100, "Pyro" },
    { 1, 6, 0, 80, "Spy" },
    { 1, 1, 6, 80, "Engineer" },
    { 0.65, 0, 0, 70, "Civilian" }
};
Code accessing table (which doesn't work):
Code:
if(m_fortress)
{
    int wep1 = classstats[classnum[weapon1]];
    int wep2 = classstats[classnum[weapon2]];
    ammo[wep1] = (itemstats[wep1[add]]*2);
    ammo[wep2] = (itemstats[wep2[add]]*2);
    armour = 0;
    maxhealth = classstats[classnum[class_maxhealth]];
    health = maxhealth;
}
I realise I've probably thought 'hey its like lua' and it won't be, at all. Ever. Darn C++.

L:

When attempting to compile, I get:

Quote:
c:\cube 2\sauerbraten - collect edition\cube 2 fortress\src\fpsgame\game.h|456|error C2065: 'weapon1' : undeclared identifier
c:\cube 2\sauerbraten - collect edition\cube 2 fortress\src\fpsgame\game.h|457|error C2065: 'weapon2' : undeclared identifier
c:\cube 2\sauerbraten - collect edition\cube 2 fortress\src\fpsgame\game.h|458|error C2065: 'add' : undeclared identifier
c:\cube 2\sauerbraten - collect edition\cube 2 fortress\src\fpsgame\game.h|461|error C2065: 'class_maxhealth' : undeclared identifier
=== Build finished: 4 errors, 0 warnings (0 minutes, 0 seconds) ===
Still, managed to (sort of) fix my first problem, which involved me trying to use something that's defined in a file which is ran after the current file :P

I just replaced the definitions with their values.
Hence the 0-6's in the 'weapon1' and 'weapon2' slots.

Yeah, if you haven't noticed yet (you probably have), I've been trying to make a Fortress mod for Cube 2.

While teaching myself how to use C++ with it's source code.

Also, I assume this should go in the 'tech' thread, 'cause there's no other place for it :L

Damn, this post keeps getting longer.
I used the values of health and speed in FF, if you were wondering, and changed them using various formulae to be more suitable for Cube 2. L:
__________________
gg ff not ded
ff very much alive
ddm999 is offline   Reply With Quote