0

I want to upload a few stats in an database, how can I take something out of an callback and put it in an variable to simplify this?

Code:

csgo.requestPlayersProfile(account_id, function(ranking) {
                console.log(ranking);
            });

Result (ranking):

Got handled GC message PlayersProfile
{ my_current_event_teams: [],
  my_current_event_stages: [],
  account_id: xxxxxxx,
  ongoingmatch: null,
  global_stats: null,
  penalty_seconds: null,
  penalty_reason: null,
  vac_banned: null,
  ranking:
   { account_id: xxxxxxx,
     rank_id: 16,
     wins: 1081,
     rank_change: null },
  commendation: { cmd_friendly: 23, cmd_teaching: 24, cmd_leader: 24 },
  medals:
   { display_items_defidx:
      [ 969, 4551, 1377, 970, 1358, 4354, 1340, 1338, 1331, 1329, 1030, 874 ],
     medal_team: null,
     medal_combat: null,
     medal_weapon: null,
     medal_global: null,
     medal_arms: null,
     featured_display_item_defidx: 969 },
  my_current_event: null,
  my_current_team: null,
  survey_vote: null,
  activity: null,
  player_level: 19,
  player_cur_xp: 327682724,
  player_xp_bonus_flags: null }

So as an example I want to put the rank_id: 16 in an var (ex. var rank = 16;) so I cant just use "UPDATE Users SET Rank='rank'"

Schmaniel
  • 105
  • 7
  • 1
    I think the way you ask this question is not very clear. However, from your callback you should be able to access the part of the data you need as `ranking.ranking.rank_id`. – Leandro Jan 24 '20 at 15:50
  • Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Antoine Jan 24 '20 at 15:54

2 Answers2

1
var rank = ranking.ranking.rank_id;
SherylHohman
  • 16,580
  • 17
  • 88
  • 94
  • Thats actually so simple, but still don't make sense to me... Why do I need 2x ranking? //Edit: nvm, got it... – Schmaniel Jan 24 '20 at 16:03
0

You are passing callback function to this requestPlayersProfile, so everything you need is just to call db from that "doSomething" function. All data you need will be in "ranking" variable.

function doSomething(ranking) {
  // do everything you want with that data here
}

csgo.requestPlayersProfile(account_id, doSomething);
Harion
  • 225
  • 1
  • 8