2015-12-09 03:32:08

Alright, so currently I'm working on getting account code set up for my game.
However I'm having an issue coming up with a way for my server to call my account class and assign that account with a unique name. The following piece of code might explain my predicament better.
string accountname="john";
class account
{
//account code goes here.
}
void maine()
{
account accountname;
}
For the idea I have to work, accountname needs to be seen as a variable, rather than an actual name. The result I want from the above code is to end up with an account class called john if that isn't clear. I haven't tried implementing this idea into my code yet because I'm almost certain it will fail. I think I might be able to use it as a handle like so though.

string accountname;
class account
{
//account code goes here.
}
void maine()
{
account @accountname;
}

However, I'm not too familiar with using handles, so again I'm almost certain this won't work.
If anybody has any suggestions on how to make this work, I'd appreciate it.
Thanks.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-12-09 06:01:59

Do you want instances of the account class to be assigned, or mapped to strings? For example, john is mapped to an account object, victorious to another?

The solution that comes to mind is to use the dictionary object, which is a hash table that allows you to associate objects of arbitrary type to string keys. For example,
dictionary accounts;
Account johnsAccount;
accounts.set("john", johnsAccount);

Then you can check for whether such an account exists with accounts.exists("john") and retrieve John's account if it exists.

Note that keys may only be associated with 1 item per dictionary.

2015-12-09 09:58:45

It might be helpful down the road, but not what I'm trying to figure out right now. I need the client to be able to send a packet of information to the server, the server will parse that information out into account name and password, then use that account name and password to create an instance of the account class. I can pass the password off as an argument in the constructor, but I don't know how to make the actual handle vary with each new packet.
This is what I want to happen.
//client code
void ClientCreateAccount()
{
//send a username and password to the server with the word createaccount in front of them.
}
//server code
void main()
{
do
{
if(network.type=="receive&&network.message contains "createaccount")
{
//parse out the packet for the username and password into variables called username and password respectively.
account username(password);
}
while(!key_pressed(KEY_ESCAPE);
}

This is just suto code, I know I'm missing some stuff in the above code, but should be enough to give you a better idea of what I'm trying to do.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-12-09 10:21:18

you would have to do something like
class account {
void create(string username, string password) {
//create account here
}
}
account@[] allAccounts;
void main () {
//check if the received packet has create account in it, and if it does, then
}accounts.insert_last(account);
accounts[accounts.length()-1].create(username,password);

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

2015-12-09 11:16:00

Think you could walk me step by step in that keyIsFull?
I'm not able to really follow that without some explination.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-12-09 12:00:44

class account {
void create(string username, string password) { //this method from the server creates the account with the username and pw.
//create account here
}
}
account@[] allAccounts; //an array of account object handles. This array stores any newly created accounts as well as any accounts you would load if someone had logged in.
void main () {
//check if the received packet has create account in it, and if it does, then
}accounts.insert_last(account); //creates a new account object in the accounts array.
accounts[accounts.length()-1].create(username,password); //initializes the account in the last array slot with the user name and password that you parsed from the network request.
}
note: you can't make variables out of the strings you parsed from the network request, because that's just not how it works. A variable name is just arbitrary. That's why you have to create an array of account objects. plus, once you have like 400 accounts, managing each one by its name would suck anyway. You could create a function that returns an account object so that you could more easily deal with them though, something like
account@ get_account(string username) {
for(uint x=0; x<accounts.length(); x++) {
if(accounts[x].username==username) return accounts[x];}
}
return null;
}

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

2015-12-09 13:14:02

Alright, I think I understand now. I'll have to experiment with it and see if I run in to any other issues. Thanks for the help.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-12-09 15:04:59

So I've gone through and worked it all out in my head and I believe this solves my problems just fine. The only thing I'm having a hard time deciding is if I want to put my movement code, weapon code, and collision code  in the account class, or if I want to have the functions run forloops with the accounts. From my understanding this problem pretty much equates to deciding if you should write 2+3=5 or 3+2=5. Is there a factor that I'm just not thinking of that would determine which direction I should go with this?

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-12-09 19:18:44

I would probably put movement and firing code in the account class. I'm not even sure why you would do it the other way.

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

2015-12-10 15:17:04

Alright. So I have my create account code working. Now I've just got to figure out how to save these accounts and load them later. I know I have to serialize everything, but I'm having a difficult time understanding the process describe in the help files. Maybe I'll have better luck if someone explained it to me.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.

2015-12-10 18:01:28

NVM, I've figured it out.

The universe is a rain storm. We are droplets sent to quench the problems of the world, yet we are blown sideways by the winds of distractions.