开发者

iPhone SQLite table inconsistency

开发者 https://www.devze.com 2022-12-20 07:07 出处:网络
I have an sqlite table that shows scores from different game modes.In one of the columns, I don\'t want the score to show up unless the user reaches the 开发者_高级运维final 5th level, but I also don\

I have an sqlite table that shows scores from different game modes. In one of the columns, I don't want the score to show up unless the user reaches the 开发者_高级运维final 5th level, but I also don't want it to be recorded as a 0 either. I want it to be as if the game was never played. No score recorded at all. Here's what I have....

 if(appDelegate.easymediumhard == 2 && gameVarLevel == 5){

            if(gameVarLevel == 5){
            globalScore = timeSeconds;
            }
else if(gameVarLevel != 5){
    ????????????
    }

        }

Now I know i need the else if statement but I don't know what it should be.


The solution is to move your table write to inside the if statement. I would assume it currently comes at some point after, but I don't know because you didn't post that part.

Edit:

If your write is in a different part of your program as you say, then you either need a separate variable to track a valid score, i.e. bool scoreValid, or you need to set your score to something you know is not valid, such as -1 for instance.

Then in the code that writes the table, check if the score is valid, and only write if it is.

For instance, your code would be such:

if(appDelegate.easymediumhard == 2 && gameVarLevel == 5){

       globalScore = timeSeconds;
       scoreValid = YES;

} else {

      scoreValid = NO;

}

I am making a bunch of assumptions cause I don't know your real requirements for a valid score, but that is the idea.


don't do anything in the else. don't even have an else.

0

精彩评论

暂无评论...
验证码 换一张
取 消