본문 바로가기

마인크래프트(Minecraft)/Computer Craft

[Computer Craft] 15. <응용기술> 채팅 인식 문


본 강좌는 컴퓨터크래프트 애드온 모드인 MiscPeripherals 가 설치되어 있어야 사용할 수 있습니다.
모드 자료 : MiscPeripherals


0. 개요


그동안 플로피 디스크를 가지고 다니거나 컴퓨터 안에서 직접 제어를 해야하니 이만저만 불편한게 아니였습니다.

그러나 컴퓨터크래프트 애드온 모드인 MiscPeripherals 가 추가됨으로써 채팅으로 문을 열고 닫고 하게 가능해졌죠.

Chat Box 라는아이템을 사용한 채팅으로 제어하는것을 알아보도록 해요.



1. Chat Box 조합법



금4개, 노트블럭4개, 다이아몬드1개 들어갑니다. 꽤나 비싸네요.



2. 주석소스



chatbox = peripheral.wrap('left') -- Chat Box 가 있는 쪽을 연결 시켜준다.

while true do
  event, user, message = os.pullEvent() -- 이벤트를 변수로 받아준다.
  if event == 'chat' then -- 채팅시 : event 에는 chat 값이 넘어온다.
    if user == 'iruril' then -- 받아줄 유저를 지정한다. 이 조건문을 빼면 누구나 쓸 수 있다.
      if message == 'open' then -- 채팅메시지를 비교 open 을 입력시 레드스톤 신호 방출
        redstone.setOutput('bottom',true)
      elseif message == 'close' then -- 채팅메시지를 비교 close 를 입력시 레드스톤 신호 제거
        redstone.setOutput('bottom',false)
      end
    end
  end

  os.sleep(0.05)
end



3. 복붙용소스


chatbox = peripheral.wrap('left')

while true do
  event, user, message = os.pullEvent()
  if event == 'chat' then
    if user == 'iruril' then
      if message == 'open' then
        redstone.setOutput('bottom',true)
      elseif message == 'close' then
        redstone.setOutput('bottom',false)
      end
    end
  end

  os.sleep(0.05)
end



4. 주의할 점

본 소스는 딜레이인 os.sleep() 함수가 없기 때문에

대량 설치하면 엄청난 렉을 주거나 서버에 부담을 줄 수 있습니다.

굳이 딜레이를 주고자 하면 0.05초를 딜레이를 주면 어느정도 부담은 줄일 수 있습니다.


2013년 9월 4일 오후5시47분 추가 작성

os.sleep() 함수추가와

chatbox = peripheral.wrap('left') 함수 위치를 조율했습니다.



5. 시연영상