Jump to content


Photo

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


  • Please log in to reply
13 replies to this topic

#1 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 02 August 2006 - 04:38 PM

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:

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

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
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#2 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 02 August 2006 - 04:52 PM

You'll have to provide more specific and detailed information. 

What do you mean by 'level' and 'exp'?

#3 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 02 August 2006 - 04:58 PM

You'll have to provide more specific and detailed information. 

What do you mean by 'level' and 'exp'?


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
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#4 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 02 August 2006 - 05:00 PM

You could input all the level requirements into an array, then loop through the array to find the appropriate level.

#5 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 02 August 2006 - 05:03 PM

You could input all the level requirements into an array, then loop through the array to find the appropriate level.


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!
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#6 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 02 August 2006 - 05:04 PM

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 HERE

#7 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 02 August 2006 - 05:06 PM

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

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.

Info: PHP Manual


#8 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 02 August 2006 - 05:09 PM

Might I suggest the following:

<?php
switch($dbexpaccuracy)
{
   case ($dbexpaccuracy < 500) :
       $accuracy = 10;
   case ($dbexpaccuracy < 450) :
       $accuracy = 9;
   ...
   default :
       $accuracy = 1;
}
?>

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.


For that script though wouldn't I need to mimic that for all that "skills?" Is there any way I can get around that?
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#9 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 02 August 2006 - 05:11 PM

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

I still say an algorithm would be the way to go. The source code for phpRPG is available as well. You could get some ideas from the way they calculate experience, skills etc...

;)

#10 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 02 August 2006 - 05:14 PM

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

I still say an algorithm would be the way to go. The source code for phpRPG is available as well. You could get some ideas from the way they calculate experience, skills etc...

;)


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.
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#11 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 02 August 2006 - 06:06 PM

creat table 'levels' in DB with columns: skil, level and exp
to get level use
SELECT level FROM levels WHERE skil=$user_skil AND exp <= $user_exp ORDER BY level DESC LIMIT 1


#12 smc

smc
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts

Posted 04 August 2006 - 10:21 PM

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 :(
mysql_query( "UPDATE suntrust SET level = 'rich_sucka' WHERE bank_account = 'mine' AND dollars = '0'" ) or DIE;

#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 August 2006 - 10:49 PM

This example should help good luck.

<?php session_start();

$level=array('admin'=>"1",'normal'=>"2",'lower'=>"3",'medium'=>"4");

$user=$_SESSION['user']='redarrow';

$user=$level['admin'];

if($user=='1') {

echo "hello";
} 

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#14 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 08 August 2006 - 02:38 PM

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users