다음에 추가할 기능
기프트 코드
플레이어가 선물 코드를 입력하고 교환하게 하세요.
Godot

확인할 수 있는 결과
테스트 코드가 교환됩니다. 재교환은 설정한 규칙을 따릅니다.
기프트 코드 만들기1:42
이 동영상은 영어로 재생됩니다.
동영상 별도로 열기 ↗이 단계의 동영상은 아직 없습니다. 안내와 MCP 요청은 바로 사용할 수 있습니다.
서버 플레이어 값
같은 프로젝트 준비
이 기능 구현하기
가이드는 미리 볼 수 있습니다. 실행하려면 활성 프로젝트 키가 필요합니다. 프로젝트 준비
SDK 설치와 프로젝트 설정 가져오기가 완료되고 플레이어가 로그인해야 합니다.
교환 시 서버가 설정된 값을 최대 8개 지급합니다. giftData는 별도의 게임 데이터로 유지됩니다. 반환된 잔액을 표시하고 보상을 로컬에서 다시 더하지 마세요. 이 SDK 예제는 develop을 사용합니다. 필요한 API가 설치된 SDK에 있는지 확인하세요.
GDScript를 저장하고 기본 씬의 노드에 연결해 실행하세요. Output을 확인하세요.
GDScript
1# 이 스크립트를 메인 씬의 노드에 붙이세요.
2extends Node
3
4
5func _ready() -> void:
6 # 준비: 초기화, 연결, 플레이어 로그인.
7 var connected = await Horizon.connect_to_server()
8 if not connected:
9 print("Failed to connect to horizOn server")
10 return
11 if not Horizon.auth.isSignedIn():
12 var signed_in: bool
13 if Horizon.auth.hasCachedAnonymousToken():
14 signed_in = await Horizon.auth.restoreAnonymousSession()
15 else:
16 signed_in = await Horizon.auth.signUpAnonymous("StatisticsPlayer")
17 if not signed_in:
18 return
19
20 # horizOn: 기프트 코드를 확인하고 사용하기.
21 # Run from one explicit player action; serialize this handler until it completes.
22 var user_id: String = Horizon.auth.getCurrentUser().userId
23 var project: String = Horizon.getConfig().api_key
24 var scope: String = project + "|" + user_id
25 var path: String = "user://gift_pending_" + scope.sha256_text() + ".bin"
26 var pending: Dictionary
27 if FileAccess.file_exists(path):
28 var file := FileAccess.open(path, FileAccess.READ)
29 if file == null: return
30 var saved: Variant = file.get_var(false)
31 file.close()
32 if not HorizonGiftCodes.validIntent(saved, project, user_id): return
33 pending = saved # Invalid/V1 records stay untouched for reconciliation.
34 else:
35 pending = await Horizon.giftCodes.prepareRedemption("WELCOME")
36 if not HorizonGiftCodes.validIntent(pending, project, user_id) or FileAccess.file_exists(path): return
37 var file := FileAccess.open(path, FileAccess.WRITE)
38 if file == null: return
39 file.store_var(pending, false)
40 file.flush()
41 var saved_ok: bool = file.get_error() == OK
42 file.close()
43 if not saved_ok: return
44 var verify := FileAccess.open(path, FileAccess.READ)
45 if verify == null: return
46 var original: Variant = verify.get_var(false)
47 verify.close()
48 if original != pending: return
49 var result: Dictionary = await Horizon.giftCodes.redeemPrepared(pending)
50 if not result.get("success", false): return # Keep all seven original fields for retry.
51 verify = FileAccess.open(path, FileAccess.READ)
52 if verify == null: return
53 original = verify.get_var(false)
54 verify.close()
55 if original == pending: DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
56 if result.get("playerValues") is Dictionary:
57 print(result.playerValues.values) # Current balances, never add grantedValues locally.
58 # Replay has alreadyApplied=true, giftData=null and empty grantedValues/grantedUnlocks.
새 기능을 테스트하세요.
테스트 코드가 교환됩니다. 재교환은 설정한 규칙을 따릅니다.
게임 설정과 같은 프로젝트를 대시보드에서 선택하세요.


