> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CloudScript를 통해 읽기 전용 또는 내부 플레이어 데이터 수정

> server.UpdateUserInternalData와 C# 및 JavaScript 샘플 코드를 사용하여 CloudScript에서 읽기 전용 및 내부 PlayFab 플레이어 데이터를 안전하게 업데이트합니다.

타이틀에서 필요한 경우 CloudScript에서 플레이어 데이터에 접근할 수 있습니다.

CloudScript 사용에 대한 자세한 내용은 [CloudScript 빠른 시작](/services/playfab/live-service-management/service-gateway/automation/cloudscript/quickstart)을 참조하세요.

이 문서의 C# 샘플은 Unity SDK용으로 작성되었습니다. Unity SDK는 이벤트 기반 모델을 사용하여 비동기 작업을 처리합니다. C# SDK를 사용하여 샘플 코드를 실행하려면 async Task 모델을 사용하도록 코드를 수정해야 합니다. 수정해야 하는 메서드는 시그니처의 메서드 이름 끝에 Async가 추가되어 있습니다. 예를 들어, Unity SDK의 SetObject는 C# SDK에서 SetObjectAsync가 됩니다. 자세한 내용은 [async 및 await를 사용한 비동기 프로그래밍](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/)을 참조하세요.

## CloudScript 코드 예제

CloudScript에서 서버 API 호출의 보안을 보장하도록 주의해야 합니다. 다음 코드는 CloudScript에서 읽기 전용 플레이어 데이터의 한 부분을 안전하게 수정하는 방법을 보여줍니다.

```javascript theme={null}
function IncrementReadOnlyUserData(args) {
  var playerData = server.GetUserInternalData({
        PlayFabId: currentPlayerId,
        Keys: ["ReadOnlyTest"]
  });

  var prevCount = "0";
  var nextCount = "1";
  try {
    prevCount = playerData.Data["ReadOnlyTest"].Value;
    var prevInt = parseInt(prevCount, 10);
    if (prevInt != prevInt) {
      prevInt = 0;
      nextCount = (prevInt + 1).toString();
    }
  } catch (e) {
    prevCount = "0";
    nextCount = "0";
  }

  var updateUserDataResult = server.UpdateUserInternalData({
    PlayFabId: currentPlayerId,
    Data:
        {
          "ReadOnlyTest": nextCount
        }
  });
}
```

## C# 코드 예제

CloudScript 빠른 시작에서 설명한 대로, 클라이언트에서 다음 로직을 호출할 수 있습니다.

```csharp theme={null}
public void CloudIncrement() {
    PlayFabClientAPI.ExecuteCloudScript( new ExecuteCloudScriptRequest {
        FunctionName = "IncrementReadOnlyUserData"
    },
    result => Debug.Log("CloudScript call successful"),
    error => {
        Debug.Log("CloudScript call failed");
        Debug.Log(error.GenerateErrorReport());
    });
}
```


## Related topics

- [플레이어 데이터 빠른 시작](/ko/services/playfab/player-progression/player-data/quickstart.md)
- [읽기 전용 플레이어 데이터 가져오기 방법](/ko/services/playfab/player-progression/player-data/how-to-get-read-only-player-data.md)
- [사용자 지정 CloudScript 작성](/ko/services/playfab/live-service-management/service-gateway/automation/cloudscript/writing-custom-cloudscript.md)
- [읽기 전용 플레이어 데이터 설정 방법](/ko/services/playfab/player-progression/player-data/how-to-set-read-only-player-data.md)
- [Publisher Data 사용](/ko/services/playfab/live-service-management/game-configuration/titledata/using-publisher-data.md)
