|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 13 Jul 2013 07:20 AM |
| Yep, that's what I thought it meant. Thanks. |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2013 07:23 AM |
You're welcome!
-Believe and you will achieve- |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
| |
|