|
| 12 Oct 2016 04:57 PM |
Well this function here:
function GetCommandLevel(cmd) for exe in string.gmatch(cmd, "%a+") do for i,v in next, (_G.Commands) do if i == exe[1] then return(v) else return false end break end end end
always returns a boolean (certainly "false"), now this would make sense if not for the fact that _G.Commands looks like this:
_G.Commands = { ["Kick"] = 2, ["Ban"] = 3, ["Kill"] = 1, ["Teleport"] = 1, ["Team"] = 1, ["Give"] = 1, ["Admin"] = 4, }
What it basically is supposed to do, is see if it can find a key word in the functions argument and then match it with a dictionary within the _G.Commands table, then return it's value. Any ideas? |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Oct 2016 04:58 PM |
Use a module script instead of gross _G
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Oct 2016 04:58 PM |
| Remove the [1] after exe[1] |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2016 05:00 PM |
I don't need a module, I plan on using these variables in other scripts. I don't see why people don't like _G. if it doesn't even affect anything that wouldn't make sense. But thanks for the help cnt, I'll try that. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Oct 2016 05:02 PM |
You are stupid you know that right? You literally said it yourself:
'I plan on using these variables in other scripts.'
That is where modules come into place idiot.
|
|
|
| Report Abuse |
|
|
| |
|
|
| 12 Oct 2016 05:05 PM |
| because _G is absolute crap and tbh it should be removed from lua becausethe only reason i can think of that it stays there is so you can use globals like CFrame or Instance or string or table on all scripts |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 12 Oct 2016 05:08 PM |
| Just for bytes sake (even though it's such a minuscule difference) I'll just save the couple of kilobytes I can unless I run into a impassable point. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Oct 2016 05:12 PM |
OP since you're using a dictionary, there's an easier way to do this:
function GetCommandLevel(cmd) local cmd = cmd:match("%a+") return _G.Commands[cmd] end |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2016 05:13 PM |
| This will return the value (such as the "2" indexed by "Kick")? |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 12 Oct 2016 05:16 PM |
Yes, it'll return the number of the command or nil if cmd is not the name of a command.
|
|
|
| Report Abuse |
|
|
|
| 12 Oct 2016 05:17 PM |
| Thanks for all the help guys. |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2016 05:29 PM |
| So this post really helped me, I'd archive this if you are new to trying to make commands (or ,I guess basic, string manipulation). |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|