Jump to content

Recommended Posts

yes...tis me again...hello all *dodges rotten tomatoes*

 

i got probs *surprise surprise*

 

first of all here is the code:

 

<?php

$research_levels_query = "SELECT * FROM research WHERE username = '$username' AND password = '$password'";
$activate_query = mysql_query($research_levels_query) or die(mysql_error());
$research_levels = mysql_fetch_assoc($activate_query) or die(mysql_error());

//base build times for all vehicles in seconds//
$light_ore_miner_base_build_time = 600;
$light_fuel_miner_base_build_time = 720;
$light_crystal_miner_base_build_time = 900;
$light_wood_farmer_base_build_time = 660;
$light_wave_sub_base_build_time = 840;
$light_atmospheric_filterer_base_build_time = 960;
$medium_ore_miner_base_build_time = 3000;
$medium_fuel_miner_base_build_time = 3420;
$medium_crystal_miner_base_build_time = 3900;
$medium_wood_farmer_base_build_time = 3300;
$medium_wave_sub_base_build_time = 3540;
$medium_atmospheric_filterer_base_build_time = 4020;
$heavy_ore_miner_base_build_time = 7800;
$heavy_fuel_miner_base_build_time = 8400;
$heavy_crystal_miner_base_build_time = 9000;
$heavy_wood_farmer_base_build_time = 8100;
$heavy_wave_sub_base_build_time = 8700;
$heavy_atmospheric_filterer_base_build_time = 9600;

//----------------------------------------------CREATE FUNCTION------------------------------------------------------------//
function vehicle_build_times($vehicle_base_build_time,$research_level)
{
    if ($research_level >= 1)
	{
        $vehicle_build_time = $research_level - (5 * ($vehicle_base_build_time / 100));
	}
	else
	{
	    $vehicle_build_time = $vehicle_base_build_time;
    }
	return $vehicle_build_time;
}
//-------------------------------------------------------------------------------------------------------------------------//


//-----------------------------------------------------ECONOMIC VEHICLE BUILD TIME FUNCTIONS--------------------------------------------------//

//Light Ore Miner//
$light_ore_miner_build_time = vehicle_build_times($light_ore_miner_base_build_time,$research_levels['simple_ore_drill_turbines']);
//---------------//

//Light Fuel Miner//
$light_fuel_miner_build_time = vehicle_build_times($light_fuel_miner_base_build_time,$research_levels['simple_fuel_drill_turbines']);
//----------------//

//Light Crystal Miner//
$light_crystal_miner_build_time = vehicle_build_times($light_crystal_miner_base_build_time,$research_levels['simple_crystal_drill_turbines']);
//-------------------//

//Light Wood Farmer//
$light_wood_farmer_build_time = vehicle_build_times($light_wood_farmer_base_build_time,$research_levels['simple_farm_fertilisation']);
//-----------------//

//Light Wave Sub//
$light_wave_sub_build_time = vehicle_build_times($light_wave_sub_base_build_time,$research_levels['simple_wave_turbines']);
//--------------//

//Light Atmospheric Filterer//
$light_atmospheric_filterer_build_time = vehicle_build_times($light_atmospheric_filterer_base_build_time,$research_levels['simple_atmospheric_filter_enlarger']);
//--------------------------//

//Medium Ore Miner//
$medium_ore_miner_build_time = vehicle_build_times($medium_ore_miner_base_build_time,$research_levels['advanced_ore_drill_turbines']);
//---------------//

//Medium Fuel Miner//
$medium_fuel_miner_build_time = vehicle_build_times($medium_fuel_miner_base_build_time,$research_levels['advanced_fuel_drill_turbines']);
//----------------//

//Medium Crystal Miner//
$medium_crystal_miner_build_time = vehicle_build_times($medium_crystal_miner_base_build_time,$research_levels['advanced_crystal_drill_turbines']);
//-------------------//

