CrimsonalJoin Date: 2011-04-23 Post Count: 1795 |
Commands = {}
function OnChatted(p,msg)
for i,v in pairs(Commands) do
print(v[1]:len())
if msg:sub(1, i:len()):lower() == v[1]:lower() then
v[2](p, msg:sub(i:len()+2))
end
end
end
function getplayer(me,name)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name:sub(1, name:len()):lower() == name:lower() then
return v
end
end
end
function AddCommand(cmd,func)
Commands[cmd] = {cmd,func}
end
AddCommand("ff", function(p, msg)
ypcall(function()
Instance.new("ForceField", getplayer(p, msg).Character)
end)
end)
AddCommand("kill", function(p, msg)
getplayer(p, msg).Character:BreakJoints()
end)
game.Players.PlayerAdded:connect(function(x)
x.Chatted:connect(function(msg) OnChatted(x,msg) end)
end)
Better than that other way? |
|
|
https://www.youtube.com/watch?v=OvseAKgAIig |
|
CrimsonalJoin Date: 2011-04-23 Post Count: 1795 |
eh, i'm gonna stick with this way |
|
chimmihcJoin Date: 2014-09-01 Post Count: 17143 |
"efficient"
Use # instead of the len function, it is much faster.
|
|
CrimsonalJoin Date: 2011-04-23 Post Count: 1795 |
I like it the way it looks and using a # does not effect the speed of the code, it is fast already -_- |
|
chimmihcJoin Date: 2014-09-01 Post Count: 17143 |
"# does not effect the speed of the code"
Yes, it does.
|
|
|
--[[+ 1 to all results to avoid scientific notations.]]
local input, returns, tick, total = ("_"):rep(1000000), {}, tick, 0
for x = 1, 7999, 1 do
local start = tick()
local _ = string.len(input)
table.insert(returns, (tick() - start))
end
for _, x in next, (returns) do
total = (total + x)
end
print("string.len() fastest time + 1; " .. (math.min(unpack(returns)) + 1))
print("string.len() slowest time + 1; " .. (math.max(unpack(returns)) + 1))
print("string.len() average time + 1; " .. ((total / #returns) + 1))
print('')
returns, total = {}, 0
for x = 1, 7999, 1 do
local start = tick()
local _ = input:len()
table.insert(returns, (tick() - start))
end
for _, x in next, (returns) do
total = (total + x)
end
print("len() fastest time + 1; " .. (math.min(unpack(returns)) + 1))
print("len() slowest time + 1; " .. (math.max(unpack(returns)) + 1))
print("len() average time + 1; " .. ((total / #returns) + 1))
print()
returns, total = {}, 0
for x = 1, 7999, 1 do
local start = tick()
local _ = #input
table.insert(returns, (tick() - start))
end
for _, x in next, (returns) do
total = (total + x)
end
print("# fastest time + 1; " .. (math.min(unpack(returns)) + 1))
print("# slowest time + 1; " .. (math.max(unpack(returns)) + 1))
print("# average time + 1; " .. ((total / #returns) + 1))
--[[>string.len() fastest time + 1; 1
string.len() slowest time + 1; 1.0000791549683
string.len() average time + 1; 1.0000004096543
len() fastest time + 1; 1
len() slowest time + 1; 1.0000157356262
len() average time + 1; 1.0000003531123
# fastest time + 1; 1
# slowest time + 1; 1.000007390976
# average time + 1; 1.0000002318911, results will very.]] |
|
CrimsonalJoin Date: 2011-04-23 Post Count: 1795 |
I said before that it's already very fast. I don't need to change something just to get an extra millisecond. It's useless. |
|
|
Yes that's actually a really efficient way. Looping over a table, finding the command, and launching the function i s the best way you can be doing it (out of the very few ways this can even be done). |
|
|
If you don't want your code to be efficient, why did you even ask? You're totally ignoring people who are suggesting ways to make it more efficient.
|
|
CrimsonalJoin Date: 2011-04-23 Post Count: 1795 |
If I don't find efficient to me, then I don't like it
Because a # over a len is useless |
|
|
Efficiency isn't about nitpicking code with a negligible impact on performance. |
|
|
I know, but he said "Most efficient", and it is not. He says he doesn't really care about miniscule differences in efficiency though, in which case idk why he even asks since pretty much everything is unnoticeable.
|
|
|
Unless he only posted his script here to brag, but has such a huge ego that he can't stand his question being answered.
|
|
CrimsonalJoin Date: 2011-04-23 Post Count: 1795 |
I just wanted to see if there was any better way because i've seen it before
btw, you can stop bumping this because I'm just gonna stick to this way
:D |
|
|
There are still other changes to the overall structure of the script that can have a noticeable impact on performance. |
|
|
If you're gonna stick to your way, then why even posting this?
This siggy is copyrighted ©
|
|
CrimsonalJoin Date: 2011-04-23 Post Count: 1795 |
"btw, you can stop bumping" |
|
|
If to had to guess Jarod is right and he posted here to try and brag,
Maybe he is hurt that the one I threw together for a video is the same concept as his. |
|
CrimsonalJoin Date: 2011-04-23 Post Count: 1795 |
Um no, you're wrong. You're all wrong. I have seen this method before and I've finally understood on how to use it.
if you want to see the video I learn off here:
https://www.youtube.com/watch?v=zK5AT4zXCOA
I knew that was a good way, and I was just seeing if there was a better way. But all I got was just use a # instead of len() |
|