// 플레이어가 입장할 때 동작하는 함수
App.onJoinPlayer.Add(function (player) {
App.httpGet(
"https://nickname.hwanmoo.kr/?format=json&count=1&max_length=6&whitespace=_",
null,
function (res) {
// 응답 결과를 JSON 오브젝트로 변경
let response = JSON.parse(res);
player.name = response.words[0];
player.sendUpdated();
}
);
});
httpPost
앱에서 보낸 헤더와 데이터를 응답으로 받아 채팅창에 출력해보기.
// q를 눌렀을 때 실행되는 함수
App.addOnKeyDown(81, function (player) {
App.httpPost(
"https://postman-echo.com/post",
{
"test-header": "zep",
},
{
name: "zepscript",
},
(res) => {
let response = JSON.parse(res);
App.sayToAll(`보낸 헤더: ${response.headers["test-header"]}`, 0xffffff);
App.sayToAll(`보낸 데이터: ${response.form.name}`, 0xffffff);
}
);
});
참고
- 튜토리얼의 App type은 미니게임(Mini game)을 권장합니다.
- .js파일의 파일이름은 반드시 main 이어야 합니다. main.js 파일을 준비합니다.