compy111
|
  |
| Joined: 02 Apr 2009 |
| Total Posts: 583 |
|
|
| 13 Feb 2015 10:05 AM |
In my game you'll be able to build your own space ship, set engines on it, choose hotkeys and do objectives. So in the control script of the ship we need to make a table out of all engines used and their hotkeys. The key is stored in a StringValue inside of the engine model.
local parts = ship:GetChildren() --These are all parts of the ship, engines are models local enginelist = {nil} local keylist = {nil} for a = 1,#parts do if parts[a].Name == "Engine" then --If the child is named Engine print("Engine found") enginelist[a] = parts[a] --add the engine to the enginelist keylist[a] = parts[a].Key.Value --add the key to the keylist end end print("Keylist: "..table.concat(keylist,", ")) --Print the table
Output of ship with 4 engines: Engine found Engine found Engine found Engine found Keylist:
It clearly says it find the engines but he doesn't want to put the keys into a table. |
|
|
| Report Abuse |
|
|
| 13 Feb 2015 10:08 AM |
"enginelist[a] = parts[a]" No.
table.insert(enginelist, parts[a])
You do not need to put nil as the first value in the table, just do {}. |
|
|
| Report Abuse |
|
compy111
|
  |
| Joined: 02 Apr 2009 |
| Total Posts: 583 |
|
|
| 13 Feb 2015 10:10 AM |
| Thanks, got a correct output now |
|
|
| Report Abuse |
|