|
| 27 Sep 2014 09:24 AM |
I honestly have no clue what I'm doing wrong here. It has no error. I use tuples the majority of the time but I never had to use a tuple this long. If anyone can figure this out that would be amazing. Thanks!
Event.OnServerEvent:connect(function(Player, ...) if Player then local tuple = {...} if tuple[1] == "Bought1" then if tuple[2] == "Upgrade1" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 4 then AwardCash(Player, -5) end elseif tuple[2] == "Upgrade2" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 7 then AwardCash(Player, -10) end elseif tuple[2] == "Upgrade3" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 12 then AwardCash(Player, -10) end elseif tuple[2] == "Upgrade4" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 16 then AwardCash(Player, -10) end elseif tuple[2] == "Upgrade5" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 21 then AwardCash(Player, -10) end elseif tuple[2] == "Upgrade6" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 9 then AwardCash(Player, -15) end elseif tuple[2] == "Upgrade7" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 15 then AwardCash(Player, -15) end elseif tuple[2] == "Upgrade8" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 19 then AwardCash(Player, -15) end elseif tuple[2] == "Upgrade9" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 36 then AwardCash(Player, -20) end elseif tuple[2] == "Upgrade10" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 48 then AwardCash(Player, -25) end end elseif tuple[1] == "Bought2" then if tuple[2] == "Texture1" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 3 then AwardCash(Player, -3) end elseif tuple[2] == "Texture2" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 7 then AwardCash(Player, -7) end elseif tuple[2] == "Texture3" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 9 then AwardCash(Player, -9) end elseif tuple[2] == "Texture4" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 13 then AwardCash(Player, -13) end elseif tuple[2] == "Texture5" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 16 then AwardCash(Player, -16) end elseif tuple[2] == "Texture6" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 19 then AwardCash(Player, -19) end elseif tuple[2] == "Texture7" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 23 then AwardCash(Player, -23) end elseif tuple[2] == "Texture8" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 29 then AwardCash(Player, -29) end elseif tuple[2] == "Texture9" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 34 then AwardCash(Player, -34) end elseif tuple[2] == "Texture10" then local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 39 then AwardCash(Player, -39) end end end end end) |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 09:29 AM |
"Tuple this long" But it only mentions two values.
This is a tuple:
1, 2, 3, 4, 5 "A", math.huge, 7.2, print
You only mentioned two values though...
Id est, you only go up to Tuple[2] |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 09:31 AM |
| I put multiple values, I know that lookes really bad saying that I use tuples the majority of the time. I'll try it again. Maybe the first time I was not doing something right. |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 09:32 AM |
| The first time I did, this was like a second attempt or a "why not" attempt because certain things I was doing did not work. |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 09:35 AM |
May I suggest a new data structure idea?
Stuff = {
["Item1"] = {
["Upgrade1"] = function(...) --Do stuff, return stuff end, ["Upgrade2"] = function(...) --Do stuff, return stuff end } ,
["Item2"] = {
["Upgrade1"] = function(...) --Do stuff, return stuff end, ["Upgrade2"] = function(...) --Do stuff, return stuff end } }
Then you only have to do Stuff [Tuple[1]] [Tuple[2]] (Arguments) instead of all of those conditionals.
|
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 09:36 AM |
Your script is so repetitive... why not use objects or similar??
Your problem is strange...
Let's check my brain...
Brain says you need to check to see if all the variables are sent.
A tuple like...
local function a(test, ...) local args = {...} print(test) print(args[1]) print(args[2]) end
will suit your needs. |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 09:53 AM |
Actually, the uncopylocked stolen versions of Deadzone have a similar problem. It's like the scripter had no idea what tables were.
if this or this or this or this or this or this or this or this or this then
I redid a large portion of that script using a Modulescript and tables and stuff, and made it much easier to read, edit and configure.
I still think you should do my idea, just to save room, and to make it easier on the eyes and easier to type. |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 09:54 AM |
@JarodOfOrbitor, I used your example. I could not finish it. Could you give me another example or even If I did anything wrong. From the way I saw your example this is what I did. I might have saw it wrong.
local tuple = {...} local Stuff = {
["Upgrades"] = { ["Upgrade1"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 4 then AwardCash(Player, -5) end end, ["Upgrade2"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 7 then AwardCash(Player, -10) end end, ["Upgrade3"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 12 then AwardCash(Player, -12) end end, ["Upgrade4"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 16 then AwardCash(Player, -12) end end, ["Upgrade5"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 21 then AwardCash(Player, -21) end end, ["Upgrade6"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 9 then AwardCash(Player, -9) end end, ["Upgrade7"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 15 then AwardCash(Player, -15) end end, ["Upgrade8"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 19 then AwardCash(Player, -19) end end, ["Upgrade9"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 36 then AwardCash(Player, -36) end end, ["Upgrade10"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 48 then AwardCash(Player, -48) end end, }
["Retextures"] = { ["Texture1"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 3 then AwardCash(Player, -3) end end, ["Texture2"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 7 then AwardCash(Player, -7) end end, ["Texture3"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 9 then AwardCash(Player, -9) end end, ["Texture4"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 13 then AwardCash(Player, -13) end end, ["Texture5"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 16 then AwardCash(Player, -16) end end, ["Texture6"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 19 then AwardCash(Player, -19) end end, ["Texture7"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 23 then AwardCash(Player, -23) end end, ["Texture8"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 29 then AwardCash(Player, -29) end end, ["Texture9"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 34 then AwardCash(Player, -34) end end, ["Texture10"] = function(...) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 39 then AwardCash(Player, -39) end end } } end end) |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 09:58 AM |
| I'll have an example for you soon, I won't post it on the forums. |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 10:07 AM |
Nevermind, I'm too lazy to upload the model. Textures = { ["Texture1"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 3 then AwardCash(Player, -3) end end, ["Texture2"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 7 then AwardCash(Player, -7) end end, --Et cetera }
Event.OnServerEvent:connect(function(Player, ...) if Player then local tuple = {...} if tuple[1] == "Bought1" then --Add the same feature for upgrades, using a table called Upgrades, or something. elseif tuple[1] == "Bought2" then Textures[tuple[2]](Player) --This will work as long as tuple[2] is either "Texture1" or "Texture2", as seen on lines 2 and 8. end end end) |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 10:10 AM |
| Okay, I see. Thank you. I'll try this out. |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 10:12 AM |
local CashTable = { 1 = 4; 2 = 7; 3 = 12; 4 = 16; 5 = 21; 6 = 9; 7 = 15; 8 = 19; 9 = 36; 10 = 48; }
local upgrade = function(player, level) AwardPlayer(player, CashTable[level]) end |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 10:33 AM |
Still not working, I probably did something wrong.
Upgrades = { ["Upgrade1"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 3 then AwardCash(Player, -4) end end, ["Upgrade2"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 7 then AwardCash(Player, -7) end end, ["Upgrade3"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 9 then AwardCash(Player, -9) end end, ["Upgrade4"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 12 then AwardCash(Player, -12) end end, ["Upgrade5"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 16 then AwardCash(Player, -16) end end, ["Upgrade6"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 9 then AwardCash(Player, -9) end end, ["Upgrade7"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 15 then AwardCash(Player, -15) end end, ["Upgrade8"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 19 then AwardCash(Player, -19) end end, ["Upgrade9"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 36 then AwardCash(Player, -36) end end, ["Upgrade10"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 48 then AwardCash(Player, -48) end end }
Textures = { ["Texture1"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 3 then AwardCash(Player, -3) end end, ["Texture2"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 7 then AwardCash(Player, -7) end end, ["Texture3"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 9 then AwardCash(Player, -9) end end, ["Texture4"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 13 then AwardCash(Player, -13) end end, ["Texture5"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 16 then AwardCash(Player, -16) end end, ["Texture6"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 19 then AwardCash(Player, -19) end end, ["Texture7"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 23 then AwardCash(Player, -23) end end, ["Texture8"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 29 then AwardCash(Player, -29) end end, ["Texture9"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 34 then AwardCash(Player, -34) end end, ["Texture10"] = function(Player) local DataCollection = PlayerData[Player.userId] if DataCollection and DataCollection.Cash >= 41 then AwardCash(Player, -41) end end }
Event.OnServerEvent:connect(function(Player, ...) if Player then local tuple = {...} if tuple[1] == "Bought1" then Upgrades[tuple[2]](Player) --I put them all here because I was not sure if it automatically would know which tuple to fire... Upgrades[tuple[3]](Player) Upgrades[tuple[4]](Player) Upgrades[tuple[5]](Player) Upgrades[tuple[6]](Player) Upgrades[tuple[7]](Player) Upgrades[tuple[8]](Player) Upgrades[tuple[9]](Player) Upgrades[tuple[10]](Player) Upgrades[tuple[11]](Player) elseif tuple[1] == "Bought2" then Textures[tuple[2]](Player) --I put them all here because I was not sure if it automatically would know which tuple to fire... Textures[tuple[3]](Player) Textures[tuple[4]](Player) Textures[tuple[5]](Player) Textures[tuple[6]](Player) Textures[tuple[7]](Player) Textures[tuple[8]](Player) Textures[tuple[9]](Player) Textures[tuple[10]](Player) Textures[tuple[11]](Player) end end end) |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 11:04 AM |
| I can see this making the code more efficient but not actually fixing the problem @people is having... |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 11:13 AM |
| I mean, I understand efficiency is great to have but that's not really what he asks nor does it solve the issue. I can't help, but I'm just trying to point something out. Maybe no one can solve this issue so they use efficiency to try to see if that may or may not solve the problem. |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2014 11:39 AM |
| This is not fixable? If I'm doing it wrong could someone at least correct me? |
|
|
| Report Abuse |
|
|