When Purchasing Things, Cost Increases

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

When Purchasing Things, Cost Increases

Post by Epiales »

Okay, on to my next adventure :) YAY me! lol

I have an idea on how to do this, but I don't know how I would do it for purchasing 10 at a time.

Let's say you purchase 10 weapons... I want the cost of those weapons to increase by a certain percentage for each 10 that are purchased. If I have to I can just make it max 10 at a time, but would rather have them purchase any amount up to 1000 at a time, but also have the increases in the total amount. But to start with, I would like a simple solution to just purchasing 10 at a time and then the cost of the weapon to increase by a certain percentage for each 10 purchased.

Any idea where to start on that?
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: When Purchasing Things, Cost Increases

Post by Jackolantern »

So you want the cost to increase for every 10 sold, and then stay increased ongoing?

But here is the basic mechanic for figuring out a cost increase for every 10 items sold when they can buy an infinite amount:

Code: Select all

$numberSold;
$cost;
//amount of increase per groups sold as a float (where 0.3 would be 30% increase, 0.05 would be 5%, etc.)
$increase = 0.08;      //8% price increase for each 10 items

//determine how many groups of 10 were sold
$groupsSold = $numberSold / 10;
//round to lowest integer
$groupsSold = floor($groupsSold);

//now increase the price
for ($x = 0; $x < $groupsSold; $x++) {
    $cost += $cost * $increase;
}

//cost has now increased cumulatively for each group of 10 bought   
The indelible lord of tl;dr
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: When Purchasing Things, Cost Increases

Post by Callan S. »

There's probably a proper math way of doing it, but I was going to suggest a for loop as well.

Off topic: I Find those math equations that seem to do the actions of a for loop but are just a singular equation to be pretty freaky.
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: When Purchasing Things, Cost Increases

Post by Epiales »

Yeah, I hate trying to figure the equations out. I'm pretty good in math, but making the equation I am not.

Okay, what's wrong with this?

Code: Select all

 $update_food = mysql_query("UPDATE `stats` SET `food`='".$stats['food'] - .$cost."' 
    WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error()); 
Error I get: Parse error: syntax error, unexpected '.' in C:\xampp\htdocs\flash\units.php on line 233

Oh, I left out a huge part of information LOL....

The cost and everything is NOT in the database, but the script. So I don't think I can even do this then, unless I rewrite the entire thing. :(
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: When Purchasing Things, Cost Increases

Post by MikuzA »

Epiales wrote:Yeah, I hate trying to figure the equations out. I'm pretty good in math, but making the equation I am not.

Okay, what's wrong with this?

Code: Select all

 $update_food = mysql_query("UPDATE `stats` SET `food`='".$stats['food'] - .$cost."' 
    WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error()); 
Error I get: Parse error: syntax error, unexpected '.' in C:\xampp\htdocs\flash\units.php on line 233

Oh, I left out a huge part of information LOL....

The cost and everything is NOT in the database, but the script. So I don't think I can even do this then, unless I rewrite the entire thing. :(
Hello,

you have an unexpected '.'

Code: Select all

SET `food`='".$stats['food'] - .$cost."' 
should be

Code: Select all

SET `food`='".$stats['food'] - $cost."' 
And what comes for the equations, it's just making the step-by-step logicality of a mathematical happening.
I don't think you are not good with equations, it's just that you are not yet fully familiar on how to get your thoughts written down in PHP, am I right? ;)


The cost do not have to be in database, as long as it is defined before the new pricing loop done by Mr. Jacko.
But the quantities sold needs to be stored somewhere, unless you just do a one time purchase increaser.. example:

"I want to buy 1000 AXES for my underground dwarven army, booyaah!"
"One axe costs 10 gold coins, and every ten axes increases the axe cost amount with 10%, so that makes it.. *massive loopings* muchos Dollars!"
And only the gold reducing is updated to db.
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: When Purchasing Things, Cost Increases

Post by Callan S. »

Code: Select all

 $update_food = mysql_query("UPDATE `stats` SET `food`='".$stats['food'] - .$cost."' 
    WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error()); 
I'd also do that '$stats['food'] - $cost' stuff outside the update string.

Trying to fit it all into the one line will just lower your Call of Cthulhu sanity stat by a few points, when you look at it a month from now!
Post Reply

Return to “Beginner Help and Support”