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: "for i=1, #[name] do" What does it mean?

Previous Thread :: Next Thread 
Darthnoodles98 is not online. Darthnoodles98
Joined: 02 Apr 2011
Total Posts: 418
13 Jul 2013 06:33 AM
As of now, I learn how to script mostly from looking at free model scripts and applying that type of thing to other things by editing it. But this thing pops up all the time:

"for i=1, #[name] do
if p.Name == [name][i] then
p.Chatted.Connect:(onSpeakDo)"

What does it mean?

I have an idea of what it means, but I need clarification.

Thanks.
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
13 Jul 2013 06:39 AM
"for i=1, #[x] do
if p.Name == [x][i] then
p.Chatted.Connect:(onSpeakDo)"

'x' has to end with "GetChildren()" because it is creating a table. Then, for every, thing, in the table, the variable, i, will do something. In this case, it will check if the child is called "p"s name. P, should be defined too.

I've never seen the third line there before.




Scripting Tutorials: youtube.com/user/smiley599roblox
Report Abuse
Darthnoodles98 is not online. Darthnoodles98
Joined: 02 Apr 2011
Total Posts: 418
13 Jul 2013 06:48 AM
No, here's an example:

ponies = {"Darthnoodles98"}

game.Players.PlayerAdded:connect(function(p)
for i=1, #ponies do
if p.Name == ponies[i] then
p.Chatted:connect(WhenTheySpeak)
break
end)
end
end


--stuff

function WhenTheySpeak()
--more stuff
Report Abuse
Darthnoodles98 is not online. Darthnoodles98
Joined: 02 Apr 2011
Total Posts: 418
13 Jul 2013 06:49 AM
I kind of supposed that you'd work out that I'd previously defined "p". (Because of the "(function(p)".
Report Abuse
kingmasterfit is not online. kingmasterfit
Joined: 22 Jul 2012
Total Posts: 2773
13 Jul 2013 06:49 AM
I like your name darth
Report Abuse
Darthnoodles98 is not online. Darthnoodles98
Joined: 02 Apr 2011
Total Posts: 418
13 Jul 2013 06:50 AM
Thanks, man. I used to be obsessed with Star Wars, hence the "Darth" and "noodles" is my nickname. "98" is my house number.
Report Abuse
juzzbyXfalcon is not online. juzzbyXfalcon
Joined: 02 Feb 2011
Total Posts: 1311
13 Jul 2013 07:08 AM
Let me go trough it all

ponies = {"Darthnoodles98"} --This is your table

game.Players.PlayerAdded:connect(function(p) --This is the function
for i=1, #ponies do --This creates a list out of your table, and will pick one "item" from your table
if p.Name == ponies[i] then --If the name of p is the same as item from the table we currently use then
p.Chatted:connect(WhenTheySpeak) --when p chats something, we execute the function WhenTheySpeak
break --Breaks the loop so it doesn't checks for any other items of the table.
end)
end --If it wasn't for the break, this would go back to the for i=1,#ponies do and that would pick a different item than before.
end

I hope this explained it pretty much.

-Believe and you will achieve-
Report Abuse
Darthnoodles98 is not online. Darthnoodles98
Joined: 02 Apr 2011
Total Posts: 418
13 Jul 2013 07:20 AM
Yep, that's what I thought it meant. Thanks.
Report Abuse
juzzbyXfalcon is not online. juzzbyXfalcon
Joined: 02 Feb 2011
Total Posts: 1311
13 Jul 2013 07:23 AM
You're welcome!

-Believe and you will achieve-
Report Abuse
Unsubstantial is not online. Unsubstantial
Joined: 11 Sep 2012
Total Posts: 872
13 Jul 2013 07:28 AM
@juzzby Wrong or too vague, I can't tell which.

'for i=1, #[name] do'
Firstly - this is a for loop. There are 2 (sometimes 3) args in the middle of it.

> for i=1,
'i' starts at 1.

> #[name] do
# gets the length of something such as a table, or array of instances (found with GetChildren())
[name] is the target, which # finds the length of.

> ponies[i]
It finds the index of 'i' in that table, 'i' is dependent on how many times the for loop has re-run. If the for loop has run 10 times, ponies[i] would be equivalent to ponies[10].

If there are 50 indexes in our table, the for loop would loop 50 times. If this loop was running again for the 50th time, it would grab the 50th value in that array.
Report Abuse
juzzbyXfalcon is not online. juzzbyXfalcon
Joined: 02 Feb 2011
Total Posts: 1311
13 Jul 2013 07:41 AM
Well, I wasn't explaining to you, was I? Neither was I writing for the wiki or something, so I didn't wanted to give definitions for every part of the script, just a simple explanations.

And on the order of randomly selecting, you're right.

ponies[math.random(1,#ponies)]

That should make it random. I've gotten rusty with tables... *Feels ashamed.*

-Believe and you will achieve-
Report Abuse
yyyfa is not online. yyyfa
Joined: 06 Aug 2011
Total Posts: 380
13 Jul 2013 08:38 AM
@kingmasterfit: vactus?111!?11?? vactus is.... well vactus. ego is too high dewd
Report Abuse
whupdup is not online. whupdup
Joined: 18 Aug 2012
Total Posts: 122
13 Jul 2013 09:10 AM
Wait noodles is your nickname? are you in the offspring?
Report Abuse
Darthnoodles98 is not online. Darthnoodles98
Joined: 02 Apr 2011
Total Posts: 418
13 Jul 2013 09:53 AM
#legit
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