Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] brak odpowiedzi (zawieszenie)
Forum PHP.pl > Forum > Przedszkole
AsenClave
  1. function attribute_modification( $attribute ) {
  2. $a = 2; $b = 3; $c = -4;
  3.  
  4. $return = 0;
  5.  
  6. while( ! $return ) {
  7. if ( $attribute == 1 ) $return = $c - 1;
  8. if ( $attribute == $a || $attribute == $b ) $return = $c;
  9.  
  10. $a += 2; $b += 2; $c++;
  11. }
  12.  
  13. return $return;
  14. }
  15.  
  16. function dice( $walls, $ratio, $bonus ) {
  17. $return = 0;
  18.  
  19. for( $k = 1 ; $k <= $ratio ; $k++ ) {
  20. $return += rand( 1, $walls );
  21. }
  22.  
  23. return $return + $bonus;
  24. }
  25.  
  26. function randomize_attributes() {
  27. $dices = array ();
  28. for ( $i = 1 ; $i <= 6 ; $i++ ) {
  29. $tmp = array ( dice( 6, 1, 0 ), dice( 6, 1, 0 ), dice( 6, 1, 0 ), dice( 6, 1, 0 ) );
  30.  
  31. sort( $tmp, SORT_NUMERIC );
  32.  
  33. $dices[ $i - 1 ] = $tmp[ 1 ] + $tmp[ 2 ] + $tmp[ 3 ];
  34. }
  35.  
  36. return $dices;
  37. }
  38.  
  39. function test_attributes( $dices ) {
  40. $modification_summary = 0;
  41.  
  42. for ( $i = 1 ; $i <= 6 ; $i++ ) {
  43. $modification_summary += attribute_modification( $dices[ $i - 1 ] );
  44. }
  45.  
  46. sort( $dices );
  47.  
  48. if ( $modification_summary < 1 || $dices[ 5 ] < 14 ) return false;
  49.  
  50. return true;
  51. }
  52.  
  53. echo test_attributes( randomize_attributes() );


echo nie zwraca wyniku :/ przeglądarka cały czas czeka na odpowiedź z serwera
Fifi209
Bo masz nieskończoną pętlę

  1. function attribute_modification( $attribute ) {
  2. $a = 2; $b = 3; $c = -4;
  3.  
  4. $return = 0;
  5.  
  6. while( ! $return ) {
  7. if ( $attribute == 1 ) $return = $c - 1;
  8. if ( $attribute == $a || $attribute == $b ) $return = $c;
  9.  
  10. $a += 2; $b += 2; $c++;
  11. }
  12.  
  13. return $return;
  14. }
  15.  


jak na moje oko. ;p
nospor
Pewnie zapetlil ci się na WHILE - sprawdź
AsenClave
acha, zapamiętam, nie nazywać zmiennych tak jak funkcji.... sciana.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.