Jump to content

Shadowing

Members
  • Posts

    722
  • Joined

  • Last visited

Everything posted by Shadowing

  1. Also i had this all wraped in a function so to echo i had to pass it into a list of returns. so i should of tossed the function to the side really echo everything good. Cause for some reason I couldnt echo distance out side the function it was showing up as 1. not sure what the deal is with that. Edit: ohhh its cause im trying to return a string using array() then list(). and the string didnt have quotes around it.
  2. OMG I figured out my problem, thanks alot drummin There was nothing wrong with me fliping through the array like you said. the db_x and db_y was backwards the x needed to go first. See I was getting the wrong math back from the function and i cant believe i didnt notice that after 12 hours of deep problem solving omg. I was about to go insane cause i knew nothing was wrong $distance .= distance($b_x,$b_y,$db_x,$db_y) . "-";
  3. The end of the array looks like this [14] => Array ( [b_x] => 435 [b_y] => 171 ) ) 1 I dont understand how or why there is a 1 on the end. so im thinking thats where this 1 is coming from
  4. thanks for the responce Drummin What i did was i just pasted what the Print_r was off the array so you would have an idea what the array looks like. $db_y = $db['b_y']; if I echo $db_y i get the return of 1 This isnt reading the array $db_x = $db['b_x']; $db_y = $db['b_y'];
  5. Hey guys im trying to insert these values from this array into the distance function I made and then it turns it into a string. Took me like 8 hours of problem solving just to find out this wasnt working. really could use some help with this. $arr is the array Array ( [0] => Array ( [b_x] => 85 [b_y] => 71 ) [1] => Array ( [b_x] => 436 [b_y] => 130 ) $b_x = 295; $b_y = 163; foreach($arr as $db) { $db_x = $db['b_x']; $db_y = $db['b_y']; $distance .= distance($b_x,$b_y,$db_y,$db_x) . "-"; } end result is suppose to look like $distance-$distance-$distance and so forth
  6. Yah i tried that before and it makes all my other pages not work since in those chains it doesnt need to look up one folder. So I guess there is no way to set a path for require so it doesnt matter what folder i have stuff in?
  7. Alright this is the way this is going but yah its the last file in the chain that is causing the issue. all my other pages work fine on my site that is requring battle.php and then having battle.php use function_battle.php. this is the page im viewing C:\Software\XAMPP\xampp\htdocs\System_Lords\messages\inbox.php then on that file im including this file "which is a menu" require("../menu.php"); C:\Software\XAMPP\xampp\htdocs\System_Lords\menu.php and on the file above "the menu" has this file included include_once("/include/battle.php"); C:\Software\XAMPP\xampp\htdocs\System_Lords\include\battle.php and on the file above "battle.php" has this file included require("/functions/function_battle.php"); C:\Software\XAMPP\xampp\htdocs\System_Lords\functions\function_battle.php
  8. ehh nevermind lol. had my x and y's fliped around I didnt even notice. doing math right when waking probably isnt a good idea
  9. Hey guys i cant figure out why im not getting an answer of 5 with this. SELECT sqrt(pow(1 - 2,2) + pow(5 - 5,2)) AS RESULT The formula im using
  10. hey guys im still having a issue with using the root path when requiring external files. So i can use one path and never have to worry about this issue. require("/functions/function_battle.php"); the file is located here C:\Software\XAMPP\xampp\htdocs\System_Lords\functions\function_battle.php i dont understand (include_path='.;C:\Software\XAMPP\xampp\php\PEAR') im suppose to be including the php folder or something? Fatal error: require() [function.require]: Failed opening required '/functions/function_battle.php' (include_path='.;C:\Software\XAMPP\xampp\php\PEAR') in C:\Software\XAMPP\xampp\htdocs\System_Lords\include\battle.php on line 2
  11. ahh I fixed the issue haha I dont know why I didnt think about this before. I just had to use php to require the file. Now im passing variables to the external java script page. require("/jquery/evaluate.js"); stead of <script type="text/javascript" src="/system_lords/jquery/evaluate.js"></script>
  12. yah i meant global on the page that the jquery is getting the variables from to pass to the php file. im passing all my variables like this. After some more testing I figured out whats going on. apparently i cant past variables onto a external java script page? If i dont use an external page and put the code in the head section of the page the code does the same as using the external java script file instead. If i put the java script code at the very bottom of the page it works but if i put the external java script link to the bottom of the page it doesnt work either. All senerios still make the first if statement work and thats because with the varaibles not being passed its still reading the if statement as true which is input fields are blank. So if im passing variables i have to have the code at the bottom of the page so the flow of the page works with it. Which makes sense but it sucks that i cant pass variables when using a external java script file. $(document).ready(function() { $("#evaluate").click(function(event) { event.preventDefault(); $.ajax({ url: "/System_Lords/ajax/include_evaluate.php", type: 'POST', dataType: 'json', data: { attacker_jaffa: $('#jaffa').val(), attacker_staff_cannons: $('#staff_cannons').val(), attacker_bombers: $('#bombers').val(), attacker_mother_ships: $('#mother_ships').val(), defender_jaffa: '<?php echo $defender_jaffa; ?>', defender_staff_cannons: '<?php echo $defender_staff_cannons; ?>', defender_bombers: '<?php echo $defender_bombers; ?>', defender_death_gliders: '<?php echo $defender_death_gliders; ?>', defender_mother_ships: '<?php echo $defender_mother_ships; ?>', defender_staff_turrets: '<?php echo $defender_staff_turrets; ?>', defender_fortress: '<?php echo $defender_fortress; ?>', attackers_weapons_tech: '<?php echo $attackers_weapons_tech; ?>', defenders_weapons_tech: '<?php echo $defenders_weapons_tech; ?>', offense_jaffa: '<?php echo $offense_jaffa; ?>', offense_staff_cannons: '<?php echo $offense_staff_cannons; ?>', offense_bombers: '<?php echo $offense_bombers; ?>', offense_mother_ships: '<?php echo $offense_mother_ships; ?>', defense_jaffa: '<?php echo $defense_jaffa; ?>', defense_staff_cannons: '<?php echo $defense_staff_cannons; ?>', defense_bombers: '<?php echo $defense_bombers; ?>', defense_death_gliders: '<?php echo $defense_death_gliders; ?>', defense_mother_ships: '<?php echo $defense_mother_ships; ?>', defense_fortress: '<?php echo $defense_fortress; ?>', battle_chance: '<?php echo $battle_chance; ?>' }, success: function(response) { $('#evaluate_box').html(response.evaluate); } }); }); });
  13. you just gave me an idea lol. I might just use some ajax on my messaging system. I was reading something today where you can change the address link to say http://localhost/system_lords/messages/inbox.php#1 so you could use that as page numbers for the links
  14. thanks thorpe. yah i removed all the variables but two that i was passing cause it was a list of like 30 variables lol. the script works when its on the page but when im using the script from an external file the if statement works but the else statement does not. The if statement checks variables if its empty so i know its passing variables correctly. So i guess there isnt anything obvious that im doing wrong. when using an external page it should be exactly same as placing the code on the page right? shouldnt matter what order i add in the external java script right? Cause java script is always read after php code anyways. Oh wait i just thought of something. the differance between the if statement and the else statement is that the if statement is using all global variables from the page and the else statement is not. so if im grabing variables that are not global does the flow of the page matter as to where i include the external java script file? on firebug i see where it shows the java script code. but its poorly formated. is this error area a window of its own? thanks for the feed back on my formating. Ive still let to get a good organized writing down. it is alot better then it used to be though lol. I dont know why i tab it over so much i need to stop that too.
  15. Hey guys wondering if this is possible or not im wanting to add the b_x with the b_y so i select it out of the data base as 1 number. The math im really going to do is more complex but just using add to simplifly what i want to do. i would obviously need to assign it in some way so I can grab it to like $variable = $star_check1[]; This will acctually become a loop grabing several rows so if i could change it into one number would be alot easier. $star_check3 = "SELECT b_x,b_y FROM planets WHERE x = '".($x)."' AND y = '".($y)."'"; $star_check2 = mysql_query($star_check3) or trigger_error("SQL", E_USER_ERROR); $star_check1 = mysql_fetch_array($star_check2);
  16. for starters anyone know how to use firebug cause I cant figure it out. Like where does it show errors at? guess i can look in the firebug forum anyways. my ajax script works perfectly with the java/ajax script on the page but as soon as I make it in a seperate file for the page only half of the ajax script works. I"m posting the code by not showing me passing all the variables so its smaller. I tested the php page zero errors. so no fatal errors stoping the page, but still like i said posting the java script on the page works fine. Its just when I make it as a included link. Maybe my idea of how including a java script is all wrong and i can only call java script functions from a external script? <script type="text/javascript" src="/system_lords/jquery/evaluate.js"></script> $(document).ready(function() { $("#evaluate").click(function(event) { event.preventDefault(); $.ajax({ url: "/System_Lords/ajax/include_evaluate.php", type: 'POST', dataType: 'json', data: { attacker_jaffa: $('#jaffa').val(), defender_jaffa: '<?php echo $defender_jaffa; ?>' }, success: function(response) { $('#evaluate_box').html(response.evaluate); } }); }); }); And here is the php file that the jquery is reading <?php require("../functions/function_battle.php"); /*/ ******************************************** EVALUATE THE ATTACK **************************************************************** /*/ // evaluates rather or not the player will win the battle // prevents sending a blank form / if all fields are empty if(empty($_POST['attacker_jaffa']) && empty($_POST['attacker_staff_cannons']) && empty($_POST['attacker_bombers']) && empty($_POST['attacker_mother_ships'])) { echo json_encode(array("evaluate" => "<table width='100%' align='center' border='1' cellspacing='1' cellpadding='8'> <tr class='odd'><th style='font-size:1em; letter-spacing:2px;'>You havn't selected any units to attack with.</th></tr> </table>")); }else{ //******************************************************Attacker Points**************************************************************************************************** // amount * setting $o_jaffa = ($_POST['attacker_jaffa'] * $_POST['offense_jaffa']); $o_staff_cannons = ($_POST['attacker_staff_cannons'] * $_POST['offense_staff_cannons']); $o_bombers = ($_POST['attacker_bombers'] * $_POST['offense_bombers']); $o_mother_ships = ($_POST['attacker_mother_ships'] * $_POST['offense_mother_ships']); // raw attack points of all attacker units $attacker_points = ($o_jaffa + $o_staff_cannons + $o_bombers + $o_mother_ships); // figures the bonus's for the attacker $attacker_bonus = ($attacker_points * $_POST['attackers_weapons_tech']); // adds the attacker poitns with the bonus to give a total $attacker_total = ($attacker_points + $attacker_bonus); //******************************************************Defender Points**************************************************************************************************** // amount * setting $d_jaffa = ($_POST['defender_jaffa'] * $_POST['defense_jaffa']); $d_staff_cannons = ($_POST['defender_staff_cannons'] * $_POST['defense_staff_cannons']); $d_bombers = ($_POST['defender_bombers'] * $_POST['defense_bombers']); $d_death_gliders = ($_POST['defender_death_gliders'] * $_POST['defense_death_gliders']); $d_mother_ships = ($_POST['defender_mother_ships'] * $_POST['defense_mother_ships']); $d_staff_turrets = ($_POST['defender_staff_turrets'] * $_POST['defense_staff_turrets']); $d_staff_fortress = ($_POST['defender_fortress'] * $_POST['defense_fortress']); // adding up all the defense points of all the units $defender_points = ($d_jaffa + $d_staff_cannons + $d_bombers + $d_death_gliders + $d_mother_ships); // figures out how much defense points turrets and fortress gives $defender_bonus = ($defender_points * $d_staff_turrets) + ($defender_points * $d_staff_fortress) + ($defender_points * $_POST['defenders_weapons_tech']); // figures out how much defense with battle chance gives $chance = ($defender_points + $defender_bonus * $_POST['battle_chance']); // adds the total points plus the bonus plus the chance for the total $defender_total = ($defender_points + $defender_bonus); /*/ ****************************************** Decides who wins the battle *************************************************************************************************** /*/ list($condition_attacker,$condition_defender,$attacker_rate) = win_lose($attacker_total,$defender_total,$_POST['battle_chance']); $attacker_total = number_format($attacker_total); $defender_total = number_format($defender_total); $attacker_rate = $attacker_rate; echo json_encode(array("evaluate" => "<table width='100%' align='center' border='1' cellspacing='1' cellpadding='8'> <tr class='odd'><th style='font-size:1.2em; letter-spacing:2px;'>Evaluate</th></tr> <tr><td>Attacker Points: $attacker_total</td></tr> <tr><td>Defender Points: $defender_total</td></tr> <tr><td>Chance of Success: $attacker_rate</td></tr> </table>")); } Notice how I have a if else statement in the php file. the first statement works. where its checking for empty inputs. but for some reason when the statement is reading the else statement nothing happends. so because its reading the first side of the statement ajax is working i guess. the largest problem is i cant see any errors cause i cant figure out how firbug works on showing errors.
  17. i just started ajax like two days ago so beware haha. i notice you said you click like and it refreshes the page? right there sounds like something is wrong. is the like link or button sharing the same id of something else on the page? cause a button made for ajax shouldnt be refreshing the page. i notice i had a situation like this and a link i was clicking on was sharing the same id as a button
  18. Hey Thorpe thanks alot, i got everything figured out now. figured out how to grab form data and pass variables to the php file. Man my mind is going a million miles an hour thinking of all the kewl stuff i can build now knowing how to use ajax. in a few months im going to make a much more advance game map. in the mean time i want to make a chat system. I really like using Json.
  19. lol i dont know what was going on. probably cause i have to many windows open. but everything i said was going on wasnt. when i delete the php code it doesnt work at all like it should. I had the example up in another window so i think i edited it which wasnt the real foo.php file.
  20. I got rid of the data field and then added something into the array and it works. so now i know im grabing from the file. I dont understand how its was able to echo it when i got rid of the php array in the php file. cause its response.msg so i would think it could only grab the key in the php file.
  21. Ahh i just got rid of the foo.php file and it still works. so ajax isnt even reading from the file its just posting whats in data: thats makes sense why the keys wasnt working cause it wasnt even reading from an array or anything.
  22. oh maybe it is a cleaner better idea to just make a new Div for every return?
  23. Sorry Thorpe, im really trying to understand this, read about json for the first time. But i dont see any json code going on in this script? I attempted to add a 2nd return to your code so if I understand this right msg1_from_js is the name of the _POST im grabing from responce is responce .key now I want to put these into a variable i guess so i can like print var msg1 = $('#foo').html(response.msg1); document write it i think it is for java script" as I wish in my DIV. so i dont really want to mention the #foo id. also i noticed if i just do this $('#foo').html(response.msg1); $('#foo').html(response.msg2); The second one just over writes the first one lol. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script type="text/javascript" src="/system_lords/jquery/jquery-1.7.1.min.js"></script> <script> $(document).ready(function() { $("#linky").click(function() { $.ajax({ url: 'foo.php', type: 'POST', dataType: 'json', data: { msg1_from_js: 'Hello from jQuery', msg2_from_js: 'Hello again from jQuery' }, success: function(response) { var msg1 = $('#foo').html(response.msg1); var msg1 = $('#foo').html(response.msg2); } }); }); }); </script> </head> <body> <a href="#" id="linky">Click</a> <div id="foo"></div> </body> </html> <?php echo json_encode(array('msg1' => $_POST['msg1_from_js'] , 'msg2' => $_POST['msg2_from_js'])); ?>
  24. lol that was confusing the heck out of me haha. , cause i barley know java script as it is lol. alright its all working now. Im going to bed. will take off from here when i wake up. one question though. this whole json thing is new to me lol. You are putting the POST in an array. so how do I echo each value seperatly when Im returning more then one thing in the array, do I use list() like i would a php function?
  25. alright i have firebug now I cant see where it shows errors on it though. I added the quotes around json and still have the error. IE is saying expecting : on line 27 I should of noticed the quotes not being around json my text editor was saying something was wrong and I didnt realize it. I notice the comma before success. so success is acting as the 5th parameter? how can that be shouldnt each parameter be a word followed by a colon? trying to understand the syntax on how its changing towards last
×
×
  • 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.