//Medium Wood Farmer//
$medium_wood_farmer_build_time = vehicle_build_times($medium_wood_farmer_base_build_time,$research_levels['advanced_farm_fertilisation']);
//-----------------//

//Medium Wave Sub//
$medium_wave_sub_build_time = vehicle_build_times($medium_wave_sub_base_build_time,$research_levels['advanced_wave_turbines']);
//--------------//

//Medium Atmospheric Filterer//
$medium_atmospheric_filterer_build_time = vehicle_build_times($medium_atmospheric_filterer_base_build_time,$research_levels['advanced_atmospheric_filter_enlarger']);
//--------------------------//

//Heavy Ore Miner//
$heavy_ore_miner_build_time = vehicle_build_times($heavy_ore_miner_base_build_time,$research_levels['hi_tech_ore_drill_turbines']);
//---------------//

//Heavy Fuel Miner//
$heavy_fuel_miner_build_time = vehicle_build_times($heavy_fuel_miner_base_build_time,$research_levels['hi_tech_fuel_drill_turbines']);
//----------------//

//Heavy Crystal Miner//
$heavy_crystal_miner_build_time = vehicle_build_times($heavy_crystal_miner_base_build_time,$research_levels['hi_tech_crystal_drill_turbines']);
//-------------------//

//Heavy Wood Farmer//
$heavy_wood_farmer_build_time = vehicle_build_times($heavy_wood_farmer_base_build_time,$research_levels['hi_tech_farm_fertilisation']);
//-----------------//

//Heavy Wave Sub//
$heavy_wave_sub_build_time = vehicle_build_times($heavy_wave_sub_base_build_time,$research_levels['hi_tech_wave_turbines']);
//--------------//

//Heavy Atmospheric Filterer//
$heavy_atmospheric_filterer_build_time = vehicle_build_times($heavy_atmospheric_filterer_base_build_time,$research_levels['hi_tech_atmospheric_filter_enlarger']);
//--------------------------//

//------------------------------------------------------------------------------------------------------------------------------------------------//




