Jump to content

madmenyo

Members
  • Posts

    38
  • Joined

  • Last visited

    Never

Everything posted by madmenyo

  1. Well i'm using settimout (not setinterval, srry mistake) from java within that i'm calling a jquery function to communicate with PHP and the mysql db. The tilemap is generated with PHP and some tiles are fetched from the database. Currently the player can move around, center, scroll and dock into a station by clicking on a tile wich gives a popup with the available actions. But sometimes if i click it does not pop up, most of the time it does but there are moments i have to click several times before that popup shows. I think it has to do with the "setinterval" but im not sure. The page refreshes with the setimeout which cals a php page that queries the server and load the new generated map into my map div. Like this: <script> function turnlistener() { $.post('flightscript.php', { go: 'first'}, function(data) { $('#flightcontroll').html(data); }); $('#map').load('mapgenerator.php'); }; $(function() { setTimeout('turnlistener()', 1000 ); }); </script> flightscript.php sets the destination the player wants to go in the database. Then mapgenerator.php generates the tiles that need to be displayed. Once the script finishes it loops again so every second ( setTimeout('turnlistener()', 1000 ); ) the map refreshes to see if there is a player nearby, or an NPC which need to be implemented yet. -edit- If things are still unclear on what map i'm using, i'm generating my own using tile divs with a fixed size and float them next to eachother within a map div with a fixed size. Currently you can only see 11x11 tiles. Hope this helps.
  2. Hey, I hope this is a common problem and don't have to post all of my code. Anyway i made a tile map which auto refreshes with setinterval every couple of seconds. It checks the database for other players in the vicinity. But often when i click the map (which makes a popup with some actions to perform) nothing happens. Any thoughts what this might be and how to fix it?
  3. Hey guys, I'm thinking out a game and am now at a point where i'm designing the map system. But i'm not sure if it's way to much to handle for the database. It's a sandbox sci-fi game and in the end there will be loads of system to fly to. Now for each system i am planning to add a system map of 100*100 tiles to warp too. And on arrival you enter the local map 100*100 tiled. So just 1 system would have 100.000.000 table entries for each map tile. Now i'm still wondering if this would be to much gameplay wise. I might make it so you can only fly to significant locations on the system map like planets and astroid fields but then i still need all the table entries to build the map i guess.
  4. Hi folks, If thought i finally managed to make a 2 player game with PHP and Jquery but i my whole computer gets stucked when the first player has gets his 2nd turn. What i basically have are 2 .txt files where both players units are listed. I will read this file into an array. Each unit has a speed key wich value increases when that unit has made an action, i write the new speed to the file and the script runs again. Heres the script that decides which unit goes first. $time = 0; $found = 0; while ($found != 1) { foreach ($P1recruit as $p1) { if ($found == 1) break; if ($p1['speed']<$time) { $p1['speed'] = $p1['speed'] * ceil ($time / $p1['speed']); } elseif ($p1['speed']==$time) { $p1turn = true; $p2turn = false; $found ++; } } foreach ($P2recruit as $p2) { if ($found == 1) break; if ($p2['speed']<$time) { $p2['speed'] = $p2['speed'] * ceil ($time / $p2['speed']); } elseif ($p2['speed']==$time) { $p1turn = false; $p2turn = true; $found ++; } } $time ++; } Then follows all the HTML to build up the page. The player who has to act gets a form with choices to do with his unit. The other player gets "Opponents turn" in that window. So in the above code you see $p1turn or $p2turn gets true or false. This is for the Jquery script at the end of all the HTML to tell wich player needs to keep polling the unit files until theres a unit for him to act. Heres the script: if ($p1turn == true) { if ($battle['player2'] == $_SESSION['SESS_MEMBER_ID']) { echo " <script type='text/javascript'> function turnlistener() { $('#main').load('battlegetnextunit.php'); }; $(function() { setInterval('turnlistener()', 5000 ); }); </script> "; } } if ($p2turn == true) { if ($battle['player1'] == $_SESSION['SESS_MEMBER_ID']) { echo " <script type='text/javascript'> function turnlistener() { $('#main').load('battlegetnextunit.php'); }; $(function() { setInterval('turnlistener()', 5000 ); }); </script> "; } } Now for the first player (the one who starts the battle) he can act properly. The next player can act, but he still is longpolling the .txt files as the form resets. If he acts withing the 5 seconds (setInterval('turnlistener()', 5000 )) the other player gets his turn again but my whole computer starts strugling and i'm not able to select anything in the form. Maybe it's like the players get double longpolling the 2nd turn. But i only have the last code once and obviously only 1 of 2 can run as either $p1turn or $p2turn can be true and it can only run for one player. What could this be? Is doing it this way even possible? I'm trying to figure this out for days now, i really hope someone can help me out. Thanks!
  5. For further reference i'll put in my complete code. The function is from http://www.phpro.org/examples/Convert-Object-To-Array-With-PHP.html <?php // function to put JSON object to an array. function objectToArray( $object ) { if( !is_object( $object ) && !is_array( $object ) ) { return $object; } if( is_object( $object ) ) { $object = get_object_vars( $object ); } return array_map( 'objectToArray', $object ); } // An array for tesing purpose. $dbaray[0]['name'] = "Rage"; $dbaray[0]['health'] = "225"; $dbaray[0]['speed'] = "40"; $dbaray[1]['name'] = "Katosh"; $dbaray[1]['health'] = "150"; $dbaray[1]['speed'] = "50"; $dbaray[2]['name'] = "Snake"; $dbaray[2]['health'] = "275"; $dbaray[2]['speed'] = "60"; $dbaray[3]['name'] = "Dan"; $dbaray[3]['health'] = "350"; $dbaray[3]['speed'] = "45"; $dbaray[4]['name'] = "Wicked"; $dbaray[4]['health'] = "200"; $dbaray[4]['speed'] = "55"; print_r ($dbaray); echo "<br><br>"; $myFile = "testFile.txt"; $fh = fopen($myFile, 'w+') or die("can't open file"); //Put the array into a JSON encoded string wich is sent to file. $stringData = "".json_encode($dbaray).""; fwrite($fh, $stringData); //get the file contents and decode these into an object $file = file_get_contents('testFile.txt'); $obj = (json_decode($file)); //use the function to make an array from the object again. $array = objectToArray( $obj ); print_r($array); ?>
  6. Ow i guess i need this : http://www.phpro.org/examples/Convert-Object-To-Array-With-PHP.html but i'm gonna look into working with objects too as i have no clue -edit- Well this does not seem to work: $obj = (json_decode($file)); $array = (array) $obj; print_r ($array); -edit- But his function does do the job I can't believe i have been fiddling around for hours and hours to get a array into a file and read it back in. Json is a live saver and you are to Chris thanks a lot .
  7. Didn't look into your resources Chris but i will. -edit-(errr ow actually i did obviously )-/edit- Looks very promising indeed! And very easy too. Though i'm encountering a small problem which probably is easy to fix. i made a temp array that is similar to the array i need to fetch from my DB. The code looks like this now: <?php // Create some test data $dbaray[0]['name'] = "Rage"; $dbaray[0]['health'] = "225"; $dbaray[0]['speed'] = "40"; $dbaray[1]['name'] = "Katosh"; $dbaray[1]['health'] = "150"; $dbaray[1]['speed'] = "50"; $dbaray[2]['name'] = "Snake"; $dbaray[2]['health'] = "275"; $dbaray[2]['speed'] = "60"; $dbaray[3]['name'] = "Dan"; $dbaray[3]['health'] = "350"; $dbaray[3]['speed'] = "45"; $dbaray[4]['name'] = "Wicked"; $dbaray[4]['health'] = "200"; $dbaray[4]['speed'] = "55"; print_r ($dbaray); echo "<br><br>"; $myFile = "testFile.txt"; $fh = fopen($myFile, 'w+') or die("can't open file"); $stringData = "".json_encode($dbaray).""; fwrite($fh, $stringData); $file = file_get_contents('testFile.txt'); print_r (json_decode($file)); The problem is (if it's even a problem as i don't know what it is) that the Decoded JSON returns: Array ( [0] => stdClass Object ( [name] => Rage [health] => 225 [speed] => 40 ) [1] => stdClass Object ( [name] => Katosh [health] => 150 [speed] => 50 ) [2] => stdClass Object ( [name] => Snake [health] => 275 [speed] => 60 ) [3] => stdClass Object ( [name] => Dan [health] => 350 [speed] => 45 ) [4] => stdClass Object ( [name] => Wicked [health] => 200 [speed] => 55 ) ) And the print_r ($dbaray); above returns: Array ( [0] => Array ( [name] => Rage [health] => 225 [speed] => 40 ) [1] => Array ( [name] => Katosh [health] => 150 [speed] => 50 ) [2] => Array ( [name] => Snake [health] => 275 [speed] => 60 ) [3] => Array ( [name] => Dan [health] => 350 [speed] => 45 ) [4] => Array ( [name] => Wicked [health] => 200 [speed] => 55 ) ) Whats the difference between those with stdClass Object? Do they work the same? What should i use to make them the same?
  8. This looks promising, i have looked at http://www.electrictoolbox.com/php-encode-array-json/ which shows an easy way to sent a PHP array to js. However is it possible to to write this to a file and retrieve this again using PHP or do you need Js to retrieve this? And a good place where i can find some info on this would be very helpfull. I will look further into this but i'm still open for other suggestions.
  9. Hi, I have a XHTML/PHP page that loads a PHP file each couple of seconds for building up the page. The PHP file should retreive data that keeps changing. What would be the best way to store and retreive the data? Obviously i can do this with a database but that will put a lot of stress on the server as each user keeps polling the database. So i was looking into other methods of doing this. I have tried doing this with a plain text file and CSV files using fwrite to put the initial data into a file with separators. Then retrieving that file and explode it into a multidimensional array again. I am unsuccessful here to assign the key values to the new array. I have also tried many snippets for this but these where also not working properly for me. Maybe XML is the key, i didn't really delve into it yet but it seems i have to get extra programs or parser to actually write and change files? But then again i can't find any working tutorials on how to put multi dimensional strings back and forth between PHP and XML. So what needs exactly to be done. Well i'm creating a game where you can fight each other with 4 units on a turn base. The units have a speed stat that determines when it's there turn to act. Like if (unit 1) has 3 speed and (unit 2) 5 speed they will move like this on the time line (unit 1) -> (unit 2) -> (unit 1) -> (unit 1) -> (unit 2). So the plan is each time the user acts with a unit to increment it's speed by the base value. A script will run each time picking up the next unit in line. The PHP page does a check on which player the unit belongs to and if that matches the players ID it will sent the necessary information. The other player will get something like "not your turn". Tx,
  10. I can see clearly now the rain has gone A heap of thanks!
  11. Great! Wasn't aware i could do it that way. I still like to know how to put them into a multidimensional array as that might be easier to work with the data. But I'll use your method for now. Tx a lot,
  12. Hi there. In my database table i have multiple records with multiple values that need to be fetched into an array. I think i need to do this as a multidimensional array but i'm not sure how. I can also put each record into a sepperate array but then i'm not sure how to increase the arrays name within the while loop. Hers an example: while ($recruits = mysql_fetch_assoc($recruitsquery)) { $recruit1 = array(name => $recruits['name'], health => $recruits['health'], damage => $recruits['damage'] } So how would i change $recruit1 in the next loop to $recruit2? Or how would i build a multidimensional array?
  13. Lol title gives me a tool tip.... mehhh... I mark this one unsolved again as i'm really looking for a better way to do this.
  14. As always a couple of minutes after my post i fix things . Please ignore all my future posts.... I was able to give the card DIV a title and sent that with Jquery through this line: $.post( "recruitcode.php", { cardID: $(this).attr("title")} Now i can generate all these divs and give them the correct title. Then when i click 'm i can sent the correct information to the script that adds them to the players private DB. Anyways, if you know of other ways i'd really like to know as title allows you to sent only 1 variable. Fortunately i only need just 1.
  15. Hi folks, I try to keep my explanation as short as possible. I have a page that loads a php script on opening with all the cards in my database. When a player clicks a div of a specific card div a popup comes up asking if he wants to add this card to his collection. When choosing yes the specific card goes into his private collection. Problem is, the card div has already got an ID for layout purpose. Can i give this div somekind of extra info while generating them from my PHP script. And then sent that info back to the PHP script that should add the card to the players DB. I am using Jquery to sent and receive data from my php script something like this. <script> $(document).ready(function(){ $('#halfrow').click(function(){ //<-- the div that gets clicked $('#popuplarge').css({'visibilty':'visible'}) //<-- the popup $.post( "addcard.php", { cardID: $("#cardDiv").val()}, //<--- here i sent the info to the php script so the correct card can be added. function(data) { $("#popuplarge").html(data); }); }); }); </script> Is there a way to add a hidden <input /> with the card ID div and then sent that trough with Jquery? Still the same problem here as all the divs have the same ID and the jquery script would not know witch hidden <input /> to sent. I could also make the whole div a button but thats probably not desirable for layout purpose. I can always add a button to the div wich has to be clicked. But i would really like the user can click anywhere on the div. And i rather not want to redesign the div .
  16. Hi, I'm kinda stuck on a query. I have a table for messages with a timestamp field. Now i want to store a maximum amount of messages in that table, so each time a message is entered it must check the table if the num_rows > $maximum. If that is true lookup the timestamp of the latest message of the last $maximum messages. Get that in a variable or array so i can delete everything older from the table. Now i can de a query like this: $lastmsg = mysql_query (" SELECT time FROM chat ORDER BY time DESC LIMIT $store_num ") or die (mysql_error()); And loop through the query, check the oldest timestamp each loop and if it's older then put that into a variable. But obviously i already know it's the last table . I would love to do something like this: $lastmsg = mysql_query (" SELECT LAST(time) FROM chat ORDER BY time DESC LIMIT $store_num <---- this needs priority ") or die (mysql_error()); But like SELECT MIN(time) it would just select the minimum in the whole table and then LIMIT becomes obviously useless unless there are more rows with the same minimum in the entire table. So can i build a query to select 1 row out of many rows and how to do that? tx!
  17. Hi, I was wondering how i can make interactions that other users can pick up? How do i pass information to another user? For example: 1. Player A clicks on Player B's name in a window and chooses to attack this player. 2. Player B gets a message in his screen and chooses yes. 3. Server rolls dice on who may start ans passes this to both players. 4. First players chooses what he wants to do and clicks finish. 5. Other player gets a go to make his move. I am using PHP, AJAX, Javascript and MySql. But i can't find anything on how to approach this. Maybe i'm using the wrong search terms so enlighten me on what functions i should use? With my knowledge i can get this to work with AJAX requests. I would make a fight toggle for the player and ajax keeps queriing the server if that toggle has been set, if so that message would appear that he got challanged. Then for the turns the same, keep doing AJAX requests to see if the finished turn toggle is set. Would this be the way to go? Or are there other sollutions that are more efficient, practical and better?
  18. I figured the query probably overwrites mapgen[tileID] therefor it just returns 1 value. If i do a num_rows it actually returns 9 so thats good. Is there a mysql function that avoids rows being overwritten? or do i have to make a function that puts the data into a array?
  19. I was planning on figuring that out later on, first i need to get more then one value into $mapgen.... i would not not to order my query if it only returns one value right?
  20. Mind, i'm still trying to get a global idea to HOW i'm about to get my game map to work for me. First i want to get my map to rebuild each time i move a tile. As there are no real tutorial on how to do this with mysql, PHP, javascript, HTML and AJAX i started up a little test environment. I'm still fiddling around with how to build my query but it should look something like this: $xpos = 3; //this variable should get feeded by a $_GET or $_POST or something. $ypos = 3; //this variable should get feeded by a $_GET or $_POST or something. //build query $mapquery = mysql_query (" SELECT tileID FROM world WHERE (xpos BETWEEN '$xpos - 1' AND '$xpos + 1') AND (ypos BETWEEN '$ypos - 1' AND '$ypos + 1') ") or die (mysql_error()); $mapgen = mysql_fetch_assoc($mapquery); print_r ($mapgen); //this only gives me the tile i'm currently on -> Array ( [tileID] => 2 ) I have build my table "world" like this: systemID -> not really used yet as there is just 1 system. orderID -> dunno if i really need this one as i could probably order my table from the xpos and ypos. xpos ypos tileID -> refers to the primary key of the table where i store my tiles. I have filled this table with 25 rows to represent a 5x5 grid. where all the outer tiles are 3 (water) the middle tile (3,3) is 2 (desert) and the rest are 1 (grass).
  21. I created the multiple field key so no need to explain that. Shame i can't edit my posts.....
  22. How do i create a multi column index? Because without a unique key my DB gives a error like no key defined. Also, what kinda operation would be faster? Like i said, i won't ever look up a query in this table by a primary key but by it's location (systemID), then see how they are ordered with (orderID) and select the tileID for display. So it looks like a unique key for each tile would be useless. Offcourse i want the most efficient method so if adding a unique key to every single tile in the game would speed up things i add that in, but i can't see how that would speed up things atm. Thanks!
  23. Hey guys! I am wondering if it's necessary to give this table a primary or unique key. It's for storing tile map arrays in the DB, here is the table i need to create: Table maps: systemID - refers to the system the player is in orderID - This is for ordering the tiles so i can fetch an array in the correct order. I could make this one the primary but as i have a map for each system i would like to have this start at 1 for each system. xpos - horizontal position ypos - vertical position tileID - refers to the tile that needs to be shown with these fields every row is unique, i would never call up a row with a unique or primary key but with the systemID and fetch it in order by orderID. If i make orderID primary and i have 2< maps i can't add to the first map so i would need another field with a unique/primary ID, is this required? What are the possibilities here? tx.
  24. I fixed the style problem with FF. I had to correctly refference the CSS element, or so i was told . Instead of using: gamebox.style.backgroundColor = 'rgb(128,0,0)'; I had to use: document.getElementById('gamebox').style.backgroundColor = 'rgb(128,0,0)'; Still some questions on why this does work without the "correct" refference: squareman.style.top = squaremanTop + 'px'; But i just give this thread the solved mark, hope this one can help some other people out.
  25. Well, i am able to move the cube/square across the gamebox with this code in firefox. The problem is changing the background color when a certain even is true. Or for that matter make "something" happen if a statement about the square is true or false.
×
×
  • 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.