functionGame.Rule:OnPlayerConnect(player) playerPosition[player.index] = player.position end
舉個例子,像是KZ的存讀點功能。
1 2 3 4 5 6 7 8 9 10 11 12
playerPosition = {}
functionGame.Rule:OnPlayerSignal(player, signal) if signal == 1then -- 當玩家按下1,儲存座標 playerPosition[player.index] = player.position elseif signal == 2then -- 當玩家按下2,讀取座標 player.position = playerPosition[player.index] end end
大量且重複性高的EntityBlock創建
這我很常用在KZ裡面的跳板,10個關卡,每一關可能有10個板子,那就要創建100個座標和函式。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
playerPosition = {}
block_1 = Game.EntityBlock.Create({x = 1, y = 1, z = 1}) functionblock_1:OnTouch(player) playerPosition[player.index] = player.position end
block_2 = Game.EntityBlock.Create({x = 2, y = 2, z = 2}) functionblock_2:OnTouch(player) playerPosition[player.index] = player.position end
block_3 = Game.EntityBlock.Create({x = 3, y = 3, z = 3}) functionblock_3:OnTouch(player) playerPosition[player.index] = player.position end
...無限循環
只要把座標全部都彙整進一個變數,利用迴圈來跑就不用再寫無意義的函式。
1 2 3 4 5 6 7 8 9 10 11 12
blocks = { {x = 1, y = 1, z = 1}, {x = 2, y = 2, z = 2}, {x = 3, y = 3, z = 3} }
for k,v inpairs(blocks) do local block = Game.EntityBlock.Create(v) functionblock:OnTouch(player) playerPosition[player.index] = player.position end end
functionGame.Rule:OnPlayerConnect(player) if player.index == 1then sync_PlayerLevel_1.value = InitialLevel elseif player.index == 2then sync_PlayerLevel_2.value = InitialLevel elseif player.index == 3then sync_PlayerLevel_3.value = InitialLevel end end
1 2 3 4 5 6 7 8 9 10 11 12 13
-- ui.lua sync_PlayerLevel_1 = UI.SyncValue.Create("sync_PlayerLevel.1") functionsync_PlayerLevel_1:OnSync() -- do something end sync_PlayerLevel_2 = UI.SyncValue.Create("sync_PlayerLevel.2") functionsync_PlayerLevel_2:OnSync() -- do something end sync_PlayerLevel_3 = UI.SyncValue.Create("sync_PlayerLevel.3") functionsync_PlayerLevel_3:OnSync() -- do something end
functioncomma_value(n) local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$') return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right end
local temp = {} for i = 1, boxCount do local rAvg = colorA.r + math.floor((colorB.r - colorA.r) * i / boxCount) local gAvg = colorA.g + math.floor((colorB.g - colorA.g) * i / boxCount) local bAvg = colorA.b + math.floor((colorB.b - colorA.b) * i / boxCount) local aAvg = colorA.a + math.floor((colorB.a - colorA.a) * i / boxCount) table.insert(temp, {r = rAvg, g = gAvg, b = bAvg, a = aAvg}) end return temp end