Hi everyone, I’ve been developing for a while and I’ve made a small game. During the development process, I gradually realized the importance of frameworks, so I recently started looking at a popular framework, Knit. After trying it, I found that one thing is a bit inconvenient, which is that the client and server service instances are obtained through GetService(string), which makes it difficult for me to automatically complete their functions. This has caused me some trouble to a certain extent.
— code —
-- MoneyService
local Knit = require(game.ReplicatedStorage.Packages.Knit)
local MoneyService = Knit.CreateService({
Name = script.Name,
Client = {}
})
function MoneyService:GiveMoney(player, count)
print(`give {player}, {count}`)
end
function MoneyService.Client:RequestMoney(player)
return self.Server:GiveMoney(player, math.random(1, 50))
end
return MoneyService
a server script starts Knit and add services, and here is the client script.
-- client
local Knit = require(game.ReplicatedStorage.Packages.Knit)
Knit.Start():catch(warn):await()
local MoneyService = Knit.GetService("MoneyService")
MoneyService.
As we can see, when I use a dot, the editor suggests some properties, but when I use a colon, there is nothing. This forces me to check the function names in my service script to avoid spelling errors.
Knit is already a mature framework, but I want to optimize this part. My initial idea was to use ‘require’, but many problems have been exposed, so I gave up. Does anyone have any good ideas?