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 » Scripters
Home Search
 

Re: Math problem (I think) Any advice?

Previous Thread :: Next Thread 
Keltrin is not online. 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 is online. galvinio
Joined: 30 Jun 2011
Total Posts: 222
19 Mar 2017 12:30 PM
level * 100 + current xp???


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
19 Mar 2017 12:33 PM
(level - 1)! + currentXP


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
19 Mar 2017 12:33 PM
(level - 1)! * 100 + currentXP*


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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 is not online. 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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
19 Mar 2017 12:47 PM
oh I'm stupid I thought of it a different way
let me write something


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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 is not online. 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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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 is not online. 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
Sacrificable is not online. Sacrificable
Joined: 11 Sep 2013
Total Posts: 271
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
Sacrificable is not online. Sacrificable
Joined: 11 Sep 2013
Total Posts: 271
19 Mar 2017 01:18 PM
Kap, I think you have a brain disorder.


20,851
Report Abuse
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
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
Sacrificable is not online. Sacrificable
Joined: 11 Sep 2013
Total Posts: 271
19 Mar 2017 01:21 PM
of course, but you needn't form any sort of loop in lua.


20,853
Report Abuse
KapKing47 is not online. 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 is not online. 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
IcedVapour is not online. IcedVapour
Joined: 10 Nov 2013
Total Posts: 2741
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 is online. 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 is not online. 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 is online. galvinio
Joined: 30 Jun 2011
Total Posts: 222
19 Mar 2017 02:09 PM
################################### + current xp
Report Abuse
galvinio is online. 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 is not online. 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 is online. galvinio
Joined: 30 Jun 2011
Total Posts: 222
19 Mar 2017 02:17 PM
o thx


Report Abuse
Sacrificable is not online. Sacrificable
Joined: 11 Sep 2013
Total Posts: 271
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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