코드 샘플 #
이 페이지는 Lua 런타임을 사용하여 프로젝트를 개발할 때 템플릿으로 사용할 수 있는 기능에 대한 공통적인 예시를 제공합니다.
대결 핸들러 #
대결 핸들러는 권한 보유 멀티플레이어 대결에 대한 게임 입력과 운영을 처리하기 위한 서버 측 함수를 모두 표시합니다. 대결 핸들러 API 및 대결 런타임 API 참조 페이지에서 대결 핸들러 기능을 살펴봅니다.
이것은 탁구 대결 핸들러에 대한 예시입니다. 서버에 수신된 메시지는 메시지를 발송한 사람한테 다시 전달됩니다.
|
|
컨텍스트 #
|
|
데이터베이스 핸들러 #
이 예시는 클라이언트에서 사용할 수 없는 시스템 ID를 생성하고 사용자 지정 SQL 쿼리는 이 ID를 users
테이블로 입력합니다.
|
|
RPC #
아래의 예시는 custom_rpc_func_id
식별자를 사용하여 함수를 등록합니다. 클라이언트 코드 내에서 ID를 사용하여 RPC 메시지를 전송하고, 서버에서 함수를 실행하여 결과를 반환합니다.
|
|
사전 후크 #
아래의 코드 예시는 현재 사용자의 프로필을 가져와서 "{level: 12}"
(으)로 인코딩된 JSON으로 추정되는 메타데이터를 확인합니다. 사용자의 수준이 낮은 경우, 오류가 발생하여 친구 추가 메시지가 서버에서 전달되지 않도록 합니다:
|
|
사후 후크 #
아래의 예시 코드는 사용자가 친구를 추가할 때 사용자의 저장소에 레코드를 작성합니다. 함수에서 반환되는 모든 데이터는 삭제됩니다.
|
|
예시 모듈 #
예시로 Pokéapi를 사용하여 “pokeapi.lua"라고 하는 모듈을 만들어보겠습니다.
|
|
이제 클라이언트에서 Pokémon에 대한 RPC 호출을 생성할 수 있습니다:
Client
|
|
Client
|
|
Client
|
|
Client
|
|
Client
|
|
Client
|
|
Client
|
|
Code snippet for this language Defold has not been found. Please choose another language to show equivalent examples.