iJarvis
|
  |
| Joined: 12 May 2015 |
| Total Posts: 105 |
|
|
| 10 Nov 2015 05:23 AM |
Just like 2D arrays in C++, for example:
char array[3][3];
Please help thanks :D
--iJarvis, first account from 2011 |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 05:25 AM |
| Sorry, on Roblox, I only script in RBX.Lua. If you want another scripting language maybe you should look on a site for that language, or learn to do it yourself. There are plenty fo C++ scripts out there on the internet all you have to do it copy paste. |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
| |
|
|
| 10 Nov 2015 05:33 AM |
| Maybe if you explain what "char array[3][3];" does.... |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 10 Nov 2015 05:35 AM |
| It's probably table[index][index] |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 06:02 AM |
Ahh yes, that makes sense, the [3][3] had me confused... Well tables index their variables automatically as numbers, though you can index them as variables themselves:
local newTable={"hi",1,true,{"wee"}}
print(newTable[1])--Prints hi print(newTable[2])--Prints 1 print(newTable[3])--Prints true print(newTable[4])--Prints the number the table has been given by the game print(newTable[4][1])--Prints wee |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 06:06 AM |
Indexing variabes:
local newTable={wooooow='HAH'}
print(newTable[1])--Prints nil print(newTable.wooooow)--Prints HAH
for a=1,#newTable do print(newTable[i]) end
--Will print nil
for a,b in pairs(newTable) do print(b) end
--Will print HAH |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 06:27 AM |
vlek... You forgotten my PMs are always open for these simple problems?
In order to index something it has to be an array, so to index [3] of array[3], it means array[3] must be an array as well. I assume you're looking for something like this?
array = { {1,2,3}, {4,5,6}, {7,8,9} }
for i = 1, 3 do for ii, = 1, 3 do print(array[i][ii]) end end |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 06:33 AM |
| What I said comes first before learning a more in depth approach to arrays in RBX.Lua because the way to "sort" the array is different in RBX.Lua than other languages, so it's important to learn how the array loops work in order to learn how to search for indexes inside the arrays. What you said will come in handy for him to learn once he has learned what I said. By that point he would have almost learned about meta tables. |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 10 Nov 2015 06:48 AM |
| Yeah got that after I saw it, but I imagined having a second value or something. |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 04:26 PM |
@robert Since you were happy enough to respond to me, I'll gladly point out some things about your post...
Which would be:
" Indexing variabes:
local newTable={wooooow='HAH'}
print(newTable[1])--Prints nil print(newTable.wooooow)--Prints HAH
for a=1,#newTable do print(newTable[i]) end
--Will print nil
for a,b in pairs(newTable) do print(b) end
--Will print HAH "
First of all, you failed to mention why newTable[1] (assuming it ran, and i was a number) would fail. It is because there are no numerical indices.
AND you didn't mention why .wooooow would work. It's because there IS an index like that.
Extra information: {['wooooow']='HAH'} can be used, using wooooow='HAH' is simply syntax sugar for strings. You have to use [] for diff. values.
Secondly, On your first loop you used 'i', which you didn't define, I assume you meant a?
Thirdly, it wouldn't print nil, because #newTable is 0. So you tried to do a for loop like
for a = 1, 0 do
Does that make any sense? No, it wouldn't print ANYTHING.
You also neglected to mention why #newTable is 0. If you're going to explain anything, at least explain it properly. It is because the # operator counts the numerical indices, which also means it expects to be used on an array.
You also didn't explain the pairs loop, which loops through key,value pairs and how a,b was the key,value pairs.
Also saying that learning dictionaries comes really close to metatables prove how little you know about tables. Many people don't even learn metatables, because they have little use. Metatables are NOT difficult, however they by NO means comes directly after dictionaries.
Dictionaries are BASIC. |
|
|
| Report Abuse |
|
|
lah30303
|
  |