//CREATE UPDATE VEHICLE QUE FUNCTION//
function update_vehicle_que($vehicle,)
{
    //query to add the que'd vehicles and added to que light_ore_miner's together and put into the database
    $add_to_que = "UPDATE vehicle_construct_amount SET $vehicle = '$light_ore_miner' WHERE username='$username' AND password='$password'";
    //get the current timestamp
    $current_timestamp = time();
    //If There are currently 0 of this certain vehicle in the que for build-add them
    if ($fetch_timestamp['$vehicle'] == 0)
    {
	    $add_date_and_time = "UPDATE vehicle_construct_seconds SET $vehicle = '$current_timestamp' WHERE username = '$username' AND password = '$password'";
			mysql_query($add_date_and_time) or die(mysql_error());
			mysql_query($add_to_que) or die(mysql_error());
	}
	else
	{
			//find out how many seconds has passed while they have been in the que
			$seconds_since = time() - $fetch_timestamp['$vehicle'];
			//work out how many could have been created
			$available_construction = $seconds_since / $'$vehicle'_build_time;
			//if all the que'd selected vehicle have finished-update the tables
			if ($available_construction > $grabbed_vehicles_construction_amounts['$vehicle'])
			{
			    //end the vehicle que
					$update_que = "UPDATE vehicle_construct_amount SET $vehicle = '0' WHERE username = '$username' AND password = '$password'";
					//reset the timestamp
					$update_timestamp = "UPDATE vehicle_construct_seconds SET $vehicle = '0' WHERE username = '$username' AND password = '$password'";
					//add current selected vehicles to already built light_ore_miners
					$total_'$vehicle' = $grabbed_vehicle_amounts['$vehicle'] + $grabbed_vehicles_construction_amounts['$vehicle'];
					//query to update the vehicles table with the new created current vehicle amount
					$update_vehicles = "UPDATE vehicle_amounts SET $vehicle = '$total_'$vehicle'' WHERE username = '$username' AND password = '$password'";
					//activate the queries
					mysql_query($update_vehicles) or die(mysql_error());
					mysql_query($update_que) or die(mysql_error());
					mysql_query($update_timestamp) or die(mysql_error());
			}
			else
			{
          //take off any remainder from end result of the above processes
		      $sums_remainder = $available_construction - floor($available_construction);
		      $available_build = $available_construction - $sums_remainder;
					if ($available_build >= 1)
					{
					    //update current vehicle que
							if ($grabbed_vehicles_construction_amounts['$vehicle'] >= 1)
							{
							    $grabbed_'$vehicle' = $grabbed_vehicles_construction_amounts['$vehicle'] - $available_build;
									//put into query
									'$vehicle'_update = "UPDATE vehicle_construct_amount SET $vehicle = '$grabbed_'$vehicle'' WHERE username = '$username' AND password = '$password'";
									mysql_query('$vehicle'_update) or die(mysql_error());
						  }
							//add ready current vehicles to list of already constructed
						  $constructed_'$vehicle' = $grabbed_vehicle_amounts['$vehicle'] + $available_construction;
						  //put this into query
						  $update_table = "UPDATE vehicle_amount SET $vehicle = '$constructed_'$vehicle'' WHERE username = '$username' AND password = '$password'";
							//make a new timestamp including the remainder for the current vehicle in production
							$timestamp_remainder = $sums_remainder * 600;
							$required_timestamp = time() - $timestamp_remainder;
							//put into query
							$insert_timestamp = "UPDATE vehicle_construct_seconds SET $vehicle = '$required_timestamp' WHERE username = '$username' AND password = '$password'";
							//activate queries
							mysql_query($update_table) or die(mysql_error());
							mysql_query($insert_timestamp) or die(mysql_error());
            }
        }  
    }
}
?>

 

now if i can explain this right u may b able to help me

 

as u can see it is a game i am making

 

neway-the prob is im trying to use the $vehicle variable to make the names of other variables inside the function e.g. $'$vehicle'_build_time

 

obviously ive found out that this doesn't work unfortunately

 

is there any way of doing what i wana do in php? or is it much more complicated than what im trying to do?

 

cheers

 

Pudgemeister

ok ive replaced any of those stupid lookin $'$vehicle'_build_time variables with ${$vehicle}_build_time variable names

 

according to the info page you gave me (which is now bookmarked-tyvm) this should be correct

 

im still getting the same error :S

 

the error is:

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_VARIABLE or '$' in C:\wamp\www\game\vehicles\vehicle_build_times.inc.php on line 141

 

i even get that error with a simple variable in place of the variable variable.

 

i can't see the problem :S whats up?

atm it's starting at the first line where im trying to use a variable variable

 

$available_construction = $seconds_since / ${$vehicle}_build_time;

 

is now in place of $available_construction = $seconds_since / $'$vehicle'_build_time;

 

and it's the same for other places like that

I tested my suggestion with

<?php
$seconds_since = 58;
$vehicle = 'jeep';
${$vehicle . '_build_time'} = 3;
$available_construction = $seconds_since / ${$vehicle . '_build_time'};
echo $available_construction;
?>

 

and it worked fine. The error must be referring to something else.

 

Ken

umm ok sumit weird is happenin here now :S

 

ive just done sum testing and i tihnk sumit is up wid my wamp package or sumthin

 

cus when I do:

 

<?php

 

$test = 'test';

echo $test;

 

?>

 

im getin no output!

 

this is slightly worrying-have a made a very stupid mistake sumwhere

wtf??

 

now everythin is workin and that solution u gave me works fine

 

i think my wamp server has had sumit up wid it for a while but hey i aint complainin-ur solution works now :D

 

cheers

 

keeping topic undolved cus the function aint complete yet

 

Pudgemeister

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.