Jump to content

Session Quest system for a game.


Kryllster

Recommended Posts

I am trying to make a session based quest sytem for a game im making. I have some code but im not sure why it isnt working. I get the basic info from a database but everytime I click on a link to fight a monster I get a blank page.

<?php
// connect to db
	include 'php/db/vanguard_db_config.php';

// Select data from database
	$sql = "SELECT * FROM assignments WHERE assignment_id='1'";
	$result = mysql_query($sql);

// Put info into array Hopefully
	while($entry = mysql_fetch_assoc($result)){
	$id = $entry['assignment_id'];
	$assignname = $entry['assignment_name'];
	$numarrest = $entry['num_to_arrest'];
	$villianarrest = $entry['villian_to_arrest'];
	$num_arrested = $entry['num_arrested'];
	$completed = $entry['completed'];
	$reward = $entry['reward'];
	
	$stat = $villianarrest;

// session assignment manipulation
		if(!isset($_SESSION['assignment_id'])) ($id = $_SESSION['assignment_id']){
		$_SESSION['assignment_id'] = $id;
		}
		if(!isset($_SESSION['num_to_arrest'])){
		$_SESSION['num_to_arrest'] = 10;
		}
		if(!isset($_SESSION['completed'])){
		$_SESSION['completed'] = 1;
		}
		if( $_SESSION['num_to_arrest'] != 10){
		$_SESSION['num_to_arrest'] + 1;
		}
		id($num_arrested == 10{
		$sql = "UPDATE assignments SET  // Update database with loot and level advance
		money = money + 20000;
		WHERE assignment_id = '$id'";
		mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
		}
		
		
		if($num_arrested == 10){
			echo "<h2>You Have Completed Your Assignment and received $20,000 Dollars!</h2>";
		}
		}
?>

Thanks for any input in advance!

Link to comment
Share on other sites

I am trying to make a session based quest sytem for a game ... I get a blank page.

 

your code has a fatal parse error/syntax error (all syntax errors are fatal and your code doesn't even run) on line 22. if you look at line 22 you can probably figure out what is wrong with it.

 

before you spend any more time working on your code, do yourself a favor and set php's error_reporting to E_ALL and display_errors to ON in your master php.ini so that all php errors will be displayed. you will know if these settings are successful when the code above produces output like - Parse error: syntax error, unexpected '{' in your file name.php on line 22

 

lastly, the mysql_ database library is not recommend for new code (its being depreciated, soon to be removed) and all new code should be written using the mysqli or pdo database libraries so that you don't need to rewrite your code in the future when the mysql_ functions are removed from php.

Link to comment
Share on other sites

Ok thanks mac I didnt know that I did turn on all error reporting in the master php.ini and now I cant even log in. I have switched on the recommendadtion to a different structur for my sites and now it looks like im gonna have to redo all the code.

Link to comment
Share on other sites

Unless you have set your session.auto_start directive to 1, then you'll need to start/resume the session at the top of each desired page using the session_start() function.

 

You don't seem to be using that function on your page.

 

Also, on closer inspection: (line 22)

if(!isset($_SESSION['assignment_id'])) ($id = $_SESSION['assignment_id']){

Doesn't look right? Try something like:

if(!isset($_SESSION['assignment_id']) && $id = $_SESSION['assignment_id']){
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.