Using Bbruntimesetjssettingsvalue() From Ios

Discussion in 'Technical Discussion' started by adrianjgomez, Oct 13, 2022.

  1. adrianjgomez

    adrianjgomez Boxer

    Joined:
    Apr 1, 2016
    Messages:
    65
    Likes Received:
    45
    Dylan B sent a ticket asking me how do I use SetJsSettingsValue in iOS.

    So although I tried to use that function, I never got it to work. It would always return an error. Luckily there is another way around it you can use executeScript() function to set the value:

    A simple example where the value is pre-known:
    Code:
    std::string returnToMenu = "Settings['returnToMenu'] = true";
    bbshared->executeScript(returnToMenu);
    
    One where I construct it from data coming in from a service call. There is probably a way to streamline this, but this is what I currently have:
    Code:
                std::string best_score_lifetime_st = "Settings['bestScore'] = ";
    
                best_score_lifetime_st += [[[NSNumbernumberWithInt:best_score_lifetime] stringValue] cStringUsingEncoding:NSUTF8StringEncoding ];
    
                best_score_lifetime_st += [@";" cStringUsingEncoding:NSUTF8StringEncoding ];
    
                bbshared->executeScript(best_score_lifetime_st);
    
    I did not have a problem with the get settings function. That one works as expected, although you must convert it back to the type you want since it all comes back as a std string:

    Code:
    std::string finalScore = bbshared->getJsSettingsValue("gameScore");
    
        NSString *finalScoreNSString = [NSString stringWithUTF8String:finalScore.c_str()];
    
        NSNumber *finalScoreNSNumber = [NSNumber numberWithInteger:[finalScoreNSString integerValue]];
    
     

Share This Page