Jump to content

For loop with increasing numbers as ($x) value icreases


Recommended Posts

This might sound confusing, so I'll post a code for my example :)

You have 100 levels to go through, each level needs a certain amount of EXPERIENCE to get to the next level. To hit level 100 you need that last 10,000,000th exp point. So [10,000,000/100] would be 100,000 EXP per level, correct?

 

But I dont want getting level 2 to be so hard you need 100,000 EXP, off the start. I want it to get harder as you progress through your levels. Here's what I have and it equals a couple thousand from 10,000,000.

 

$number=1;
$num=99;
for($x=2;$x<=99;$x++)
{
$xp2+=($number*250)+($x*250)*0.211;


echo "<br>";
echo "Level: $x";
echo "- <b>".number_format($xp2)."</b>";


$tot+=$xp2;
}

echo "<br>";
echo "TOTAL: ".number_format($tot)."";

echo stripslashes($message);

 

 

This might sound confusing, so I'll post a code for my example :)

You have 100 levels to go through, each level needs a certain amount of EXPERIENCE to get to the next level. To hit level 100 you need that last 10,000,000th exp point. So [10,000,000/100] would be 100,000 EXP per level, correct?

 

But I dont want getting level 2 to be so hard you need 100,000 EXP, off the start. I want it to get harder as you progress through your levels. Here's what I have and it equals a couple thousand from 10,000,000.

 

$number=1;
$num=99;
for($x=2;$x<=99;$x++)
{
$xp2+=($number*250)+($x*250)*0.211;


echo "<br>";
echo "Level: $x";
echo "- <b>".number_format($xp2)."</b>";


$tot+=$xp2;
}

echo "<br>";
echo "TOTAL: ".number_format($tot)."";

echo stripslashes($message);

 

 

This might sound confusing, so I'll post a code for my example :)

You have 100 levels to go through, each level needs a certain amount of EXPERIENCE to get to the next level. To hit level 100 you need that last 10,000,000th exp point. So [10,000,000/100] would be 100,000 EXP per level, correct?

 

But I dont want getting level 2 to be so hard you need 100,000 EXP, off the start. I want it to get harder as you progress through your levels. Here's what I have and it equals a couple thousand from 10,000,000.

 

$number=1;
$num=99;
for($x=2;$x<=99;$x++)
{
$xp2+=($number*250)+($x*250)*0.211;


echo "<br>";
echo "Level: $x";
echo "- <b>".number_format($xp2)."</b>";


$tot+=$xp2;
}

echo "<br>";
echo "TOTAL: ".number_format($tot)."";

echo stripslashes($message);

Output:

Level: 2- 356
Level: 3- 764
Level: 4- 1,225
Level: 5- 1,739
Level: 6- 2,306
Level: 7- 2,925
Level: 8- 3,597
Level: 9- 4,322
Level: 10- 5,100
Level: 11- 5,930
Level: 12- 6,814
Level: 13- 7,750
Level: 14- 8,739
Level: 15- 9,780
Level: 16- 10,875
Level: 17- 12,022
Level: 18- 13,222
Level: 19- 14,474
Level: 20- 15,780
Level: 21- 17,138
Level: 22- 18,549
Level: 23- 20,013
Level: 24- 21,530
Level: 25- 23,099
Level: 26- 24,721
Level: 27- 26,396
Level: 28- 28,124
Level: 29- 29,904
Level: 30- 31,738
Level: 31- 33,624
Level: 32- 35,562
Level: 33- 37,554
Level: 34- 39,598
Level: 35- 41,695
Level: 36- 43,845
Level: 37- 46,048
Level: 38- 48,304
Level: 39- 50,612
Level: 40- 52,973
Level: 41- 55,387
Level: 42- 57,853
Level: 43- 60,372
Level: 44- 62,944
Level: 45- 65,569
Level: 46- 68,247
Level: 47- 70,977
Level: 48- 73,761
Level: 49- 76,597
Level: 50- 79,485
Level: 51- 82,427
Level: 52- 85,421
Level: 53- 88,468
Level: 54- 91,568
Level: 55- 94,721
Level: 56- 97,926
Level: 57- 101,184
Level: 58- 104,495
Level: 59- 107,859
Level: 60- 111,275
Level: 61- 114,745
Level: 62- 118,267
Level: 63- 121,842
Level: 64- 125,469
Level: 65- 129,150
Level: 66- 132,883
Level: 67- 136,669
Level: 68- 140,507
Level: 69- 144,399
Level: 70- 148,343
Level: 71- 152,340
Level: 72- 156,390
Level: 73- 160,493
Level: 74- 164,648
Level: 75- 168,856
Level: 76- 173,117
Level: 77- 177,431
Level: 78- 181,797
Level: 79- 186,216
Level: 80- 190,688
Level: 81- 195,213
Level: 82- 199,791
Level: 83- 204,421
Level: 84- 209,104
Level: 85- 213,840
Level: 86- 218,629
Level: 87- 223,470
Level: 88- 228,364
Level: 89- 233,311
Level: 90- 238,311
Level: 91- 243,363
Level: 92- 248,469
Level: 93- 253,627
Level: 94- 258,838
Level: 95- 264,101
Level: 96- 269,418
Level: 97- 274,787
Level: 98- 280,209
Level: 99- 285,683
TOTAL: 10,002,479

...Dude. Posting the same thing three times in one post doesn't make it three times easier to understand.

 

I/We can run the math for you. Give us a couple data points to start with, such as "Level 1->2 is 1000 points" or "You hit level 100 as you reach 1M XP" or "Level 99->100 is 100K points", if you would rather a straight line (each level is the amount it took for the previous level + some fixed amount), or three data points if you want a curve (same amount as the previous level + some amount which increases as you gain levels).

 

[edit] I may totally be overthinking this though. I'm just excited for a chance to do some math.

Edited by requinix

...Dude. Posting the same thing three times in one post doesn't make it three times easier to understand.

 

I/We can run the math for you. Give us a couple data points to start with, such as "Level 1->2 is 1000 points" or "You hit level 100 as you reach 1M XP" or "Level 99->100 is 100K points", if you would rather a straight line (each level is the amount it took for the previous level + some fixed amount), or three data points if you want a curve (same amount as the previous level + some amount which increases as you gain levels).

 

[edit] I may totally be overthinking this though. I'm just excited for a chance to do some math.

 

Weird I have no idea how it posted 3 times...lagged ctrl+v maybe :P

Ok, level 1->2 = getting 500xp, total XP of 500

level 2->3 getting (500*1.5) xp , total xp = 500+750=1,250 total XP when reaching level 3

level 100 = 10,000,000 total XP when reaching level 100

Edited by slyte33

Increasing the increment by around 2020 each level gets you there

$score = 500;
echo '<pre>';
for ($i=0; $i<100; $i++) {
$inc = $i*2020.1;
$score += $inc;
printf('%3d %7.0f %7.0f<br>', $i+1, $inc, $score);
}
echo '</pre>';

 

Alternatively, there's exponential increase in difficulty

 

$score = 500;
echo '<pre>';
for ($i=0; $i<100; $i++) {
$score *= 1.104105;

printf('%3d  %7.0f<br>', $i+1, $score);
}
echo '</pre>';

Edited by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.