Jump to content

[SOLVED] Not sure how to solve this?


Kryllster

Recommended Posts

I have an entry point to a dungeon room (Im making a game) and Its supposed to take a diamond out of the inventory. Now it was working with a link to the php sctript then using the header location funtion it would take the diamond the send him to the page. I am wanting to just use this over and over agiain as a function. I have like 7 or 8 scripts in different rooms to do this. Here is what my function looks like??

 

<?php
function takeDiamond($arg){
	switch ($arg){
	 case "main1":
	 $takedia =	$sql="UPDATE $tbl_name SET  
        diamond = diamond - 1 
        WHERE username='$username'";
     break;
}
return $takedia;
}
?>

 

now in the index.php it just shows the content but I am at a loss how to do it or I mean get it to work???

 

Stumped again.

 

Thanks.

Kryllster

Link to comment
Share on other sites

I don't exactly understand what you're doing with that switch statement. Just run the function when someone tries to enter a room that requires a diamond and have it first check for diamonds, and return pass/fail.

 

function takeDiamond() {
$diamond = (Run a query to get amount of diamonds in inventory);
if ($diamond > 0) {
   $diamond--;
   (Run new query to update the database with new diamond amount);
   return true;
} else {
   return false;
}

 

Then just check that function for true or false when the person enters the room.

Link to comment
Share on other sites

Basically, you would run something like this wherever you want the diamond check / reduction to take place. If that is on your index page, then run it there. If it is on the content page.... your script and the logic determines where you want to run this.

 

<?php
if(takeDiamond())
{
  // let the user proceed, they have 1 less diamond now
}
else
{
   // the user does not have enough diamonds to proceed.
}
?>

 

Nate

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.