| Joined: 15 Feb 2008 |
| Total Posts: 10027 |
|
|
| 10 Nov 2015 06:00 PM |
| Dictionaries do bring you closer to learning about metatables though because special keys for metatables are all dictionary keys. There's not much more to learn about tables other than metatables once you learn about the difference between dictionary part and the array part and how it assigns values to either of those. Getting a proper understanding of lua's for loops and how pairs works is a separate topic imo and is not required before learning metatables. |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 07:18 PM |
| Warspyking, he obviously knows the basics of scripting so he did not need me to explain anything in detail, and yes the i was a typo, yet again, he obviously knew enough about scripting to know I made a typo, it happens, especially here in the forums because it does not tell you that you are trying to call a global variable that doesn't exist. Do me a favor and keep your commentary to yourself when it comes to correcting me kid, I've been around longer than anyone else in the scripting forums. I don't need a wanna be pointing out a typo or pointing out that I didn't go into depth as to WHY my script works. If I felt like he was a nub to scripting, I might have gone in depth and explained why it was working the way it was, but he knew what indexing was otherwise he wouldn't have asked the question "Anyone who knows how to make a 2D array in Lua?". Go bother someone else now, thanks. |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 10 Nov 2015 07:21 PM |
"I've been around longer than anyone else in the scripting forums."
And still haven't learned anything. Welcome back again, nice to see you again after six years since your true activity.
Don't use your duration of membership as a weapon. It's a blunt edge. Show something more than your lack of wisdom. |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 07:27 PM |
local function newGrid(x,y) local t = {} for i=1,y do for i=1,x do table.insert(t,{}) end end return t end
local 2dArray = newGrid(2,3)
Instance.new("BodyVelocity",SenseiWarrior).velocity = CFrame.new(SenseiWarrior.Torso.Position,YourGirlsDMs.Position).lookVector * 10 |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 07:34 PM |
| I'm not really using it as a weapon, simply stating a fact that I have been around and seen more than the average bear. It says enough to state that I'm not new to helping people, and yes it has been a while since I was truly active, I go back and forth from scripting to being busy with rl. Your "ROBLOX Wiki Staff" group set as your main group to be visible here in the forums is just as much a weapon of words as my time on roblox forums being being said. You say I haven't learned anything as if you knew me then and you know me now, but your name is one I've never heard of. 26689 posts and never heard of... This must mean that you are not originally from the scripting forum, but rather another genre. You obviously didn't know me 6 years ago, thus making your entire statement of me learning anything invalid. |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 10 Nov 2015 07:37 PM |
| He's MrNicNac/DrMathematica |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 10 Nov 2015 07:38 PM |
"Your "ROBLOX Wiki Staff" group set as your main group to be visible here in the forums is just as much a weapon of words as my time on roblox forums being being said. You say I haven't learned anything as if you knew me then and you know me now, but your name is one I've never heard of. 26689 posts and never heard of... This must mean that you are not originally from the scripting forum, but rather another genre."
I'm crying rite nao. Look at my previous usernames ("MrNicNac") then look here: http://forum.roblox.com/Forum/ShowPost.aspx?PostID=38653403
omg i feel so left out because the great robertoman doesn't no me. i cri |
|
|
| Report Abuse |
|
|
nox7
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 27467 |
|
|
| 10 Nov 2015 07:41 PM |
@Robertoman
Just be careful before you open that ignorant mouth of yours :P It seems time has only dulled your intelligence. Now.... come at me :P |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 07:41 PM |
| Oh yes MrNicNac, I recognize that name. Now I understand why you are attacking me for only defending myself in the first place. You always did like a gank. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 10 Nov 2015 07:50 PM |
| roberto you're stupid, shut up. |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 08:01 PM |
| Really, getting attacked by you too. How many people does it take to screw in a light bulb? Mind backing off and minding your own business? If you aren't helping the forum post in any way, keep your opinions to yourself. Really... |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 10 Nov 2015 08:03 PM |
"Do me a favor and keep your commentary to yourself when it comes to correcting me kid, I've been around longer than anyone else in the scripting forums. I don't need a wanna be pointing out a typo or pointing out that I didn't go into depth as to WHY my script works." "I'm not really using it as a weapon, simply stating a fact that I have been around and seen more than the average bear. It says enough to state that I'm not new to helping people, and yes it has been a while since I was truly active, I go back and forth from scripting to being busy with rl. Your "ROBLOX Wiki Staff" group set as your main group to be visible here in the forums is just as much a weapon of words as my time on roblox forums being being said. You say I haven't learned anything as if you knew me then and you know me now, but your name is one I've never heard of." "Just be careful before you open that ignorant mouth of yours :P It seems time has only dulled your intelligence. Now.... come at me :P" That is why I called you stupid, if you aren't stupid you won't act the part. |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 08:07 PM |
| Look, I'm tired of being attacked. Help people and leave me alone, or be quiet. Enough is enough is what I'm saying. |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2015 08:29 PM |
@roberto I didn't say anything offensive.
And btw, metatables would NOT be the last thing about tables you learn. I would argue that weak tables would be. (There may be other advanced things, but that's more opinionated) |
|
|
| Report Abuse |
|
|