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
|
  |
| 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
|
  |
| 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 |
|
|
| |
|
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
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
| |
|
|
| 24 May 2012 04:37 PM |
Okay can you give the exact output? (Line #, Location, Etc.) |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 24 May 2012 05:10 PM |
| That one probably won't work, minor changes. |
|
|
| Report Abuse |
|
|
|
| 24 May 2012 05:12 PM |
| Nvm don't use that. Let's see if I can fix this. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 21 Apr 2012 |
| Total Posts: 671 |
|
|
| 24 May 2012 08:04 PM |
Got it to work. :D
MrMcAero |
|
|
| Report Abuse |
|
|
|
| 24 May 2012 08:10 PM |
| I'm going to check out your tycoon place. :3 |
|
|
| Report Abuse |
|
|
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 |
|
|