Reputation: 43
basically I have a text document that has the following content
136 998831511
137 1109901576
138 1233322632
139 1370468109
140 1522864163
141 1692206658
142 1880380039
143 2089478300
144 2321828287
145 2580015593
146 2866913327
147 3185714089
148 3539965496
The first column (#136-148) are player levels, the second column is the experience point the player needs before they can move to the next level
What I am trying to do is create a function that if I for example choose the level "140" and the player has the experience of the player that is level 136 998831511 then it will check the players level in the text file and the exp it is supposed to have 1522864163 and update the players exp to be between the exp of the level 140 and the exp of the level 141.
This is the function I have created
function ExpIsBugged($CurrentLv,$CurrentExp)
{
$File = @file('charlv.txt');
foreach($File as $key => $FileLine)
{
$Lvs = explode("\t", $FileLine);
$NewLv = $key + 1;
if($Lvs[0] == $NewLv)
$NewExp = $Lvs[1];
if($Lvs[0] == $CurrentLv)
{
if($CurrentExp > $Lvs[1] && $CurrentExp < $NewExp )
{
return "Your Exp Is Bugged";
}
else
return "Your Exp Is Not Bugged";
}
}
}
But I am getting the error "The variable $NewExp is undefined" and it will not get the exp of the next level.
Any Help?
Upvotes: 0
Views: 265
Reputation: 545
I found the solution! change this line in your code. it work fine
$Lvs = explode(0x09, $FileLine);
it give you 3 or 2 array(depend in your file);
$Lvs[0]= 136 //(lvl);
$Lvs[1]= " "
$Lvs[2] =998831511// (exp)
if it give you 2 array:
$Lvs[0]= 136 //(lvl);
$Lvs[1] =998831511// (exp)
Upvotes: 1