æ¦è¦
ãã®è¨äºã§ã¯ãRobloxã®Luaã¹ã¯ãªããã«ãããç¹æ®ãªã°ãã¼ãã«ãã¼ãã«ã_G
ãã«ã¤ãã¦è§£èª¬ãã¾ãã_G
ã使ç¨ãããã¨ã§ãè¤æ°ã®ã¹ã¯ãªããéã§ãã¼ã¿ãé¢æ°ãå
±æããæ¹æ³ã¨ããã®ã¡ãªããã»ãã¡ãªãããå¦ã³ã¾ãããã®è¨äºãèªããã¨ã§ãã¹ã¯ãªããéã®ãã¼ã¿å
±æãå¹ççã«è¡ããéçºå¹çãåä¸ãããããã®ç¥èã身ã«ã¤ãããã¨ãã§ãã¾ãã
èæ¯
ã²ã¼ã éçºã§ã¯ãè¤æ°ã®ã¹ã¯ãªãããé£æºãã¦åä½ãããã¨ãä¸è¬çã§ãããã®éãã¹ã¯ãªããéã§ãã¼ã¿ãå
±æãããå ´åãããã¾ããä¾ãã°ããã¬ã¤ã¤ã¼ã®ææéãã²ã¼ã å
ã®è¨å®å¤ãªã©ãè¤æ°ã®ã¹ã¯ãªããããåç
§ã»æ´æ°ãããã·ãã¥ã¨ã¼ã·ã§ã³ã§ããé常ãã¢ã¸ã¥ã¼ã«ã¹ã¯ãªããã使ã£ã¦ãã¼ã¿ãå
±æãã¾ããã_G
ã使ããã¨ã§æ軽ã«ãã¼ã¿å
±æãå¯è½ã«ãªãã¾ãããããããã®ä½¿ãæ¹ã注æç¹ãæ£ããç解ãããã¨ãéè¦ã§ãã
詳細
_G
ã¨ã¯ä½ãï¼
_G
ã¯Luaã«ãããã°ãã¼ãã«ãã¼ãã«ã§ãå
¨ã¦ã®ã¹ã¯ãªããããã¢ã¯ã»ã¹å¯è½ãªç¹æ®ãªãã¼ãã«ã§ããRobloxã®ç°å¢ã§ã¯ãåãç°å¢å
ï¼ãµã¼ãã¼ã¾ãã¯ã¯ã©ã¤ã¢ã³ãï¼ã§åä½ããã¹ã¯ãªããéã§ããã®_G
ãéãã¦ãã¼ã¿ãé¢æ°ãå
±æã§ãã¾ãã
åºæ¬çãªä½¿ãæ¹
ä¾ï¼ãã¼ã¿ã®å ±æ
-- ã¹ã¯ãªãã1 _G.PlayerCash = 1000 -- ãã¬ã¤ã¤ã¼ã®ææéãè¨å®
-- ã¹ã¯ãªãã2 print("ç¾å¨ã®ææé㯠" .. _G.PlayerCash .. " ã³ã¤ã³ã§ã") -- åºåçµæ: ç¾å¨ã®ææé㯠1000 ã³ã¤ã³ã§ã
ãã®ããã«ã_G
ã使ç¨ããã¨ãä¸åº¦è¨å®ããå¤ãä»ã®ã¹ã¯ãªããããåç
§ã§ãã¾ãã
ä¾ï¼é¢æ°ã®å ±æ
-- ã¹ã¯ãªãã1 function _G.GreetPlayer(playerName) print("ããããã" .. playerName .. "ããï¼") end
-- ã¹ã¯ãªãã2 _G.GreetPlayer("太é") -- åºåçµæ: ããããã太éããï¼
_G
ã使ããã¨ã§ãé¢æ°ãå
±æå¯è½ã§ãã
注æç¹ã¨ãã¹ããã©ã¯ãã£ã¹
ã¯ã©ã¤ã¢ã³ãã¨ãµã¼ãã¼éã§ã¯å ±æãããªã
_G
ã¯ãµã¼ãã¼ã¹ã¯ãªããéãã¾ãã¯ã¯ã©ã¤ã¢ã³ãã¹ã¯ãªããéã§ã®ã¿å ±æããã¾ãããµã¼ãã¼ã¨ã¯ã©ã¤ã¢ã³ãéã§ãã¼ã¿ãå ±æããããã«ã¯ãRemoteEventãRemoteFunctionã使ç¨ããå¿ è¦ãããã¾ããäºæãã¬ä¸æ¸ãã®ãªã¹ã¯
ã°ãã¼ãã«å¤æ°ã§ãããããã©ã®ã¹ã¯ãªããããã§ãå¤ãå¤æ´ã§ãã¾ãããã®ãããæå³ããªãå ´æã§å¤ãå¤æ´ããããã°ã®åå ã¨ãªãå¯è½æ§ãããã¾ãããããã°ãé£ãããªã
ã¹ã¯ãªããéã®ä¾åé¢ä¿ãæ確ã§ãªããããåé¡ã®åå ãç¹å®ãã«ãããªãã¾ããã»ãã¥ãªãã£ã®æ¸å¿µ
ã¯ã©ã¤ã¢ã³ãå´ã§_G
ã使ç¨ããã¨ãã¨ã¯ã¹ããã¤ãã«ãã£ã¦å¤ãä¸æ£ã«å¤æ´ãããå¯è½æ§ãããã¾ããéè¦ãªãã¼ã¿ã®ç®¡çã¯ãµã¼ãã¼å´ã§è¡ãã¾ãããã
ããããã®ä»£æ¿æ¹æ³ï¼ã¢ã¸ã¥ã¼ã«ã¹ã¯ãªãã
ã¢ã¸ã¥ã¼ã«ã¹ã¯ãªããã使ç¨ããã¨ãæ示çã«ãã¼ã¿ãé¢æ°ãä»ã®ã¹ã¯ãªããã«æä¾ã§ãã¾ãã
ModuleScript
-- ModuleScript local DataModule = {} DataModule.PlayerCash = 1000 function DataModule.GreetPlayer(playerName) print("ããããã" .. playerName .. "ããï¼") end return DataModule
-- ã¹ã¯ãªãã1 local Data = require(game.ServerScriptService.ModuleScript) Data.PlayerCash = Data.PlayerCash + 500
-- ã¹ã¯ãªãã2 local Data = require(game.ServerScriptService.ModuleScript) print("ç¾å¨ã®ææé㯠" .. Data.PlayerCash .. " ã³ã¤ã³ã§ã") -- åºåçµæ: ç¾å¨ã®ææé㯠1500 ã³ã¤ã³ã§ã Data.GreetPlayer("太é") -- åºåçµæ: ããããã太éããï¼
ã¢ã¸ã¥ã¼ã«ã¹ã¯ãªããã使ç¨ãããã¨ã§ããã¼ã¿ã®ç®¡çãããæ確ã«ãªããä¿å®æ§ãåä¸ãã¾ãã
ã¾ã¨ãï¼_G
ã®æ´»ç¨ã¯æ
éã«
_G
ã¯æ軽ã«ãã¼ã¿å
±æãã§ããåé¢ãä¸è¨ã®ãããªãªã¹ã¯ãããã¾ããå°è¦æ¨¡ãªã¹ã¯ãªããããããã¿ã¤ãã§ããã°æç¨ã§ããã大è¦æ¨¡ãªããã¸ã§ã¯ããè¤éãªã·ã¹ãã ã§ã¯ã¢ã¸ã¥ã¼ã«ã¹ã¯ãªããã®ä½¿ç¨ãæ¤è¨ãã¾ãããã
ã¾ã¨ã
_G
ã¯Robloxã®Luaã¹ã¯ãªããã«ããã¦ãã¹ã¯ãªããéã§ãã¼ã¿ãé¢æ°ãå
±æããããã®ã°ãã¼ãã«ãã¼ãã«ã§ããæ軽ã«ä½¿ç¨ã§ãã¾ãããäºæãã¬ãã°ãã»ãã¥ãªãã£ãªã¹ã¯ãæãå¯è½æ§ãããã¾ããéçºè¦æ¨¡ãç®çã«åããã¦ãã¢ã¸ã¥ã¼ã«ã¹ã¯ãªãããªã©ã®ä»ã®æ¹æ³ã¨æ¯è¼ããæé©ãªææ³ãé¸æãããã¨ãéè¦ã§ããé©åãªãã¼ã¿å
±æã®æ¹æ³ãç解ããããå®å
¨ã§å¹ççãªã²ã¼ã éçºãç®æãã¾ãããã