|
| 14 Oct 2014 12:35 PM |
_G["RankInsignias"] = { 182266628, 182266663, 182266680, 182266706, 182266719, 182266737, 182266759, 182266784, 182266819, 182266832, 182266847, 182266901 }
You get the 1st insignia at lvl 1. You get the 2nd insignia at lvl 10. You get the 3rd insignia at lvl 20. 12th at 120 if (lvl >= 1 and level < 10) then insignia[1]
see where im goin with this?
I could do a ton of IF lines, but I was hoping there was a more compact way of doing it. o.o |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 14 Oct 2014 12:39 PM |
Hmm... You could reduce it a little, you know? Give the insignias keys, respective of their required level, and do this for k,v in pairs(_G.RankInsignias) do if lvl > k then v end end
Result will be that at the end, it will have repeated it to the highest you can get to. Just do something with v okay |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2014 12:52 PM |
um
local insignia = _G.RankInsignias[level] |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2014 12:58 PM |
foreverdev no, because then theyd end up with fleet admiral at lvl 12, which is totally wrong. O.o
eLunate, this?
_G["RankInsignias"] = { [1] = 182266628, [10] = 182266663, [20] = 182266680, [30] = 182266706 }
i dont know what you mean by keys unfortunately. tables are still rather new to me |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2014 12:58 PM |
oh my bad i didnt read the whole question.. maybe you could put each insignia into it's own table, along with another integer that contains the level required... for example:
local insignias = { {182266628, 1}, --insignia ID, level required {182266663, 10}, {182266680, 20} }
local getInsignia = function(level) for i = 1, #insignias do --not using pairs loop for a reason if level == insignias[i][2] then return insignias[i][1] elseif level < insignias[i][2] then return insignias[i - 1][1] end end return insignias[1][1] --catch any possible errors? end
print(getInsignia(20)) --182266680 print(getInsignia(11)) --182266663 print(getInsignia(1)) --182266628 |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2014 01:06 PM |
| Now see that's a bunch of If statements. I'm trying to avoid that. |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2014 01:24 PM |
Emm....
What's the big deal with if statements?
I mean, you could use a repeat loop if you WANTED to.
local ins = { {"ID1", 1}, {"ID2", 10}, {"ID3", 20}, {"ID4", 50}, {"Place holder", math.huge} --this needs to be here, too lazy to debug }
function getIns(level) local index = 0 local id = ins[1][1] repeat index = index + 1 id = (level >= ins[index][2] and level < ins[index + 1][2]) and ins[index][1] or id until index == #ins return id end
print(getIns(1)) -- ID1 print(getIns(11)) -- ID2 print(getIns(21)) --ID3 print(getIns(55)) --ID4 print(getIns(10230)) --ID4
No if statements. Happy?
|
|
|
| Report Abuse |
|
|
|
| 14 Oct 2014 01:37 PM |
I'm not trying to sound ungrateful. I appreciate any help I can get. I'm trying to keep the function as short as possible by removing as many if statements as I can, plus I don't even understand what you're doing in the function which makes it impossible for me to modify later on if I see that the levels are unbalanced. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 14 Oct 2014 04:09 PM |
_G["RankInsignias"] = {1 = someid, 10 = someid, 20 = someid, 25 = someid, 40 = someid, 50 = someid, 65 = someid} etc My code will then go through those and do something with the ID so long as the player's level is higher than the key supplied |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2014 04:14 PM |
_G["RankInsignias"][math.floor(level/10)]
Why not just do this since you're doing every 10 levels??
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 14 Oct 2014 04:18 PM |
| Works reasonably until you want to change it to a level not a multiple of 10. Also lvl 1 would be index 0, which by default Lua tables don't use |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2014 04:24 PM |
Sorry... Since you get the 2nd one and not the 1st one at 10 etc..
if level < 10 then _G["RankInsignias"][1] else _G["RankInsignias"][math.floor(level/10)+1] end
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|