Raising the value slowly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Raising the value slowly

Post by azz0r_ »

Ok basically Ive rewrote my kama system.

Basically say a user has 3000 karma, I have a forumula that works out how many blocks the user should have.

The only problem I have is the "step". Technically it should start off @ like 100 per block, then by the end require 400 odd per a block.

Example; http://forumz.wuggawoo.co.uk/index/test?user_karma=1999

Code

Code: Select all

Post three
Last edited by azz0r_ on Thu Feb 17, 2005 1:34 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

do you want to use a math equation for stepping, or just a facetted system?
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Post by azz0r_ »

Math equation, I'm not familiar with foreach.

However I am aware that Ive seen something similar to a step equation of like $amount * 1.3.
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Post by azz0r_ »

Updated code

Code: Select all

function define_bar($actual_bar, $blocks)  {

	if($actual_bar <= ceil($blocks / 6))
	&#123;$bar_scale = 'sta';&#125;
		
		elseif($actual_bar == ceil($blocks / 4))
		&#123;$bar_scale = 'avg';&#125;
	
	elseif($actual_bar == ceil($blocks / 2))
	&#123;$bar_scale = 'med';&#125;
		
		elseif($actual_bar == $blocks)
		&#123;$bar_scale = 'max';&#125;

return $bar_scale;&#125;


	$forum_properties&#1111;'karma_limit'] = 2000;
	$forum_properties&#1111;'karma_blocks'] = 10;
	$per_block = ceil($forum_properties&#1111;'karma_limit'] / $forum_properties&#1111;'karma_blocks']);
	$user_karma = $_GET&#1111;'user_karma'];
	$number_of_blocks = floor($user_karma / $per_block);
	$block_steps = array(100, 200, 350, 500);
	
	echo "The karma limit is ".$forum_properties&#1111;'karma_limit']."<br />";	echo "The number of blocks to fill is ".$forum_properties&#1111;'karma_blocks']."<br />";	echo "For each block $per_block is needed.<br />"; echo "For this test, the user has $user_karma karma.<br />";	echo "That means there is $number_of_blocks blocks filled in.<br /><br />";


	while($x < $forum_properties&#1111;'karma_blocks'])//we make our blocks
	&#123;$x++; $actual_bar++;
	
	$bar_scale = define_bar($actual_bar, $forum_properties&#1111;'karma_blocks']);

	if($number_of_blocks > 0)
	&#123;$number_of_blocks--; $blocked .= "<img src="$bar_scale.jpg">";&#125;
	else
	&#123;$unblocked .= "<img src="empty.jpg">";&#125;&#125;



	echo $blocked.$unblocked;
Ive tried some foreach testing but I can get it right
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

exponential stepping:

Code: Select all

$exponential = 1.4;
$negative = $karma < 0;
$karma = abs($karma);
$blocks = 1;
$multiplier = 100;
while($karma > (pow($blocks, $exponential) * $multiplier)) $blocks++;
fiddle with $multipler and $exponential to adjust where the steps happen. If need be, you can store off the result and shave it into hundreds or something..

precalculating the level requirements for many blocks would help speed the processing..
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Post by azz0r_ »

I dont understand your code, so I tried to come up with something else.

Code: Select all

$block_steps = array(100, 200, 350, 500);

	foreach ($block_steps as $value)
	&#123;$step&#1111;$value] = floor($forum_properties&#1111;'karma_limit'] / $value);
	$total = $total + (($value * $step&#1111;$value]) / 4);
	$stepo&#1111;$value] = floor(($forum_properties&#1111;'karma_limit'] / $value) / 4);&#125;

echo $total;
print '<br />';print_r($step);
print '<br />';print_r($stepo);
Which doesnt consider how many blocks there is, but its a start
azz0r_
Forum Commoner
Posts: 27
Joined: Mon Jan 24, 2005 4:15 pm

Post by azz0r_ »

Hey I got it working, I decide the method I was going for was slightly slopped, the new method basically uses the array that would allow the admin to decide how many of each blocks there should be and is very versitile as you'll see below.

Code: Select all

$forum_properties&#1111;'user_karma'] = $_GET&#1111;'user_karma'];
	$karma_total&#1111;'fifty'] = 1;
	$karma_total&#1111;'one'] = 3;
	$karma_total&#1111;'two'] = 2;
	$karma_total&#1111;'three'] = 2;
	$karma_total&#1111;'four'] = 0;
	$karma_total&#1111;'five'] = 1;
	$karma_total&#1111;'six'] = 1;
	$karma_total&#1111;'seven'] = 1;
	$karma_total&#1111;'eight'] = 0;

$karma_array = array(
	array(50, $karma_total&#1111;'fifty'], 1), 
	array(100, $karma_total&#1111;'one'], 1), 
	array(200, $karma_total&#1111;'two'], 2), 
	array(300, $karma_total&#1111;'three'], 2), 
	array (400, $karma_total&#1111;'four'], 2), 
	array(500, $karma_total&#1111;'five'], 3), 
	array(600, $karma_total&#1111;'six'], 3), 
	array(700, $karma_total&#1111;'seven'], 3), 
	array(800, $karma_total&#1111;'eight'], 4));

#else	
####information
foreach($karma_array as $sub_array)
&#123;list($value, $amount) = $sub_array;
$total = $total + ($value * $amount);
$blocks = $blocks + $amount;&#125;
echo "Total karma to achieve a full bar is $total.<br />Total number of blocks is $blocks.<br />";
###information


	foreach($karma_array as $sub_array)
	&#123;list($value, $no_bars, $image) = $sub_array;

	while($no_bars > 0)  &#123;
	

	if($forum_properties&#1111;'user_karma'] >= $value)
	&#123;$block .= '<img src="'.$image.'.jpg" alt="'.$value.'" />';
	$forum_properties&#1111;'user_karma'] = $forum_properties&#1111;'user_karma'] - $value;&#125;
	else
	&#123;$unblock .= '<img src="empty.jpg" alt="" />';&#125;

	$no_bars--;
	&#125;#end while
	&#125;#end foreach
	


	echo $block.$unblock;
Thanks for your help :)
Post Reply