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: Why does this not work? Rage.

Previous Thread :: Next Thread 
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 04:16 PM
So I can't seem to get a number out of a table. D:

_G["myTable"] = {
["cost"] = 100
}
_G["money"] = 1000

if _G["money"] ​>= _G["myTable"]["cost"] then
print("Yes!")
end

Why this no work? D:?


MrMcAero
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 04:17 PM
Real code:

moneyCost = {
["coalMine"] = 750,
["copperMine"] = 1250,
["silverMine"] = 2000,
["goldMine"] = 3000,
["windMill"] = 5000,
}

money = 1000
_G["curBldng"] = "coalMine"

if money.Value ​>= moneyCost[_G["curBldng"]] then
money.Value = money.Value - moneyCost[_G["curBldng"]]
end


MrMcAero
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 04:18 PM
Basically I have a variable that changes, it's a string variable, and instead of doing a bunch of if statements I want it to look at the variable curBldng, then look at the table and find that value of curBldng, then subtract it from the money value, but I get an error of "triyng to compare nil with a number".

MrMcAero
Report Abuse
thecaptain97 is not online. thecaptain97
Joined: 17 Jun 2010
Total Posts: 4987
24 May 2012 04:22 PM
No need to Rage.
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 04:22 PM
That's not help. I've posted about this problem and no one helps.

MrMcAero
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 04:33 PM
Bump.

MrMcAero
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
24 May 2012 04:37 PM
Okay can you give the exact output?
(Line #, Location, Etc.)
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 04:40 PM
the line where I subtract moneyCost[_G["curBldng"]]

MrMcAero
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
24 May 2012 05:09 PM
moneyCost = {
coalMine = 750,
copperMine = 1250,
silverMine = 2000,
goldMine = 3000,
windMill = 5000
}

money = 1000
_G["curBldng"] = coalMine

if money.Value ​>= moneyCost[_G["curBldng"]] then
money.Value = money.Value - moneyCost[_G["curBldng"]]
end
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
24 May 2012 05:10 PM
That one probably won't work, minor changes.
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
24 May 2012 05:12 PM
Nvm don't use that. Let's see if I can fix this.
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
24 May 2012 07:45 PM
coalMineCost = 750
copperMineCost = 1250
silverMineCost = 2000
goldMineCost = 3000
windMillCost = 5000

money = 1000

_G["curBldng"] = coalMineCost

if money >= _G["curBldng"] then
money = money - _G["curBldng"]
end

That works. Your welcome. :3
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 07:50 PM
@Jellyfish403

I knew that would work, it's just I didn't want all the variables. Oh well, it'll do.

MrMcAero
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
24 May 2012 07:55 PM
When life gives you lemons, make lemonade.

And you would still have to set all the prices in the table so why would setting a lot of variables be different?
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 07:59 PM
Well, here's why:

When I click the mouse it's suppose to place a brick at the mouse's location. BUT I want the placing cost money, and I need a table, cause placement is about 50 lines of code, and for each part option I can't copy/paste those 50 lines of code. So I need a table that my code can look through. But I think I know another way to this. :\

MrMcAero
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
24 May 2012 08:03 PM
# of values in table
=
# of variables doing it my way (I think)

Actually I think theres another way to do this.
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 08:04 PM
Got it to work. :D

MrMcAero
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
24 May 2012 08:10 PM
I'm going to check out your tycoon place. :3
Report Abuse
MrMcAero is not online. MrMcAero
Joined: 21 Apr 2012
Total Posts: 671
24 May 2012 08:12 PM
Lol, I haven't updated it yet to fit all the places. Still configuring it. I'll PM you when it works.

MrMcAero
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