badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 03:14 PM |
guns[v.Name] = {v.Stats.Damage.Value, v.Stats.Accuracy.Value, v.Stats.GunType.Value, v.Stats.Firerate.Value} is there a way I can give a name to each table position (like I can get accuracy by going: guns[gun.Name].Accuracy)
if so tell me how
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 03:18 PM |
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
CscLambda
|
  |
| Joined: 09 Nov 2014 |
| Total Posts: 46 |
|
|
| 21 Aug 2015 03:18 PM |
When you declare the table:
guns = { ["A Gun"] = { ["Damage"] = 3.141 ["Accuracy"] = ... },
... }
|
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 03:19 PM |
i have a bunch of guns
do you honestly think I'm going to write down each gun with the 5+ variables inside them
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
ohno1112
|
  |
| Joined: 23 Mar 2013 |
| Total Posts: 833 |
|
|
| 21 Aug 2015 03:20 PM |
| scripting is not pressing 1 button and having an entire system done. work is required. |
|
|
| Report Abuse |
|
|
|
| 21 Aug 2015 03:21 PM |
for k,z in pairs(v:GetChildren()) do guns[v.Name][z.Name] = z.Value end
Something like that? while true do the do |
|
|
| Report Abuse |
|
|
CscLambda
|
  |
| Joined: 09 Nov 2014 |
| Total Posts: 46 |
|
|
| 21 Aug 2015 03:21 PM |
It's applicable to setting as well:
guns[v.Name] = { ["Damage"] = v.Stats.Damage.Value, ["Accuracy"] = v.Stats.Accuracy.Value, ["GunType"] = v.Stats.GunType.Value, ["FireRate"] = v.Stats.Firerate.Value } |
|
|
| Report Abuse |
|
|
CscLambda
|
  |
| Joined: 09 Nov 2014 |
| Total Posts: 46 |
|
|
| 21 Aug 2015 03:23 PM |
| What @morashsPeasant was saying is a shorter way if your table names are the same as your variable names. |
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 03:23 PM |
"scripting is not pressing 1 button and having an entire system done. work is required."
did you even read the thread
guns[v.Name] = {v.Stats.Damage.Value, v.Stats.Accuracy.Value, v.Stats.GunType.Value, v.Stats.Firerate.Value}
i've already made it so it creates a dictionary for each gun, it's tedious to write down a new v.ValueObject.Value everytime i want to add a stat. Putting the stats automatically in using :GetChildren() will ruin my script because I do:
guns[gun.Name][stat position number]
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 03:24 PM |
@Csc
thanks, but I'd still have to add a new line for each stat i add
and I'm starting to add a lot of stats
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
CscLambda
|
  |
| Joined: 09 Nov 2014 |
| Total Posts: 46 |
|
|
| 21 Aug 2015 03:25 PM |
| But that's the point of @morashsPeasant's script. It DOES put names for the table entries. |
|
|
| Report Abuse |
|
|
|
| 21 Aug 2015 03:26 PM |
@OP, create a folder inside the gun called properties And everytime you loop through guns, ALSO loop through the properties and put their data into the dictionary. And DONT EVER SET YOUR variables in stone. What are you going to do if you have to add another property? Go back and add 40 more lines??
while true do the do |
|
|
| Report Abuse |
|
|
CscLambda
|
  |
| Joined: 09 Nov 2014 |
| Total Posts: 46 |
|
|
| 21 Aug 2015 03:26 PM |
| Whoops, ignore previous post, posted before I saw your reply |
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 03:27 PM |
didn't see his. thank you!
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
CscLambda
|
  |
| Joined: 09 Nov 2014 |
| Total Posts: 46 |
|
|
| 21 Aug 2015 03:27 PM |
| I think you should use @morashasPeasant's method |
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 03:29 PM |
@morash
i am literally doing what you just said lol
yours works fine, thank you <33
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
| |
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 03:46 PM |
wait does morash's script add the table values & stuff?
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
|
| 21 Aug 2015 03:49 PM |
Yes, it creates a string index based on the property's name
while true do the do |
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 03:51 PM |
so if i wanted to damage a player depending on a stat
lets assume the stats name is damage(why are we assuming that's literally what it's called :\/\/\/\/\)
hum:TakeDamage(guns[gun.Name]["Damage"].Value)
would get "Damage" from the table and deal damage depending on it's value
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
|
| 21 Aug 2015 03:59 PM |
Since only the .Value property of the Damage object is inside the table you could go like this: hum:TakeDamage(tonumber(guns[gun.Name]["Damage"]))
while true do the do |
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 04:03 PM |
getting a nil value error
for _, v in pairs(game:GetService("ReplicatedStorage"):GetChildren()) do for k,z in pairs(v.Stats:GetChildren()) do guns[v.Name][z.Name] = z.Value end end
from this
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 04:05 PM |
wait error is:
22:02:47.038 - Players.Player1.PlayerGui.ScreenGui.Main:59: attempt to index field '?' (a string value) 22:02:47.039 - Stack Begin 22:02:47.039 - Script 'Players.Player1.PlayerGui.ScreenGui.Main', Line 59 22:02:47.039 - Stack End
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|
|
| 21 Aug 2015 04:05 PM |
How are you structuring your objects?
while true do the do |
|
|
| Report Abuse |
|
|
badfitz60
|
  |
| Joined: 03 Sep 2010 |
| Total Posts: 1283 |
|
|
| 21 Aug 2015 04:07 PM |
local guns = { } -- create dictionary for all guns and their stats
empty dictionary
for _, v in pairs(game:GetService("ReplicatedStorage"):GetChildren()) do for k,z in pairs(v.Stats:GetChildren()) do guns[v.Name][z.Name] = z.Value end end
the place where the dictionary should have things put into it
Your brain's the only thing with stretch marks |
|
|
| Report Abuse |
|
|