Keltrin
|
  |
| Joined: 01 Jan 2014 |
| Total Posts: 2085 |
|
|
| 19 Mar 2017 12:29 PM |
My in-game level system resets your EXP when you level up and adds on 100 to the current level margin
So level 1 needs 100 EXP, level 2 needs 200, level 13 needs 1300, etc.
How can I generate the total amount of EXP a player has accumulated using their current EXP and their current level?
|
|
|
| Report Abuse |
|
|
galvinio
|
  |
| Joined: 30 Jun 2011 |
| Total Posts: 222 |
|
|
| 19 Mar 2017 12:30 PM |
level * 100 + current xp???
|
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Mar 2017 12:33 PM |
(level - 1)! * 100 + currentXP*
|
|
|
| Report Abuse |
|
|
|
| 19 Mar 2017 12:34 PM |
Obviously that won't work for level 1 since 0! is 1 so work around that
|
|
|
| Report Abuse |
|
|
Keltrin
|
  |
| Joined: 01 Jan 2014 |
| Total Posts: 2085 |
|
|
| 19 Mar 2017 12:44 PM |
Are you sure that'll work? Cuz the EXP resets after each level up so I'd imagine the grand total would be pretty large
|
|
|
| Report Abuse |
|
|
|
| 19 Mar 2017 12:47 PM |
oh I'm stupid I thought of it a different way let me write something
|
|
|
| Report Abuse |
|
|
|
| 19 Mar 2017 12:51 PM |
local function accumulate(amount) if amount >= 1 then return amount * 100 + accumulate(amount - 1) else return amount end end
local total = accumulate(currentLevel - 1) + currentXP
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 19 Mar 2017 01:08 PM |
What are yas on about??? He said he needs 100 xp to level up to lvl 1, 200 to lvl 2, 1300 to lvl 13, etc...
XpNeeded = NewLevel * 100
That is all ya need.
|
|
|
| Report Abuse |
|
|
|
| 19 Mar 2017 01:09 PM |
Did you even read the OP? That's obviously not what they asked for. Here, let me quote:
"How can I generate the total amount of EXP a player has accumulated using their current EXP and their current level?"
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 19 Mar 2017 01:17 PM |
Ah right, that's simple too.
Accumulated = (Level - 1) * 100 + CurrentXp
|
|
|
| Report Abuse |
|
|
|
| 19 Mar 2017 01:18 PM |
that doesn't need a recursive function..
So level 1 needs 100 EXP, level 2 needs 200, level 13 needs 1300, etc.
local TotalXP = CurrentXP; for i = CurrentLevel,1,-1 do TotalXP = TotalXp + i*100; end;
as for level 5 you'd need CurrentXP + 500 + 400 + 300 + 200 + 100
I wonder if you could do this without a loop at all.
20,851 |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2017 01:18 PM |
Kap, I think you have a brain disorder.
20,851 |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2017 01:20 PM |
| Technically, any way you do it, there will be a loop, as you iterate over some structure. Even if it's not technically a loop as far as lexing goes, there will always be some form of a computational loop |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2017 01:21 PM |
of course, but you needn't form any sort of loop in lua.
20,853 |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 19 Mar 2017 01:24 PM |
How I hate myself sometimes... forgot that all the previous levels have to be added too...
So recursion would be 1 of the ways... though I forgot another way that could be used to get around this.
|
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 19 Mar 2017 01:26 PM |
Um... no... I do admit, I am a bit dumb ATM, but that's cos it's hard to get my attention right now, am in pain and pretty exhausted... and of course overthinking a couple of things.
|
|
|
| Report Abuse |
|
|
|
| 19 Mar 2017 01:38 PM |
level = 5 currentxp = 50 local total = 0 for i=1,level-1,1 do total = total + (i*100) end
total = total + currentxp
print(total) |
|
|
| Report Abuse |
|
|
galvinio
|
  |
| Joined: 30 Jun 2011 |
| Total Posts: 222 |
|
|
| 19 Mar 2017 01:58 PM |
oh wow i completely missed the each level requires more bit woops
|
|
|
| Report Abuse |
|
|
cars37
|
  |
| Joined: 27 Nov 2013 |
| Total Posts: 189 |
|
|
| 19 Mar 2017 02:08 PM |
l is current level x is current exp
(1+2+3...+(l-1))*100+x |
|
|
| Report Abuse |
|
|
galvinio
|
  |
| Joined: 30 Jun 2011 |
| Total Posts: 222 |
|
|
| 19 Mar 2017 02:09 PM |
| ################################### + current xp |
|
|
| Report Abuse |
|
|
galvinio
|
  |
| Joined: 30 Jun 2011 |
| Total Posts: 222 |
|
|
| 19 Mar 2017 02:10 PM |
((level/2) * (2*(100) + (level-1) * 100)) + current xp
|
|
|
| Report Abuse |
|
|
cars37
|
  |
| Joined: 27 Nov 2013 |
| Total Posts: 189 |
|
|
| 19 Mar 2017 02:13 PM |
@above
1/2*(level-1)*level*100+exp |
|
|
| Report Abuse |
|
|
galvinio
|
  |
| Joined: 30 Jun 2011 |
| Total Posts: 222 |
|
| |
|
|
| 19 Mar 2017 02:39 PM |
local TotalXP = (CurrentLevel * (CurrentLevel + 1) / 2)*100 + CurrentXP
I'm surprised no one thought of this.
I'm posting here again as any sort of loop is completely unecessary.
Tip : Learn everything from scratch, don't use high-level solutions.
20,855 |
|
|
| Report Abuse |
|
|