sleepå®è£ ããã¤ãã³ããå¦ã¶ï¼ï¼ï¼ï¼ã¤ã³ã¿ã©ã¯ãã£ããªããã°ã©ã ãä½ã
ã¯ããã«
ãã¦ãã¤ãã³ãã«é¢ããé£è¼ããããã大詰ãã§ãã
ããã¾ã§å¦ãã å
容ããã«ã«ä½¿ã£ã¦ãããããã¨æä½ãã§ãããã¤ã³ã¿ã©ã¯ãã£ããªããã°ã©ã ãä½ã£ã¦ã¿ã¾ãããã
ããã¾ã§ç´¹ä»ããããã°ã©ã ã¯ãã¿ã¼ããã«ç»é¢ä¸ã§ãã¦ã¹ãã¯ãªãã¯ãããããã¼ãã¼ãå ¥åããããã¨ã§æä½ãè¡ãã¾ãããå ·ä½çã«ã¯ããã¼ãã¼ãã§ãã£ã©ã¯ã¿ã@ããåãããããã¡ãã¥ã¼ãé¸æãããããããã°ã©ã ãç´¹ä»ãã¾ããã
ã§ãããããããã°ã©ã ã使ã£ã¦ãããã¡ã«æãã¾ããã§ããï¼
ãæ¯åãå³ã¯ãªãã¯ãã¦ã¿ã¼ããã«ç»é¢ãå¼ã³åºãã®ãããã©ããããã§ããã©ï¼ï¼
ããã«ã¿ã¼ããã«ç»é¢ã¯å°ããã®ã§ãå¤é¨ã¢ãã¿ã«ãã£ã¨å¤§ãã表示ãããï¼ï¼ã
ããã§ä»åã¯ã次ã®ãããªããã°ã©ã ãç´¹ä»ãããã¨æãã¾ãã
ããã°ã©ã ã®ç´¹ä»
ã¾ãã次ã®ããã«ã³ã³ãã¥ã¼ã¿ã¨ã¢ãã¿ãè¨ç½®ãã¦ãã ããã
éè²ã®Advancedã§ã¯ãªããæ®éã®ã³ã³ãã¥ã¼ã¿ã»ã¢ãã¿ã§ãåé¡ããã¾ããã
éè²ã®Advanced Monitorã使ã£ã¦ãã ãããæ®éã®ã¢ãã¿ã¼ã§ã¯ãã¡ã§ãã
ã³ã³ãã¥ã¼ã¿ã«å¯¾ãã¦ãä¸ï¼topï¼ã¨ä¸ï¼bottomï¼ã¨å³ï¼rightï¼ã«ã¢ãã¿ã¼ãé£æ¥ãã¦ãããã¨ãéè¦ã§ããå³å´ã®ã¢ãã¿ã¯ããã¾ã§å¤§ããããªãã¦ã大ä¸å¤«ã
ããã¦ã次ã®ããã°ã©ã ãæã¡è¾¼ãã§å®è¡ãã¦ã¿ã¾ãããã
ããã°ã©ã ãå®è¡ãããã3ã¤ã®ã¢ãã¿ãã©ãã§ãè¯ãã®ã§ãå³ã¯ãªãã¯ããã¦ãã ããã
次ã®ããã«å³å´ã®å¤§ããªã¢ãã¿ã«æåã表示ããããæåã§ãã
ã¡ãã£ã¨è¦ã¥ããã§ããããã®å³ã§ã¯ãå³ã®ã¢ãã¿ã«ãmonitor_touch / right / (22, 15)ãã¨è¡¨ç¤ºããã¦ãã¾ãããã®ãrightãã®é¨åã§ãããä¸ã®ã¢ãã¿ãå³ã¯ãªãã¯ããã¨ãbottomãã¨è¡¨ç¤ºããã¾ãããä¸ã®ã¢ãã¿ã ã¨ãtopãã¨è¡¨ç¤ºããã¾ãã
ä½ãããããã°ã©ã ããããããã¾ãããã
ãã¢ãã¿ãå³ã¯ãªãã¯ãã¦çºçãã"monitor_touch"ã¤ãã³ããæ¾ãããã®å 容ã表示ããããã°ã©ã ãã§ãã
ããã°ã©ã ã®è§£èª¬
- L9 ãlocal event, side, x, y = os.pullEvent("monitor_touch")ã
ãã®é¨åããã®ããã°ã©ã ã®æéè¦ãã¤ã³ãã§ãã
"monitor_touch"ã¤ãã³ãã ããos.pullEvent()ã§æ¾ã£ã¦ãã¾ãã
ãã®ã¤ãã³ãã¯ã次ã®ãããªç¹å¾´ãæã£ã¦ãã¾ãã
monitor_touchã¤ãã³ã
- å¤é¨ã¢ãã¿ãå³ã¯ãªãã¯ããã¨çºç
- 第1è¿å¤ï¼ããã°ã©ã ä¸ã§ã¯å¤æ°eventã«ä»£å ¥ï¼ï¼ "monitor_touch"
- 第2è¿å¤ï¼åãsideï¼ï¼ãã©ã®æ¹åã«ããã¢ãã¿ãï¼"right"ã"top"ãªã©ï¼
- 第3è¿å¤ï¼åãxï¼ï¼ãã¢ãã¿ã®ã©ã®ä½ç½®ãã¯ãªãã¯ãããããã®X座æ¨ï¼æ°å¤ï¼
- 第4è¿å¤ï¼åãyï¼ï¼ãã¢ãã¿ã®ã©ã®ä½ç½®ãã¯ãªãã¯ãããããã®Y座æ¨ï¼æ°å¤ï¼
ã¤ã¾ããé£æ¥ãã¦ããã©ã®ã¢ãã¿ãã¯ãªãã¯ãããã ãã§ã¯ãªãããã®ã¢ãã¿ã®ã©ã®ä½ç½®ãã¯ãªãã¯ããããè¿ãã¦ããããã¨ã¦ã親åãªã¤ãã³ããçºçããã®ã§ãã
ãè£è¶³ãstring.format()ã«ã¤ãã¦
ããã²ã¨ã¤ãã®ããã°ã©ã ã®ãã¤ã³ãããL14ã«ããstring.format()é¢æ°ã§ãã
string.format("%s / %s / (%d, %d)", event, side, x, y)
string.format()é¢æ°ã使ã£ã¦æååãä½æãããããå³å´ã®ã¢ãã¿ã«æ¸ãè¾¼ãã§ãã¾ãã
ãã®é¢æ°ã§ãããä»ã®ããã°ã©ã è¨èªãããã£ããã¨ããã人ãªã誰ã§ãç¥ã£ã¦ããæåãªé¢æ°ã§ããã
使ãæ¹ã¯ãLuaリファレンスãè¦ã¦ãã ããã
â¦â¦ãï¼ãããã°ã©ãã³ã°åå¿è
ã«ã¯ãã®ãªãã¡ã¬ã³ã¹èªãã§ãããããªãã£ã¦ï¼
ãããåããããèªã¿ã¾ããããCè¨èªï¼ãJavaè¨èªï¼ãªã©ã®string.format()é¢æ°ã®ç¥èããããã¨åæã«æ¸ãã¦ã¾ããããåå¿è
ãå®å
¨ã«ç¡è¦ï½ãã²ã©ãï½*1
ãã®é¢æ°ã¯ã¨ã¦ãé«æ©è½ãªã®ã§ã使ãæ¹ãå
¨ã¦èª¬æããã¨ã²ã©ãé·ããªãã¾ããããã§ã¯ãä»åã®ããã°ã©ã ã§ã©ã®ããã«ä½¿ã£ã¦ãããã¨ãããã¨ã ãç°¡åã«èª¬æãã¾ãããã
ããããªã®ç¥ã£ã¦ãããï¼ãã¨ãã人ã¯ã次ã®å¤§è¦åºãã¾ã§ãèªã¿é£ã°ãæ¨å¥¨ã§ãã
string.format()ã¯ã¶ã£ã¡ããã¦è¨ãã¨ããè¤æ°ã®å¤æ°ï¼ã®å¤ï¼ãåãè¾¼ã¿ã¤ã¤æååãä½æããé¢æ°ãã§ã*2ã
string.format(第1å¼æ°, 第2å¼æ°ä»¥éã¯ããã¤ã§ãOK)ãã¨ãããµãã«è§£èªãã¦ãã ããã
第1å¼æ°ã¯ãFormatæååã§ãã表示ãããæååã¨ãã®ä¸ã®ã©ã®ä½ç½®ã«å¤æ°ãåãè¾¼ãã®ãã¨ããæ示ãè¨è¿°ããããã³ãã¬ã¼ãæååã«ãªãã¾ãã
ããã¦2çªç®ä»¥éã®å¼æ°ã¨ãã¦ããã®ãã³ãã¬ã¼ãã®ä¸ã§ä½¿ãå¤æ°ããåãè¾¼ãé çªã«ããã©ãã©ã¨ä¸¦ã¹ã¦ããã¾ãã
ãã³ãã¬ã¼ãæååã®ä¸ã«å¤æ°ãåãè¾¼ãããã«ããã®ä½ç½®ã«æ¸å¼è¨å·ãè¨è¿°ãã¾ããæ¸å¼è¨å·ã¯ããããã®ç¨®é¡ãããã®ã§ãããä»åã®ããã°ã©ã ã§ã¯ã%sãã¨ã%dãã使ã£ã¦ãã¾ãã
- %sï¼ã対å¿ããå¤æ°ãæååã¨ãã¦èªã¿åãããã®ä½ç½®ã«åãè¾¼ã
- %dï¼ã対å¿ããå¤æ°ãæ°å¤ï¼æ´æ°ï¼ã¨ãã¦èªã¿åãããã®ä½ç½®ã«åãè¾¼ã
ä»åã®ããã°ã©ã ã§ã¯ããã³ãã¬ã¼ãæååä¸ã«è¨4ã¤ã®æ¸å¼è¨å·ã使ã£ã¦ãã¾ãã
ããã¯ããããstring.format()ã®ç¬¬2以éã®å¤æ°ã§ããã第2å¼æ°ã第3å¼æ°ã第4å¼æ°ã第5å¼æ°ã«å¯¾å¿ãã¦ãã¾ããã¤ã¾ãã次ã®ãããªå¯¾å¿é¢ä¿ã§ãï¼ä¾ï¼ä¸çªç®ã®%sã¨eventã対å¿ï¼ã
"%s / %s / (%d, %d)" ^ ^ ^ ^ event side x y
ãã®ããã«æå®ãããã¨ã§ã
monitor_touch / right / (10, 10)
ã®ãããªè¡¨ç¤ºãå¯è½ã«ãã¦ããããã§ãã
ä»å¾ã¯ãã®é¢æ°ã説æãªãã§å¤ç¨ããã®ã§ã注æãã ããã
話ãæ»ãã¦ã"monitor_touch"ã¤ãã³ããã©ã使ãã®ã
ç¸å¤ãããè£è¶³ãé·ãã§ããã話ãæ»ãã¾ãã
"monitor_touch"ã¤ãã³ãã使ããã¨ã§ãå¤é¨ã¢ãã¿ã®æ¹åã®ã¿ãªããã¯ãªãã¯ããä½ç½®ï¼åº§æ¨ï¼ã¾ã§è©³ç´°ã«ãããã®ã§ãåºåè£
ç½®ã§ããã¢ãã¿ãã¾ãã§å
¥åè£
ç½®ã®ããã«åãæ±ããã¨ãã§ãã¾ãã
ã¤ã¾ããã¢ãã¿ãããã°ã©ã ã®ã³ã³ããã¼ã©ã¼ã«ãªãããã§ããã
ä¾ã¨ãã¦ã©ã®ãããªããã°ã©ã ãç´¹ä»ãããæ©ãã ã®ã§ãããå¿ç¨ç¯å²ã®åºããèãã¦æ¬¡ã®ãããªããã°ã©ã ãåãä¸ãããã¨ã«ãã¾ããã
äºå®ï¼ãã¢ãã¿ãã¿ã³ã«ããç»é¢è¡¨ç¤ºæä½ãããã°ã©ã
- ã³ã³ãã¥ã¼ã¿ã«é£æ¥ãã巨大ã¢ãã¿ã表示å°ç¨ã¢ãã¿ã¨ããã
- 表示å°ç¨ã¢ãã¿ã®ä¸å¤®ã«ãã£ã©ã¯ã¿ã@ãã表示ããã
- ã¾ãåæã«ã¢ãã¿ã®ä¸çªä¸ã«ãã©ã®ãããªæä½ããããã¨ããæ å ±ã表示ããã
- ã³ã³ãã¥ã¼ã¿ã«é£æ¥ããããã²ã¨ã¤ã®ï¼å°ããªï¼ã¢ãã¿ãã³ã³ããã¼ã«ç¨ã¢ãã¿ã¨ããã
- ã³ã³ããã¼ã«ç¨ã¢ãã¿ã®è¡¨ç¤ºé åã縦2Ã横3ã«6åå²ãã縦2Ã横3ã®è¨6åã®ãã¿ã³ãä½æããï¼ãã¡ããç©ççã«åå²ããã®ã§ã¯ãªããããã°ã©ã å ã§è¨ç®*3ãã¦è¡¨ç¤ºã¨ãªã¢ãä»®æ³çã«6åå²ããï¼ã
- ã¾ãã表示ããããã¿ã³ãå³ã¯ãªãã¯ãããã¨ã§ã表示å°ç¨ã¢ãã¿ã«è¡¨ç¤ºããã¦ãããã£ã©ã¯ã¿ã@ããä¸ä¸å·¦å³ã«èªç±ã«åããããããã£ã©ãåæä½ç½®ã«æ»ãããï¼ãªã»ããï¼ãããã°ã©ã ãã®ãã®ãçµäºï¼exitï¼ãããããã¾ãã¾ãªæä½ãã§ããã
äºå®ï¼ãã¢ãã¿ãã¿ã³ã«ããã¿ã¼ãã«æä½ãããã°ã©ã
- ã¿ã¼ãã«ã®ä¸ã«Adovanced Monitorï¼éè²ã¢ãã¿ï¼ãè¨ç½®
- ã¢ãã¿ã¯6ã¤ã®ãã¿ã³ã表示ãããã¿ã³ãæ¼ããã¨ã§çä¸ã«ããã¿ã¼ãã«ãæä½ã§ãã
- å³å転ãå·¦å転ãæ£é¢ã«åãã£ã¦turtle.dig()ãã¤ã³ãã³ããªã®é¸æã¹ããããå¤æ´ãæ£é¢ã«åãã£ã¦turtle.place()ãªã©ãå¯è½ã«ã
- ã¿ã¼ãã«ãã¢ãã¿ããé¢ããã¨æä½ãã§ããªããªãã®ã§ãturtle.forward()ãªã©ã¯å®è£ ããªã
- ãã®ããã°ã©ã ã®çºå±ç³»ã¨ãã¦ãã¯ã¤ã¤ã¬ã¹éä¿¡(rednet API)ã使ã£ãé éæä½ãªã©ãèãããã¾ããã¤ã¾ãã¯ã©ã¸ã³ã³ããã°ã©ã ã§ãï¼ï¼
- ãã®å ´åãã¿ã³6ã¤ã§ã¯è¶³ããªãããããã¾ãããã
- ã¯ã¤ã¤ã¬ã¹éä¿¡ã«ã¤ãã¦ã解説ããªãã¨ã»ã»ã»ã»ã»ã»ã
ãã®ãããªããã°ã©ã ã次å以éãç´¹ä»ãããã¨æãã¾ãã
ããã§ã¯ã楽ãã¿ã«ã
*1:ããããCCã®Luaã£ã¦ä¸è¬çãªstring.formatã®æ©è½ã®ãã¡ãä¸é¨ã®éè¦ãªæ©è½ãå®è£ ããã¦ããªãã®ã§ãããã²ã©ããã²ã©ããããããã¦å°æ°ã®æå¹æ°åæå®ãããã¯å®è£ ãã¦ãã ããããã»ãã¨ãã®ã¿ã¾ãï¼æ³£ï¼
*2:ãã£ã¨æ£ç¢ºã«è¨ããªãã°ãå¤æ°ããå å·¥ããä¸ã§ãåãè¾¼ãã®ã§ããããã®ãããã詳ãã説æããã¨ãããã¹ãã¼ã¹ããã£ã¦ã足ãã¾ããã詳ããã¯ãstring.formatãã¨ãããã¼ã¯ã¼ãã§ã°ã°ããªããã¦ãèªåã§èª¿ã¹ã¦ãã ãããã¶ã£ã¡ããç§ããæ©è½ãããããã¦ä¸é¨ã®æ©è½ãã使ãããªãã¦ãã¾ããã
*3:ãã¾ããã®è¨ç®é¨åããããã°ä¸ã ãã©ã¡ã³ãã¯ãµã¤ãï¼ï¼ï¼