skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 29 Nov 2013 12:40 PM |
I still don't understand the symbols [] in scripting, or the symbol #
Also, I still don't understand arguments. I get how some scripts use them (for example, you have to make the arguments for print otherwise it wont print anything) but I don't understand how you make them. How does putting in words in the parenthesis in a function you have just made change anything?
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
|
| 29 Nov 2013 12:44 PM |
[] index
game.workspace["Part"] is the same as game.workspace.Part
# number
#workspace:GetChildren() returns the number of things in workspace
example2
MODEL >PART >PART2 >Value >MODEL >CHARACTER
#MODEL:GetChildren() will return 5, as there are 5 children |
|
|
| Report Abuse |
|
|
|
| 29 Nov 2013 12:49 PM |
The [] symbol can do 2 things.
If you use double of them ([[ or ]]) then it creates a longer string, which can be multiple lines.
Example:
[[hello world]]
would be fine
"hello world"
would error.
The second use it to access indexes in a table. It is the same as doing .something but can include spaces/dots/what ever stuff isn't allow.
Example:
game.Workspace["Part 1"]
tab = {} tab["Space "] = 5
game.Workspace["Part.1"]
these would all work fine.
game.Workspace.Part 1--Would error
tab = {} tab.Space = 5 --You would be unable to add the space after 'space'
game.Workspace.Part.1--1 is not a valid child of Part
these all would error
Now for the # symbol. It basically stands for number of. It is the same as string.len() or table.getn(). What it does is tell you the length of a string, or the number of indexes.
Examples:
str = "asdfasdfadsf"
print(#str) print(string.len(str)) -->both would print 12, since the string contains 12 characters.
tab = {1,2,3,4,5,6,7,8,9} print(#tab) print(table.getn) -->Both would print 9, since there are 9 indexes.
Hope this helps, just say if any of this confuses you |
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 29 Nov 2013 12:52 PM |
Did you even understand his question?
@OP Consider this example
function kill() -- in this function, we cannot decide who dies. Player1 would die no matter what. Game.Players:FindFirstChild("Player1").Character:BreakJoints() end
function kill(player_name) -- we could say kill("ekkoh") and it would kill me instead of a default to whatever the function is Game.Players:FindFirstChild(player_name).Character:BreakJoints() end
"We can walk a million miles, and end up in the sea." - George Ragan aka Johnny 3 Tears |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 29 Nov 2013 12:54 PM |
>The second use it to access indexes in a table.
What is that?
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
|
| 29 Nov 2013 12:57 PM |
you can also use [] for an array
array_name = [] --An array which stores multiple values
array_full = [2,"hi",nil] --An array filled with values
To call an array simply do this:
for _,v in pairs(array_full) do print(v) --v is the array_full --or other code here n stuff end
|
|
|
| Report Abuse |
|
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 29 Nov 2013 01:02 PM |
This isn't JavaScript, they're not called arrays, you can't instantiate them with brackets. This is Lua, they're called tables, and you use curly braces to instantiate them ({}).
"We can walk a million miles, and end up in the sea." - George Ragan aka Johnny 3 Tears |
|
|
| Report Abuse |
|
|
|
| 29 Nov 2013 01:03 PM |
ok w/e echo
I think the point got across anyway. |
|
|
| Report Abuse |
|
|
|
| 29 Nov 2013 01:05 PM |
@duel
No, it didn't. You were giving false information. |
|
|
| Report Abuse |
|
|
KEVEKEV77
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 6961 |
|
|
| 29 Nov 2013 01:09 PM |
You can also use them to get information form a table A table is a configuration of different thing.
ex:
local myfirsttable = {1,2,3,4,6,2} -- use the {} to make a table print (myfirttable[5]) -- this will print 6, because it is the 5th one
|
|
|
| Report Abuse |
|
|
|
| 29 Nov 2013 01:11 PM |
It still can be called an array, >just verified
however you are right with the brackets |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 29 Nov 2013 01:11 PM |
@Ek
Ohhh. I already knew about arrays. I never knew you called them tables in Lua
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
|
| 29 Nov 2013 01:13 PM |
How do all of these people new to Lua have Bloxy's?
How were the obtained? |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
|
| 29 Nov 2013 01:20 PM |
>How were the obtained?
Illegally.
"Don't Panic"- HHGTTG |
|
|
| Report Abuse |
|
|
skyarex
|
  |
| Joined: 21 Mar 2010 |
| Total Posts: 12989 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
Ekkoh
|
  |
| Joined: 22 Oct 2012 |
| Total Posts: 524 |
|
|
| 30 Nov 2013 10:15 PM |
OP got banned...
"We can walk a million miles, and end up in the sea." - George Ragan aka Johnny 3 Tears |
|
|
| Report Abuse |
|
|