Jump to content

Help - Wondering how to input a variable, analyze it, then output


smc

Recommended Posts

Hello,

I'm trying to create a script to determine a users "Level" by analyzing the number "exp" in the MySQL database, then comparing it to the experiance number of the different levels.

Here is the simple statement I thought of:

[code]
if ($dbexpaccuracy > $lvl1m || $dbexpaccuracy < $lvl2m){
$accuracy = "1";
}
if ($dbexpaccuracy == $lvl1m){
$accuracy = "1";
}
[/code]

But for this I would have to define this statement for all 150 levels, then do it again for all 20 some other skills.

I was wondering if there was a way I could have the experiance anaylzed to determinie what level it was, then plug it in for all the appropriate variables for echoing.

Thanks!!
-SmC
Link to comment
Share on other sites

[quote author=bltesar link=topic=102737.msg408199#msg408199 date=1154537570]
You'll have to provide more specific and detailed information. 

What do you mean by 'level' and 'exp'?
[/quote]

Well basically the level is in a game for example. If you have more than this amount of "exp" (or a number) but less than another amount of exp then you are this level.

For example. Level 1 is 0 exp, Level 2 is 200 exp. If your 132 exp your obviously level 1, so I need a script to determine that the number (exp) is greator than lvl1m (variable defining level 1's exp) but less than lvl2m, and return that the level is one.

Hope this clears it up a bit more
Link to comment
Share on other sites

[quote author=bpops link=topic=102737.msg408209#msg408209 date=1154538053]
You could input all the level requirements into an array, then loop through the array to find the appropriate level.
[/quote]

Would this be able to do it for all the different "skills." For example, I need to find a level for skill 1, skill 2, skill 3, etc. but they all use the same numbers for experiance.

If so, could you show me an example of what your talking about? I'm a newbie when it comes to things like this, I know stuff in some areas but not in others :P

Thanks!
Link to comment
Share on other sites

If you don't want to hard code what XP values each level has, then you'll need to create an algorithm that will have an exponential increase for each level. This could work experience, skills, etc...

I came across a web page where someone dissected the XP mechanics for FF7, which may help you get started.

Check it out [url=http://astro.berkeley.edu/~dperley/ff7/expmechanics.html]HERE[/url]
Link to comment
Share on other sites

Might I suggest the following:
[code]
<?php
switch($dbexpaccuracy)
{
  case ($dbexpaccuracy < 500) :
      $accuracy = 10;
  case ($dbexpaccuracy < 450) :
      $accuracy = 9;
  ...
  default :
      $accuracy = 1;
}
?>
[/code]

It basically falls through the switch until it finds what it's looking for.  Keep in mind, I didn't test this, but it should work in theory.  You may have to adjust it or flip it so that it goes up instead of down.
Link to comment
Share on other sites

[quote author=ober link=topic=102737.msg408215#msg408215 date=1154538389]
Might I suggest the following:
[code]
<?php
switch($dbexpaccuracy)
{
  case ($dbexpaccuracy < 500) :
      $accuracy = 10;
  case ($dbexpaccuracy < 450) :
      $accuracy = 9;
  ...
  default :
      $accuracy = 1;
}
?>
[/code]

It basically falls through the switch until it finds what it's looking for.  Keep in mind, I didn't test this, but it should work in theory.  You may have to adjust it or flip it so that it goes up instead of down.
[/quote]

For that script though wouldn't I need to mimic that for all that "skills?" Is there any way I can get around that?
Link to comment
Share on other sites

Depending on how many levels you allow, that could be one [b]HUGE[/b] switch statement.

I still say an algorithm would be the way to go. The source code for [url=http://phprpg.org/]phpRPG[/url] is available as well. You could get some ideas from the way they calculate experience, skills etc...

;)
Link to comment
Share on other sites

[quote author=HeyRay2 link=topic=102737.msg408219#msg408219 date=1154538716]
Depending on how many levels you allow, that could be one [b]HUGE[/b] switch statement.

I still say an algorithm would be the way to go. The source code for [url=http://phprpg.org/]phpRPG[/url] is available as well. You could get some ideas from the way they calculate experience, skills etc...

;)
[/quote]

Yeah thats my problem, because there is 20 something skills and 150 levels for each of them.

The exp for the code though is hard coded as the game operates on set values of experiance.
Link to comment
Share on other sites

Well unfortunatly the way the game operates it dosen't store it in level form.

I was wondering if an array is the best bet. I'm not really sure how to do the array but something like

$variable = new_array("0", "27", "58", "92", "130", "173", "220", ............

But if I did something like that, how would I cycle through it until it found which it was greator then, with which level it was less than? I suppose it could stop at the number it is less than, but I'm just not farmilar with PHP enough to devise that kind of function.

Help :(
Link to comment
Share on other sites

define the exp values for the various levels in an array, e.g.-

$level=array(0,200,400,750,...);

level 1 is 0-200, level 2 is 201-400, level 3 is 401-750

then use the following code to find your level:

$i=1;
$exp_score;
while($level[$i]<$exp_score)
{
    $i++;
}


$i is the level for $exp_score
Link to comment
Share on other sites

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.