|
| 16 Feb 2014 06:19 PM |
What does return do? Don't tell me to go on wiki, cause I did and I have no clue what it means. |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2014 06:22 PM |
return is usually used at the end of a function or to stop a function from running if it finds a particular condition.
Example:
function timestwo(n) return n*2 end
print(timestwo(2))
if timestwo(2) == 4 then --code here end
function imsupposedtostop() if true then return end --Will stop here and not print hi print("hi") end |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2014 06:26 PM |
...? So if it's not true then it will print hi? |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 16 Feb 2014 06:39 PM |
I was looking at how to create admin commands and here was the script. One of the lines is return player. What does that do?
local isAdmin = {["OBF"] = true, ["ArceusInator"] = true, ["amanda12895"] = true} function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end function onChatted(message, player) if message:sub(1, 5) == "kill/" and isAdmin[player.Name] then victim = findPlayer(message:sub(6)) if victim and victim.Character then victim.Character:BreakJoints() end end end game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) end) |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2014 06:41 PM |
findPlayer() returns player say findPlayer return MarioKartAddict
k = findPlayer() print(k) --> "MarioKartAddict"
it basically makes the function a variable |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2014 06:45 PM |
local isAdmin = {["OBF"] = true, ["ArceusInator"] = true, ["amanda12895"] = true}
function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player --if the player is found within all the children of "Players" then it will return the player end end end
function onChatted(message, player) if message:sub(1, 5) == "kill/" and isAdmin[player.Name] then --checks to see if the first 5 characters are "kill/" and if player is in the table "isAdmin" victim = findPlayer(message:sub(6)) --looks at the 6th character and beyond then checks to see if it's a player through the findplayer() method which will return the player if victim and victim.Character then victim.Character:BreakJoints() --Kills the player if there is actually a player end end end
game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) --If the player that entered chats then it will do the function onchatted end |
|
|
| Report Abuse |
|
|
| |
|
|
| 16 Feb 2014 08:31 PM |
| I understand the rest of the scripts but I never scripted using return before. What is it do and when I do I use it? |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2014 08:34 PM |
Imagine this, you are in an airport(ROBLOX airport) and you want to check if the player is a valid.. well.. player.
You do: (Pseudo code Btw)
function checkplayer(player) if game:find(player) then return true else return false end end
passport.Passed:connect(function(plr) --plr is the player that is trying to pass plr:Stop if checkplayer(plr) then --if player passes the test plr:Go() end end) |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2014 08:37 PM |
example of stuff I do with return
function kickScrob(lol) -- start with lol, soon it will be nothing
if lol:IsA('Player') then -- check if it's a player i'm scrobing lol:Kick() -- SCROB!!11! else -- if it's not a scrob print'Scrob cheated') -- print the scrob cheated
end -- end the loop return nil -- makes the value of lol nothing end -- end the function
kickScrob('cooldude999921') -- removes me in place of lol , Don't remove me scrob
Medium Script0r |
|
|
| Report Abuse |
|
|