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: Dictionary - wat.

Previous Thread :: Next Thread 
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 01:42 PM
My dictionary:

local EngDictionary = {
["Plasma expulsion exhaust"] = 20,
["Plasma ignition ports"] = 35,
["Spacetime impulse drive"] = 45,
["Spacial elastic catapult"] = 60,
["Quantum slipstream drive"] = 75,
["Spacetime compresser"] = 90,
}
My print:
print(EngDictionary[3])
> Prints nil

Wat.
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
03 Sep 2014 01:52 PM
You are using a key-value table (similar to a Map in other programming languages). This means that it is not ordered, so EngDictionary[3] or #EngDictionary will not work. You can, however, do this: print(EngDictionary["Plasma expulsion exhaust"]) --> 20
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 01:56 PM
That wont work for what I'm doing.
How do I order it?
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
03 Sep 2014 02:15 PM
local EngDictionary = {
{["Plasma expulsion exhaust"], 20},
{["Plasma ignition ports"], 35},
etc
}

print(EngDictionary[1][1]) -- [#][1] for name, [#][2] for number
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 02:26 PM
Still printing nil.

local EngDictionary = {
{["Plasma expulsion exhaust"] = 20},
{["Plasma ignition ports"] = 35},
etc
}

print(EngDictionary[1][1])
>Nil

I could swear it was working two days ago.
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
03 Sep 2014 02:34 PM
Oops sorry I did a bit wrong.

{"Plasma expulsion exhaust", 20},
{"Plasma ignition ports", 35},

That is how you put int he elements. Don't forget to add your other ones and get rid of the "etc"
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 02:43 PM
Wunderbar

One last question :L

My plan is to correlate the name of a value to a dictionary entry.
For example:

Value's name is "Spacetime compresser"
How would I get it to search for a dictionary entry which is equal to the value's name?
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
03 Sep 2014 02:48 PM
You would do what you did the first time.

local EngDictionary = {
["Plasma expulsion exhaust"] = 20,
["Plasma ignition ports"] = 35,
["Spacetime impulse drive"] = 45,
["Spacial elastic catapult"] = 60,
["Quantum slipstream drive"] = 75,
["Spacetime compresser"] = 90,
}

local val = "Plasma expulsion exhaust"
local cost = EngDictionary[val]
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 02:54 PM
Yes, I know.
The problem is that when I tried that it didn't work which is how this started.
:L
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
03 Sep 2014 02:57 PM
Ah, well then you can do this with the new version of your table:

local find = "Item name to find"
for i, item in pairs(EngDictionary) do
if item[1] == find then
return item[2] -- Return the cost
end
end

Also, remember that pairs can be used to search through key-value tables, so if finding all the products was your problem you could always use that.
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 03:12 PM
It repeats the find for the entire dictionary.


local find = engine
for i, item in pairs(EngDictionary) do
if item[1] == find then
return item[2]
end
addspeed = item[2] --
print(addspeed)



engine == the value with the name in it which I want found in the dictionary
It prints all the [2]s, which means it's changing addspeed to all the values as it goes through them.
So I'm assuming it either doesn't know what v.Name is or is ignoring it.
Report Abuse
super10099 is not online. super10099
Joined: 30 Jan 2010
Total Posts: 1102
03 Sep 2014 03:20 PM
local EngDictionary = {
["Plasma expulsion exhaust"] = 20,
["Plasma ignition ports"] = 35,
["Spacetime impulse drive"] = 45,
["Spacial elastic catapult"] = 60,
["Quantum slipstream drive"] = 75,
["Spacetime compresser"] = 90,
}

print(EngDictionary["Plasma explusion exhaust"])
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 03:22 PM
@Super


Doesn't work, that was the first method.
:L
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 03:24 PM
I'm going to put us out of our misery and just use another independent value.
Report Abuse
super10099 is not online. super10099
Joined: 30 Jan 2010
Total Posts: 1102
03 Sep 2014 03:25 PM
Tell me why its not.
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
03 Sep 2014 03:26 PM
local find = engine
for i, item in pairs(EngDictionary) do
if item[1] == find then
return item[2] -- Stops the loop
end
addspeed = item[2] -- Is still in for loop, so it changes every value until the if condition is met and item[2] is returned.
print(addspeed)

Just add an end after the end closing the if statement.
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 03:28 PM
Because yours would work except what I'm doing is finding the name of a value, making it a variable and then searching for it which is apparently too much for the "best game making studio for beginners on the internet".
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
03 Sep 2014 03:36 PM
Thanks iiE

Had to twiddle that a bit but now it works.

THANK YOU EVERYBODY
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