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 Finding and Picking ARRAYS

Previous Thread :: Next Thread 
TimeworksX is not online. TimeworksX
Joined: 14 Feb 2011
Total Posts: 421
06 Aug 2012 05:47 PM
I am building a script that has an array for random parts, and picks a random part in the array. Here is what i have so far:

function findNearestHarbor()
local Harbors = {Workspace.Harbors.Harbor1,Workspace.Harbors.Harbor2,Workspace.Harbors.Harbor3}

If you could help that would be great. Thanks
Report Abuse
Xnite515 is not online. Xnite515
Joined: 18 Feb 2011
Total Posts: 22763
06 Aug 2012 05:49 PM
math.random(harbors)

I think that;s right..
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 05:54 PM
math.random(1, #harbors)
Report Abuse
TimeworksX is not online. TimeworksX
Joined: 14 Feb 2011
Total Posts: 421
06 Aug 2012 05:55 PM
so in this case i would be
Math.random(1,17)??
were does it pick from the array?
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 05:56 PM
Is that all of the script you have? If you're trying to do what I think you're doing, then I think there might be a more efficient way.
Report Abuse
TimeworksX is not online. TimeworksX
Joined: 14 Feb 2011
Total Posts: 421
06 Aug 2012 07:01 PM
here is all i have:


function findNearestHarbor()
math.randomseed(tick())
local Harbors = {Workspace.Harbors.Harbor1,Workspace.Harbors.Harbor2,Workspace.Harbors.Harbor3,Workspace.Harbors.Harbor4,Workspace.Harbors.Harbor5,Workspace.Harbors.Harbor6,Workspace.Harbors.Harbor7,Workspace.Harbors.Harbor8,Workspace.Harbors.Harbor9,Workspace.Harbors.Harbor10,Workspace.Harbors.Harbor11,Workspace.Harbors.Harbor12,Workspace.Harbors.Harbor13,Workspace.Harbors.Harbor14,Workspace.Harbors.Harbor15,Workspace.Harbors.Harbor16,Workspace.Harbors.Harbor17}
RandomBrick = Math.random(Harbors)
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 07:02 PM
Oh my o.o
Use this instead:
local randomBrick = workspace.Harbor["Harbor"..tostring(math.random(1, 17))];
Report Abuse
TimeworksX is not online. TimeworksX
Joined: 14 Feb 2011
Total Posts: 421
06 Aug 2012 07:04 PM
if you notice, my workspace is:

Workspace.Harbors.Harbor#

so how would i incorperate that into a script
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 07:06 PM
The way I just should you.
The ".." is string concatentation.
"Harbor"..tostring(math.random(1, 17)) would generate a random Harbor# between 1 and 17, and as all your parts are called Harbor#, it would be fine.
Report Abuse
TimeworksX is not online. TimeworksX
Joined: 14 Feb 2011
Total Posts: 421
06 Aug 2012 07:07 PM
oh ok thanks you much!
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 07:09 PM
Yw :3
This is a nice technique to use when all yours objects are named similarly like that.
Report Abuse
TimeworksX is not online. TimeworksX
Joined: 14 Feb 2011
Total Posts: 421
06 Aug 2012 07:10 PM
well on thing, my workspace has is like:

Workspace
Harbors
Harbor1
Harbor2
...
..
.
....

..

..
....
Harbor16
Harbor17


would it still work?
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 07:11 PM
Yeah I believe so. The best way to find out is to try it yourself! :3
Report Abuse
TimeworksX is not online. TimeworksX
Joined: 14 Feb 2011
Total Posts: 421
06 Aug 2012 07:17 PM
AWESOME!!! I ran this:\
function findNearestHarbor()
math.randomseed(tick())
local randomBrick = Workspace.Harbor["Harbor"..tostring(math.random(1, 17))];
print(Harbor[3]:GetFullName())
end



on output and it worked!!
thx so much :)
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
06 Aug 2012 07:19 PM
:DDDDDD
Yw ^0^!
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