generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Array help

Previous Thread :: Next Thread 
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
07 Dec 2013 01:34 PM
I'm trying to figure out a way to sort out things in a model

array = {}
for q, k in pairs(script.Parent.Model:children()) do
if not array[k.Name] then
array[k.Name] = 1
else
array[k.Name] = array[k.Name] + 1
end
end

Does this look right? Or are there any glaring errors?
Report Abuse
sunday1520 is not online. sunday1520
Joined: 23 Aug 2012
Total Posts: 693
07 Dec 2013 01:43 PM
I'm not exactly sure what your asking, can you possibly clarify the goal of this script. sort out things in a model is very vague, especially after looking at the script haha
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
07 Dec 2013 01:50 PM
Basically this counts out how many of an item with a certain name there is an a model.
If there are 10 objects in a model, with 4 potatos, 2 apples, 3 noobs and 1 gun,
I want it to be
{"potatos" = 4, "noobs" = 3, "gun" = 1, "apples" = 2}
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
08 Dec 2013 01:56 AM
erm?
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
08 Dec 2013 02:12 AM
List = {
["Carrot"] = 0,
["Potato"] = 0
}
Items = {"Carrot","Carrot","Potato"}

for _,p in pairs(Items) do
for i,v in pairs(List) do
if i == p then
List[i] = List[i] + 1
end
end
end

for i,v in pairs(List) do
print(i .. ": " .. v)
end
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
08 Dec 2013 02:13 AM
So, Erm, thanks to this I decided to stop being lazy and learned how dictionaries worked.
Report Abuse
PiggyJingles is not online. PiggyJingles
Joined: 13 Jan 2009
Total Posts: 2472
08 Dec 2013 02:17 AM
Aren't they basically arrays of set values or something?

Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
08 Dec 2013 02:37 AM
Pretty much. But the syntax of it is weird :L

I'm mainly concerned with this line

if not array[k.Name] then
array[k.Name] = 1

It seems weird. No red line, but somehow doesnt seem to run?
Report Abuse
PiggyJingles is not online. PiggyJingles
Joined: 13 Jan 2009
Total Posts: 2472
08 Dec 2013 02:38 AM
if not array[k].Name then
array[k].Name = 1
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
08 Dec 2013 02:50 AM
Wait...
You were asking if yours worked?
It should.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
08 Dec 2013 03:22 AM
Your script looks like it will work as intended. Let's look at an example:

Model
> Part
> Part
> Chuck
> Part
> Norris
> Chuck
> Hammer


array = {}
for q, k in pairs(script.Parent.Model:children()) do
if not array[k.Name] then
array[k.Name] = 1
else
array[k.Name] = array[k.Name] + 1
end
end

> Part not in array
> array.Part = 1
> Part in array
> array.Part = array.Part + 1
> Chuck not in array
> array.Chuck = 1
> Part in array
> array.Part = array.Part + 1
> Norris not in array
> array.Norris = 1
> Chuck in array
> array.Chuck = array.Chuck + 1
> Hammer not in array
> array.Hammer = 1
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image