Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 636933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:34:07+00:00 2026-05-13T20:34:07+00:00

I have a high scores table in my game. When the game is over,

  • 0

I have a high scores table in my game. When the game is over, the score is shown on the screen and it gets inserted into the high scores table. I want to know how to compare the new score to the highest score in the table so I can let the user know if they achieved a high score. Below I included the code I use to update and insert the score into the table. The score being kept is an integer, globalScore.

-(void)updateScores:(NSInteger)Primary_key
{
    sqlite3_stmt *statement=nil;
    NSString  *sql=nil; 
    @try
    {
        statement=nil;
        sql=nil;    


        sql=[NSString stringWithFormat:@"update tblHard set Score=? where id=%d",Primary_key];


        if(sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL)!=SQLITE_OK)
        {
            NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
        }

        sqlite3_bind_int(statement, 1, globalScore);

        int success=sqlite3_step(statement);

        if (success == SQLITE_ERROR) {

            NSAssert1(0, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(database));
        }
        sqlite3_finalize(statement);
        statement=nil;
        sql=nil;
    }
    @catch (NSException *e) 
    {
        NSLog(@"asd");
    }
}

-(int)InsertGame
{
    int i=0;
    sqlite3_stmt *statement=nil;
    NSString  *sql=nil; 
    @try
    {
        statement=nil;
        sql=nil;    


        sql=[NSString stringWithFormat:@"insert into tblHard(Score) values (?)"];


        if(sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL)!=SQLITE_OK)
        {
            NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
        }

        sqlite3_bind_int(statement, 1, globalScore);

        int success=sqlite3_step(statement);

        if (success == SQLITE_ERROR) {

            NSAssert1(0, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(database));
        }
        i= sqlite3_last_insert_rowid(database);
        sqlite3_finalize(statement);
        statement=nil;
        sql=nil;
    }
    @catch (NSException *e) 
    {
        NSLog(@"asd");
    }
    return i;
}

So what I’m looking for is something like this…

if(globalScore > "the highest score in the table"){
highscorelabel.hidden=NO;
}
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:34:07+00:00Added an answer on May 13, 2026 at 8:34 pm

    You can retrieve the highest score in the table with

    select max(Score) from tblHard
    

    You can retrieve the result of this SQL query with sqlite3_column_int. Here is the code (error checking removed for brevity):

    int highestScore;
    /* ... */
    sqlite3_prepare_v2(database, "select max(Score) from tblHard", -1,
                       &statement, NULL);
    sqlite3_step(statement);
    highestScore = sqlite3_column_int(statement, 0);
    

    And then you can compare the current maximum score with globalScore:

    if (globalScore > highestScore) {
        /* ... */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL high scores table for a game that shows the daily
I have a two player game which stores scores in a table. I want
I have made a high score activity for my game. i used table row
I have a table I use for high scores of an iPhone game. As
I have the following used to create a dummy high score table if if
I have a NSMutableArray and it has the users high scores saved into it.
I have created a game where the user can upload their high score and
I have a table containing the scores of my game CREATE TABLE Scores (
I have a table which records users's scores at a game (a user may
I am trying to post a game high-score to my database table, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.