Question

I'm writing a game; rather than making a complete mess of my code I'd really like to do something like this.

This is how my code is now.

bool Verified[18] = { false }; // 18 for (18 clients in game)

Than to set that bool I'd obviously do

for(int Client;Client<18;Client++)
{
 Verified[Client] = false;
}

What I'd like to actually do is this below.

static class Clients
{
//Verified size is 18, for (18 clients max in game)
 bool Verified = the value sent by example below to client?

 //some functions i'd like to add later
}

What I want to be able to do is this below:

Clients[ClientIndex].Verified = false;
Clients[ClientIndex].SomeFunction_Call( < This param same as ClientIndex);

I don't know much c++ I know; I fail. But any help would be awesome.

Was it helpful?

Solution

First, there is no such thing as a static class in c++. remove it.

Now after you defined the class (don't forget ; at the end of the class)

class Client {
public:
   bool var;
   void func (int i);
};

You need to create an array (or vector or anything)

Client clients[10];

then, you can use it like this:

    for (int i=0; i<10; i++) {
       clients[i].var = false;
    }

Or:

    for (int i=0; i<10; i++) {
        clients[i].func (i);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top