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

  • Home
  • SEARCH
  • 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 8788465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:09:00+00:00 2026-06-13T22:09:00+00:00

I am creating a game in Unity3d using the GREE c# API. I am

  • 0

I am creating a game in Unity3d using the GREE c# API.
I am trying to get run an Action for every (username, score) in a leader board.

The code is the following:

public static void LoadBestScoreFromFriends(Action<FriendAndScore> onComplete)
{
    Gree.Leaderboard.LoadScores(LEADERBOARD_ID,
        UnityEngine.SocialPlatforms.UserScope.FriendsOnly,
        UnityEngine.SocialPlatforms.TimeScope.AllTime,
        1,
        100,
        (IScore[] scores) => {

        foreach (IScore iscore in scores)
        {
            // Since the username is needed, a second
            // call to the API must be done
            Gree.User.LoadUser(iscore.userID, 
            (Gree.User guser) => {
                FriendAndScore friend = new FriendAndScore();
                friend.Name = guser.nickname;
                friend.Score = "" + iscore.value;

                // Run the action for every (nickname, score value)
                onComplete(friend);
            }, (string error) => {
                Debug.Log("Couldn't fetch friend! error: " + error);
            });
        }
    });
}

The problem here is that the iscore.value it’s always the same. It’s the last element of the foreach. This make sense because the LoadUser() finishes after the foreach ends its loop.

I thought of creating a second method to do the call there. Something like:

private void GetTheUserAndCallTheAction(Action<FriendAndScore> onComplete, string userID, string score)
{
    Gree.User.LoadUser(userID, 
            (Gree.User guser) => {
                FriendAndScore friend = new FriendAndScore();
                friend.Name = guser.nickname;
                friend.Score = score;
                onComplete(friend);
            }, (string error) => {
                Debug.Log("Couldn't fetch friend! error: " + error);
            });
}

Since I am a C# newbie I wanted to know if there is a better way of handling this.

  • 1 1 Answer
  • 0 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-06-13T22:09:03+00:00Added an answer on June 13, 2026 at 10:09 pm

    By design – this is how capture works when constructing lambda expression in foreach loop and executing this lambda later.

    Fix – declare local copy of IScore iscore:

    foreach (IScore eachScore in scores)
    {
       IScore iscore = eachScore;
    

    And Closing over the loop variable… by Eric Lippert details the behavior and related issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a game engine using wxWidgets and OpenGL. I'm trying to set up
Im creating a game an want to be able to add there score so
I'm creating a game in ActionScript 3.0 using the FlashPunk game engine and the
I'm creating a game in Java for fun and I'm trying to decide how
I'm creating a game for the iPad using Phonegap, which means I'm using JavaScript/
I am starting with game dev using Unity3d and I can see there's 3
I am creating a game using a 10x10 2D array. The player starts at
I am creating a game similar to Pokemon and right now I'm trying to
I'm creating c++ game server. The server creates many objects monster , and every
I am creating a game web site using PHP and I want to just

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.