generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Always returns boolean?

Previous Thread :: Next Thread 
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
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 is not online. 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 is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Oct 2016 04:58 PM
Remove the [1] after exe[1]
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
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 is not online. 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
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
12 Oct 2016 05:03 PM
Then why not just use _G.
Report Abuse
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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 is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Oct 2016 05:06 PM
wrong again wunder.
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
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 is not online. 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
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
12 Oct 2016 05:13 PM
This will return the value (such as the "2" indexed by "Kick")?
Report Abuse
Kodran is not online. 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
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
12 Oct 2016 05:17 PM
Thanks for all the help guys.
Report Abuse
Seizurezxzz is not online. Seizurezxzz
Joined: 12 Feb 2013
Total Posts: 1297
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 is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
12 Oct 2016 05:29 PM
pastebin
.
com
/XXQxXCiH


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image