Jump to content

madmenyo

Members
  • Posts

    38
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

madmenyo's Achievements

Member

Member (2/5)

0

Reputation

  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 .
×
×
  • 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.