ComputerCraftã®ç¡ç·éä¿¡ã使ãããªãã(4)ãâç¡ç·ã§ã¿ã¼ãã«ãé éæä½
ã¯ããã«
ååã¯ãç¡ç·ã§ã¡ãã»ã¼ã¸ï¼æååï¼ãéä¿¡ï¼åä¿¡ããããã°ã©ã ãç´¹ä»ãã¾ããã
ä»åã¯ãã®ããã°ã©ã ãä¿®æ£ãã¦ãã¿ã¼ãã«ãé éæä½ããããã°ã©ã ã«ä½ãå¤ãã¦ã¿ã¾ãããã
以ä¸ã®ç»åã®ããã«ãWireless Modemãã¤ããã³ã³ãã¥ã¼ã¿ã¨ã¯ã¤ã¤ã¬ã¹ã¿ã¼ãã«ï¼Wireles Turtle)ãç¨æãã¦ãã ããã ä»åã¯ãã³ã³ãã¥ã¼ã¿ï¼ç»åä¸ãéè²ã®Advanced Computerï¼ãå½ä»¤ã¡ãã»ã¼ã¸ãéä¿¡ããã³ã³ããã¼ã©å´ãã¿ã¼ãã«ãå½ä»¤ã¡ãã»ã¼ã¸ãåä¿¡ããå´ã¨ãªãã¾ãã
ã¡ãã»ã¼ã¸éä¿¡ï¼ã³ã³ããã¼ã©å´ï¼ããã°ã©ã
ã¡ãã»ã¼ã¸éä¿¡ããã°ã©ã ã¯ãååã®éä¿¡ããã°ã©ã ããã®ã¾ã¾ä½¿ãã¾ãã
ã¡ãã»ã¼ã¸åä¿¡ï¼ã¿ã¼ãã«å´ï¼ããã°ã©ã ããã¼ã¸ã§ã³2
ååã®åä¿¡ããã°ã©ã ï¼ãã¼ã¸ã§ã³1ï¼ã«ãL9-11ã®ãããª3è¡ãå ãã¾ããã
å®ã¯ãã®ããã°ã©ã ãL9ã®loadstring(message)()
ãä»ãå ããã ãã§ããã¾ãã¾ããï¼è¨ãæããã¨ãL9ã¨L10-11ã¯åããã¨ããã£ã¦ãããL9ã®ã³ã¡ã³ãã¢ã¦ãè¨å·ãã¯ããã¦ãL10-11ãã³ã¡ã³ãã¢ã¦ããã¦ããã¾ãã¾ããï¼ã
L9ã®è¨æ³ã¯ãããã¥ããã¨æã£ãã®ã§ãL10-11ã®ããã«ããåãããããå½¢ã«å解ãã¦ã¿ã¾ããã
ã¾ãããã§ä½¿ã£ã¦ããloadstring()é¢æ°ã«ã¤ãã¦èª¬æãã¾ãããï¼æ£ç¢ºãªæ å ±ã¯Lua5.1ãªãã¡ã¬ã³ã¹ããã¥ã¢ã«ãã©ããï¼ã
- loadstring(æåå)
- å¼æ°ã¨ãã¦ä¸ããæååãé¢æ°ã¨ãã¦è§£éãã¦ç¡åé¢æ°ãä½æï¼ã³ã³ãã¤ã«ï¼ãã¾ããããã¦ãã®ç¡åé¢æ°ãè¿å¤ã¨ãã¾ãã
- ä¾ãã°åä¿¡ããã¡ãã»ã¼ã¸(message)ãã"turtle.up()"ã¨ããæååã ã¨ããã¨ããã®æååã解éãã¦ã
turtle.up()
ãå®è¡ãã¦ãããæ°ããç¡åé¢æ°ãä½æãã¾ãã
- ã¾ããç¡åé¢æ°ã®æ«å°¾ã«
()
ãå ãããã¨ã§ããã®ç¡åé¢æ°ãå®è¡ãã¾ãã
ãã®ä¸é£ã®æµããããããããããããã«å解ããã®ãL10-11ã®è¨è¿°ã«ãªãã¾ãã
- L10:
local func = loadstring(message)
loadstring(message)
ã«ãã£ã¦ä½æãããç¡åé¢æ°ããå¤æ°func
ã«ä»£å ¥
- L11:
func()
- ç¡åé¢æ°ã®æ«å°¾ã«
()
ãå ãããã¨ã§ãå¼æ°ãªãã§ãã®ç¡åé¢æ°ãå®è¡ã
- ç¡åé¢æ°ã®æ«å°¾ã«
ãç¡åé¢æ°ã£ã¦ä½ï¼ãããªãã§ãããªãã¨ãã§ããã®ï¼ãã¨è©³ããä»çµã¿ã«èå³ãæã£ãæ¹ã¯ã以ä¸ã®è¨äºã§è©³ãã解説ãã¦ããã®ã§ã覧ãã ãããä¸è¨ã§ããã¨ãLuaã®ä¾¿å©ãªä»æ§ãã§ãï½
ããã°ã©ã ãå®è¡ãã¦ã¿ãã
- åä¿¡å´ï¼ã¿ã¼ãã«å´ï¼ããã°ã©ã ãå®è¡ããâãã¿ã¼ãã«ã¯ãã®ã¾ã¾ã¡ãã»ã¼ã¸å¾ ã¡ç¶æ ã¸ã
- éä¿¡å´ï¼ã³ã³ããã¼ã©å´ï¼ããã°ã©ã ã§ã以ä¸ã®ããã«ããã°ã©ã ãå®è¡ã
msg_sender turtle.turnRight() 30
ã»ã»ã»ID30ã®ã¿ã¼ãã«ã«ã¡ãã»ã¼ã¸"turtle.turnRight()"ãéä¿¡ã
æåå"turtle.turnRight()"ãåä¿¡ããã¿ã¼ãã«ã¯ããããé¢æ°turtle.turnRight()
ã¨è§£éãã¦ãå³ãåãã¯ãã§ãã
以ä¸ã¯ä¸ä¾ã§ãããã¿ã¼ãã«ãæä½ããé¢æ°ã¯ä»ã«ãããããããã¾ãï¼Turtle (API) - ComputerCraft Wikiï¼ã ãããããªå½ä»¤ãå ¥åã»éä¿¡ãã¦éãã§ã¿ã¾ãããã
turtle.forward()
ãturtle.back()
ãã»ã»ã»åï¼å¾ã¸ç§»åï¼çæãå¿ è¦ï¼turtle.up()
ãturtle.down()
ãã»ã»ã»ä¸ï¼ä¸ã¸ç§»åï¼çæãå¿ è¦ï¼turtle.turnRight()
ãturtle.turnLeft()
ãã»ã»ã»90度å³ãåãï¼90度左ãåãï¼çæã®å¿ è¦ãªãï¼
ãã®ããã°ã©ã ã®åé¡ç¹
ãã¦ãéãã§ãããã¡ã«ãé¢åãªãã¨ãèµ·ãã¾ããã§ããï¼
- "turtle.turnRight()"ãã¨æã¡è¾¼ãã¤ãããééãã¦ã"turtle.turnRihgt()"ãã¨ã¤ã¥ããééãã¦å½ä»¤ãã¡ãã£ãï¼
- åä¿¡å´ã®ã¿ã¼ãã«ããã°ã©ã ã¯ãã¨ã©ã¼ãçããã®ã§ããã°ã©ã å¼·å¶çµäºï½ï½ï½ï½
ããããããã¾ãåä¿¡å´ã®ããã°ã©ã ãå®è¡ããªãããããããï½ï¼ã
ãããªãã§ããloadstring(æåå)é¢æ°ãå®è¡ããã¨ãã«ã誤ã£ãæååãä¸ãã¦ãã¾ãã¨ããnilãå¼ã³ã ããã¨ãã¦ããï¼ã ããããããªé¢æ°ä½ããªããï¼ï¼ã¨ã¨ã©ã¼ãçºçãã¦å¼·å¶çã«ããã°ã©ã ãåæ¢ããã¦ãã¾ãã®ã§ãã
åææ¦ããããã°ãã¾ãã¿ã¼ãã«å´ã§å¾ ã¡ããããã°ã©ã ãèµ·åããªãããªãã¨ããã¾ãããã¤ã¾ãæåå ¥åã失æã§ããªãã®ã§ããããã¯ã¤ããã
å°ãã¾ãããã¨ã©ã¼ãçãã¦ããããããªã ãã¦ãããã°ã©ã ããã®ã¾ã¾å®è¡ãã¤ã¥ãããã¨ã¯ã§ããªãã®ã§ããããã
ã¡ãã»ã¼ã¸åä¿¡ï¼ã¿ã¼ãã«å´ï¼ããã°ã©ã ããã¼ã¸ã§ã³3
çµè«ããè¨ãã¨ã工夫ããã°ã§ãã¾ãã以ä¸ã¯ããã®åé¡ãä¿®æ£ããããã°ã©ã ã§ãã
L10ã§æ°ããåºã¦ããé¢æ°ãpcall()
ãç´¹ä»ãã¾ãï¼æ£ç¢ºãªæ
å ±ã¯Lua5.1ãªãã¡ã¬ã³ã¹ããã¥ã¢ã«ï¼ã
pcall(f, arg1, arg2, ã»ã»ã»)
- pcall()ã¯ä¸è¨ã§ããã¨ããé¢æ°ãå®è¡ãã¦ã¨ã©ã¼ãçºçããããããæã¾ãã¦ãfalseã¨ã¨ã©ã¼ã¡ãã»ã¼ã¸ãè¿ããé¢æ°ã§ãã
- å¼æ°1ï¼ç¡åé¢æ°ï¼ï¼ãå®è¡ãããé¢æ°ãä¸ãã¾ã
- å¼æ°2以éããã®ç¡åé¢æ°ã«ä¸ããå¼æ°ãããã¤ã§ã
- è¿å¤1ï¼boolean)ï¼ãã¹ãã¼ã¿ã¹ã³ã¼ããé¢æ°å®è¡æåãªãtrueãã¨ã©ã¼ãçãããfalseã
- è¿å¤2以éï¼ãé¢æ°å®è¡æåãªãé¢æ°å®è¡ã«ããè¿å¤ããã¨ã©ã¼çºçæã«ã¯ã¨ã©ã¼ã¡ãã»ã¼ã¸ãè¿ãã
- å®è¡ä¾ï¼
pcall(func, arg1, arg2)
ãã¯ãfunc(arg1, arg2)
ãå®è¡ãã¦ã¨ã©ã¼çºçãæããã¦å¦çãè¡ãã¾ãã
L12-16ã¯ãpcall()ããè¿ã£ã¦ããã¹ãã¼ã¿ã¹ã³ã¼ãï¼å¤æ°statusï¼ã«ãã£ã¦ã表示ã¡ãã»ã¼ã¸ãå¤ãã¦ããé¨åã«ãªãã¾ãã
ä»åº¦ãããããã°ã©ã ã§éãã§ã¿ãã
ä¸è¨ç»åã¯ã¿ã¼ãã«å´ã®ç»é¢ã§ãããéä¸ãã¹ãã«ãã¹ããã¦ãã(error)ãã¨ææãããã ãã§ããã®ã¾ã¾ç¶ãã¦ããã°ã©ã ãå®è¡ãã¦ãã¾ããã
ã¾ã¨ã
ããããã§ããããã§ãééãããã¨ãã§ããããã«ãªãã¾ãããã便å©ã§ãããï¼
ã»ã»ã»ãï¼ããããããé¢æ°åãå ¥åããã®ãããã©ãããï¼
ã§ãããã¼ã
次åã¯ãã®å¯¾çãèãã¾ãããã