Raised This Month: $51 Target: $400
 12% 

What's the best way to store this kind of data in the sql...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Matheus28
Senior Member
Join Date: Aug 2009
Old 11-02-2010 , 20:49   What's the best way to store this kind of data in the sql...
Reply With Quote #1

Well, I have several "Unlocks", each one with an id string.
They all have only two states: unlocked (true) or locked (false).

What would be the best way to store a client unlocks in the database?
Generating a keyvalue string?
Making a simple text parser? (aaaa=1;bbbb=0;cccc=1;)
Matheus28 is offline
r00tage
Senior Member
Join Date: Nov 2008
Old 11-02-2010 , 21:00   Re: What's the best way to store this kind of data in the sql...
Reply With Quote #2

Well, what I would say is if you are intending to do unlockables like RPG, you would implement it like this.

Quote:
table name | field (int usually)
--------------------------------------------
icestab | [5000] points allocated
jump | [3000] points allocated
Then in your code, you just read the value of field and do an if else statement.

if (jumpxp > 2000)
//Player is level 2
else if(jumpxp > 1000)
//Player is level 1
else
//Level 0 how lame

Otherwise, a nifty boolean table would probably be enough for 1 time unlockables.
r00tage is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 11-02-2010 , 21:09   Re: What's the best way to store this kind of data in the sql...
Reply With Quote #3

Why not bit flags?
Code:
#define Unlock1 (1<<0) //1
#define Unlock2 (1<<1) //2
#define Unlock3 (1<<2) //4

new flags = 0;

flags |= Unlock1; //Adds Unlock1 flag
flags &= ~Unlock1; //Removes Unlock1 flag

new bool:HasUnlock1 = flags & Unlock1;
This way you have a simple interger and the limit is 32 (1<<31) and if you need more you can always make a 2nd integer.
Sammy-ROCK! is offline
Matheus28
Senior Member
Join Date: Aug 2009
Old 11-02-2010 , 21:22   Re: What's the best way to store this kind of data in the sql...
Reply With Quote #4

Quote:
Originally Posted by Sammy-ROCK! View Post
Why not bit flags?
Code:
#define Unlock1 (1<<0) //1
#define Unlock2 (1<<1) //2
#define Unlock3 (1<<2) //4

new flags = 0;

flags |= Unlock1; //Adds Unlock1 flag
flags &= ~Unlock1; //Removes Unlock1 flag

new bool:HasUnlock1 = flags & Unlock1;
This way you have a simple interger and the limit is 32 (1<<31) and if you need more you can always make a 2nd integer.
Because I wanna support more than 200 unlocks, and I don't know how much I'll need to support, so I can't rely on it.

Also, unlocks aren't based on an exp level, the user chooses which one he wants to buy, he can buy more than one.

I am inclined to use the simple text parsing

Last edited by Matheus28; 11-02-2010 at 21:26.
Matheus28 is offline
Matheus28
Senior Member
Join Date: Aug 2009
Old 11-02-2010 , 22:28   Re: What's the best way to store this kind of data in the sql...
Reply With Quote #5

Okay, I did it using a "simple text parser".

I just exploded the string on the ";" and then on the "=".
Matheus28 is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 11-03-2010 , 10:56   Re: What's the best way to store this kind of data in the sql...
Reply With Quote #6

You can store unlocks in a file or MySQL as very large bitstring.
__________________
FaTony is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode