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 » Scripting Helpers
Home Search
 

Re: Help with returning bools

Previous Thread :: Next Thread 
EpikYummeh is not online. EpikYummeh
Joined: 05 Sep 2009
Total Posts: 1879
01 Aug 2011 05:27 PM
So there is nothing on the Wiki directly about the use of the return snippet, and I'd like to know how to use it. In this case, I have a function in a script in a HopperBin called when the player clicks after some conditions. Inside the function, it checks all the parts in a model for a part in a certain position in relation to an existing object. If the part relative to the position of the existing object is false, it adds a part there and returns false. If something is there, return true and do nothing.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
01 Aug 2011 05:31 PM
return true

return false
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
01 Aug 2011 05:33 PM
function example(arg1,arg2)
return arg1+arg2
end

print(example(1,5))

>6
Report Abuse
EpikYummeh is not online. EpikYummeh
Joined: 05 Sep 2009
Total Posts: 1879
01 Aug 2011 05:36 PM
@Duke: But how can I grab the returned value in another function?

Here is the checker function and its parameters:
function checkPos2(target,pos,bool)

Target is mouse.Target from the Button1Down(mouse) function, and pos is the position of target. Bool is the bool I want to grab for the Button1Down function.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
01 Aug 2011 05:38 PM
wouldn't it have to return after you check though?
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
01 Aug 2011 05:39 PM
function explode(boom)
local pos = boom.Position(math.random(1,100), math.random(1,100), math.random(1,100))
return pos
end

print(""..explode(Instance.new("Explosion", workspace)).."")
Report Abuse
EpikYummeh is not online. EpikYummeh
Joined: 05 Sep 2009
Total Posts: 1879
01 Aug 2011 05:39 PM
Yes. I'll just post the check function and let you decide if it's right.

function checkPos2(target,pos,bool)
isPart = false
mine = game.Workspace.Mine:GetChildren()
for i = 1, #mine do
if (mine[i].Position == pos + Vector3.new(4,0,0) then
isPart == true
end
end
end
return isPart
end
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
01 Aug 2011 05:42 PM
function checkPos2(target,pos,bool)
local isPart = false
mine = game.Workspace.Mine:GetChildren()
for i = 1, #mine do
if (mine[i].Position-pos).magnitude<=4 then
isPart = true
end
end
return isPart
end

I still don't see what you need the bool is for?
Report Abuse
EpikYummeh is not online. EpikYummeh
Joined: 05 Sep 2009
Total Posts: 1879
01 Aug 2011 05:43 PM
I'm writing a script for a mining game like the popular game Epic Mining by PiePerson. I don't want to add a new block where another one already is.
Report Abuse
kyleman1990 is not online. kyleman1990
Joined: 09 Sep 2008
Total Posts: 2103
01 Aug 2011 05:43 PM
In another function you would have to use an "if" statement.

if checkPos2(target,pos,bool) == true then

--stuff if checkPos2 returns 'true'

else

--stuff if checkPos2 returns 'false'

end
Report Abuse
EpikYummeh is not online. EpikYummeh
Joined: 05 Sep 2009
Total Posts: 1879
01 Aug 2011 05:46 PM
OK, but what I'm asking is the way I have my check function the right way?
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
01 Aug 2011 05:48 PM
Then you would NOT use clicked stuff. First when you generate all the bricks to start, make all of them named by their position. When you dig one out and it's gone, make it so that the brick isn't removed but instead is completely invisible and CanCollide==false. Then you're going to get where the parts for each direction should be by simple vector math. Then once you have all those positions, use :findFirstChild() to find if there's already one and if there isn't make a new brick.
Report Abuse
EpikYummeh is not online. EpikYummeh
Joined: 05 Sep 2009
Total Posts: 1879
01 Aug 2011 05:50 PM
Yes, I already figured out I can't remove parts, which is why I added the checker. The problem is though is that I'm determining whether the target is an ore or not by the name.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
01 Aug 2011 05:51 PM
That's why you name it by the position.
Report Abuse
EpikYummeh is not online. EpikYummeh
Joined: 05 Sep 2009
Total Posts: 1879
01 Aug 2011 05:56 PM
I could probably make that work.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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