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: returning multiple values

Previous Thread :: Next Thread 
RogueMage is not online. RogueMage
Joined: 28 Jan 2012
Total Posts: 1235
23 Dec 2016 06:27 PM
If I have said function:


function _M.findData(player) -- returns boolean to check if the we could find the player data
if player then
if game.ReplicatedStorage.PlayerData:FindFirstChild(player.UserId .. "_data") then
return true, game.ReplicatedStorage.PlayerData:FindFirstChild(player.UserId .. "_data")
else
return false
end
else
return false
end
end


and then I try to assign it to variables, such that:

local check, folder = _M.findData(player)

If I return false for check, then I wouldn't be returning *folder*

Would that just evaluate to nil?
Report Abuse
OAuth2 is not online. OAuth2
Joined: 27 Nov 2016
Total Posts: 751
23 Dec 2016 06:33 PM
return val1, val2


~ This is not a siggy ~
Report Abuse
RogueMage is not online. RogueMage
Joined: 28 Jan 2012
Total Posts: 1235
23 Dec 2016 06:36 PM
I'm not asking how to return multiple values...

Read what I asked
Report Abuse
SteadyOn is not online. SteadyOn
Joined: 20 Mar 2011
Total Posts: 600
23 Dec 2016 06:37 PM
You're defining 2 values but only returning one, therefore it's only registering check as false and doing nothing for folder.

do what he said ^


- R$389 SteadyOn if u wanna thank me buy this 4 5 r$ www.roblox.com/catalog/446657116/Ayy-Lmao
Report Abuse
clc02 is not online. clc02
Joined: 30 Dec 2007
Total Posts: 7393
23 Dec 2016 06:38 PM
Alternatively
return {Item = game.Workspace.Item, Player = game.Players.Player, Target = game.Workspace.Target}


results = func()
results.Item:Destroy()
results.Player.Score.Value = results.Player.Score.Value + 1
results.Target:Destroy()

I prefer it to return one, two as you'll never go "Well, do I go item, player, target = func() or was it player, target, item = func()"
Report Abuse
OAuth2 is not online. OAuth2
Joined: 27 Nov 2016
Total Posts: 751
23 Dec 2016 06:39 PM
My bad. Yes, folder will return nil.


~ This is not a siggy ~
Report Abuse
SteadyOn is not online. SteadyOn
Joined: 20 Mar 2011
Total Posts: 600
23 Dec 2016 06:39 PM
Oh I see. I mean I don't really see the point in it unless you're planning on giving 2 variables in one place and 1 in another. I'm not sure but it's likely that only check is being filled.

If you want to avoid glitches just define it as nil

so like

return false, nil


- R$389 SteadyOn if u wanna thank me buy this 4 5 r$ www.roblox.com/catalog/446657116/Ayy-Lmao
Report Abuse
OAuth2 is not online. OAuth2
Joined: 27 Nov 2016
Total Posts: 751
23 Dec 2016 06:41 PM
@SteadyOn "If you want to avoid glitches just define it as nil"

Incorrect. There will be no glitches as folder will automatically be nil.

local a,b = 3
print(a, b)

> 3 nil


~ This is not a siggy ~
Report Abuse
SteadyOn is not online. SteadyOn
Joined: 20 Mar 2011
Total Posts: 600
23 Dec 2016 06:42 PM
I meant it as a precaution as I don't really know whether it would return nil, as you have now pointed out it would return as nil.


- R$389 SteadyOn if u wanna thank me buy this 4 5 r$ www.roblox.com/catalog/446657116/Ayy-Lmao
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