06.07.2012, 19:27
(
Последний раз редактировалось Snip3d; 06.07.2012 в 20:20.
)
Hello, I'm having a hell of a time with SQLite. Here's my code for saving stats.
When szQuery outputs everything looks like it works, my database just doesn't change.
also here's my code for getting the stats from the database which works, just adding it to help you guys debug.
and I set the score like this onPlayerSpawn
EDIT: I got it saving but whenever I connect my score gets set to 49 even though in the database it's 10? any ideas
EDIT2: Wow, strval is actually really helpful. I fixed it by converting my string to an int for SetPlayerScore. Was that the correct solution?
Код:
forward saveStats(playerid); public saveStats(playerid) { new szQuery[109], szPlayerName[MAX_PLAYER_NAME]; GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME); format(szQuery, sizeof(szQuery), "UPDATE `users` SET `score` = '%i' WHERE `username` = '%s' collate nocase", GetPlayerScore(playerid), szPlayerName); db_query(USERDB, szQuery); SendClientMessageToAll(COLOR_WHITE, "Stats Saved"); print("Score saved"); print("on name"); print(szPlayerName); print("using query"); print(szQuery); db_free_result(db_query(USERDB, szQuery)); db_close(USERDB); return 1; }
also here's my code for getting the stats from the database which works, just adding it to help you guys debug.
Код:
public checkStatsFromDB(playerid) { new szQuery[74], DBResult: query, szzPlayerName[25]; USERDB = db_open("serverDB.db"); GetPlayerName(playerid, szzPlayerName, 25); //ouput to szQuery -- Max Length is the size of szQuery which is 74 -- Formart String -- format(szQuery, sizeof(szQuery), "select * from `Users` where `username` = '%s' collate nocase", szzPlayerName); // DB: serverDB, Query to perform. query = db_query(USERDB, szQuery); if(db_num_rows(query) > 0) { print("Account already registered while looking up stats."); db_get_field_assoc(query, "score", pScore[playerid], sizeof(pScore)); print("Found Score"); print(pScore); db_get_field_assoc(query, "skin", pSkin[playerid], sizeof(pSkin)); print("Found Skin"); print(pSkin); db_free_result(query); } if (db_num_rows(query) == 0) { print("[ERROR] Account not registered while looking up stats."); }
Код:
new pScore[MAX_PLAYERS]; //Score at the top of my script SetPlayerScore(playerid, pScore[playerid]);
EDIT2: Wow, strval is actually really helpful. I fixed it by converting my string to an int for SetPlayerScore. Was that the correct solution?