about sscanf "enum" or "array"
#1

Hello guys, I have got some troubles on sscanf.
I'd +rep for you if you got any idea.
sorry my bad English.

This is my register system using Mysql system. // give thanks for BlueG.
pawn Код:
new pState[56];
    cache_get_field_content(0, "States", currentState, 1, sizeof(pState));
    // I create a string and get info from Mysql.
    // it contains info of  Float:health, Float:armour, Float:postionX, Float:postionY, Float:postionZ, interiror, world.
    // like "100.0, 100.0, 0.0, 0.0, 0.0, 0, 0";
    // Now I create a enum called pStateInfo;
    enum pStateInfo {
        Float:health,
        Float:armour,
        Float:position[3],
        interior,
        world
    }
    new pCurrentState[pStateInfo];
    // I want use sscanf for cutting this string.
    sscanf(currentState, "", pCurrentState);
    // but how I input this?
I have a easy metod.

pawn Код:
new currentState[56];
    cache_get_field_content(0, "States", currentState, 1, 56);
    enum pCurrentInfo {
        Float:health,
        Float:armour,
        Float:positionX,
        Float:positionY,
        Float:positionZ,
        interior,
        world
    }
    new pCurrentState[pCurrentInfo];
    sscanf(currentState, "p<,>e<5f2i>", pCurrentState);
Thanks for everyone who joinning this discussion.
Reply
#2

i've explained with comments

pawn Код:
//>Define a new variable that store "States" Field info into it
new pState[56];
//>Store data into "pState" Variable
cache_get_field_content(0, "States", pState,/*connectionHandle*/, sizeof(pState));
//>Your Enum :D
enum pStateInfo {
    Float:health,
    Float:armour,
    Float:position[3],
    interior,
    world
}
new pCurrentState[pStateInfo];
//now Separate Data from pState Variable into Enum Variables
sscanf(pState, "fP<,>fP<,>fP<,>fP<,>fP<,>iP<,>i", pCurrentState[health], pCurrentState[armour], pCurrentState[position[0]], pCurrentState[position[1]], pCurrentState[position[2]], pCurrentState[interior], pCurrentState[world]);
//now you finished...stored "States" field information into enum variables...
NOTE: Your information into "States" Field MUST be like this: 100.0,100.0,0.0,0.0,0.0,0,0

i mean DON't put "Space" between floats and ,
for example don't save them like this: 100.0, 100.0, 0.0, 0.0,................

if you want to save them like this you have to put a space after , between < and > in the sscanf function...
Reply
#3

Quote:
Originally Posted by M4D
Посмотреть сообщение
i've explained with comments

pawn Код:
//>Define a new variable that store "States" Field info into it
new pState[56];
//>Store data into "pState" Variable
cache_get_field_content(0, "States", pState,/*connectionHandle*/, sizeof(pState));
//>Your Enum :D
enum pStateInfo {
    Float:health,
    Float:armour,
    Float:position[3],
    interior,
    world
}
new pCurrentState[pStateInfo];
//now Separate Data from pState Variable into Enum Variables
sscanf(pState, "fP<,>fP<,>fP<,>fP<,>fP<,>iP<,>i", pCurrentState[health], pCurrentState[armour], pCurrentState[position[0]], pCurrentState[position[1]], pCurrentState[position[2]], pCurrentState[interior], pCurrentState[world]);
//now you finished...stored "States" field information into enum variables...
NOTE: Your information into "States" Field MUST be like this: 100.0,100.0,0.0,0.0,0.0,0,0

i mean DON't put "Space" between floats and ,
for example don't save them like this: 100.0, 100.0, 0.0, 0.0,................

if you want to save them like this you have to put a space after , between < and > in the sscanf function...
Yours is a very newbie version.
This method isn't used Enum.
Just like create a lot of "new".

But Thank you for reply.


+Rep
Reply
#4

pawn Код:
sscanf(pState, "e<fP<,>fP<,>fP<,>fP<,>fP<,>iP<,>i>", pCurrentState[pStateInfo]);
Reply
#5

Never store more than one value in a single column to begin with. On top of that, these variables you mention aren't even related to each other so it makes even less sense doing so.
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
Never store more than one value in a single column to begin with. On top of that, these variables you mention aren't even related to each other so it makes even less sense doing so.
Quote:
Originally Posted by ******
Посмотреть сообщение
M4D: That is not only quite a poor specifier, but also wrong.

iLuXing: "p<,>e<fffffii>" will work correctly, even for the first version of your enum - contrary to popular belief, arrays inside enums are not true arrays and can be treated as a set of flat variables:

pawn Код:
enum pStateInfo {
        Float:health,
        Float:armour,
        Float:position[3],
        interior,
        world
}
Is equivalent to:

pawn Код:
enum pStateInfo {
        Float:health,
        Float:armour,
        Float:position,
        interior = 5,
        world
}
The specifier you posted will (if I ever finish) work in the future, but IIRC that's only in the upcoming sscanf 3, not in the current sscanf 2 (and the major missing feature in v3 is enums currently).

Having said all that, Vince is right. This code is trying to poorly replicate the functionality of databases, which are already VERY good at storing multiple pieces of independent data. Don't second guess SQL!
Sorry, but I think : if I store those data at the same time, and I only loaded it on player spawned.
I think this method with sscanf is faster a little.

Should I store those in every single column ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)