Jump to content

zero_ZX

Members
  • Posts

    223
  • Joined

  • Last visited

Everything posted by zero_ZX

  1. So, after reviewing my code, it would appear that a variable was misspelled which is why the chance of winning was a set 30%..
  2. Hi, I basically want a function that takes a parameter which is a percentage chance of the functioning returning true. A user can move from tier 1->10 and at tier 1 there's a 70% chance to move to tier 2, from tier 2 there's a slightly less chance to move up, and so on. I tried with the following piece of code: public function rollTheDice($winnerPercentage) { $number = rand(1, 100); if ($number <= $winnerPercentage) return true; return false; } The above code makes logical sense to me: 1. Pick a random number between 1 and 100. 2. If that number is less than or equal to the percentage, then we passed (example, if the random number is less than or equal to 70.. there must be a 70% chance of this?) This however does not seem to work, in fact it appears that when simulating a roll, 70% fails at the very first step (where there is a 70% chance of winning..) To actually make it to tier 10, has yet to be accomplished, so by simulating this with unlimited attempts for 120 seconds straight doesn't seem to "win". I tried (just for fun) and change the if-statement so: if ($number >= $winnerPercentage) This seems to be working quite well, as the simulator quickly reaches tier 10 this way. Any suggestions to code changes, or can someone explain why it is working way better when exchanging less than with greater than?
  3. Hi, sorry about that, you made the correct assumption <title> '.$lang['PAGE_TITLE'].'</title> I thought the lang array was actually global as it's not in any function, would I need to declare the $lang variable global?
  4. I actually ran into some new issues. It appears that I cannot use the variables that I have now included. From my portolio.php I include the header.php <?PHP require_once("../../inc/common.inc.php"); require_once("inc/header.php"); DisplayHeader(); ?> From the header.php I include the main.php <?php //require_once("../inc/common.inc.php"); require_once("lang/main.php"); /** * Created by JetBrains PhpStorm. * User: Mikkel * Date: 05-08-13 * Time: 12:07 * To change this template use File | Settings | File Templates. */ function DisplayHeader(){ //.... } From the main.php I include a single language file: <?php //session_start(); //header('Cache-control: private'); // IE 6 FIX if(isSet($_GET['lang'])) { $lang = $_GET['lang']; // register the session and set the cookie // $_SESSION['lang'] = $lang; setcookie('lang', $lang, time() + (3600 * 24 * 30)); } //else if(isSet($_SESSION['lang'])) //{ // $lang = $_SESSION['lang']; //} else if(isSet($_COOKIE['lang'])) { $lang = $_COOKIE['lang']; } else { $lang = 'en'; } switch ($lang) { case 'en': $lang_file = 'en.php'; break; case 'da': $lang_file = 'da.php'; break; default: $lang_file = 'en.php'; } require_once ("lang/".$lang_file); ?> In which the variable $lang is set $lang = array(); $lang['PAGE_TITLE'] = 'My website page title'; Yet I receive this message: [Thu Aug 22 13:06:27 2013] [error] [client 83.92.74.170] PHP Notice: Undefined variable: lang in /home/thomsen/mikkel/inc/header.php on line 26,
  5. Hi kicken, Thanks a lot for you in-depth answer. It really helped me understand the include behind-the-scene - and solved my problem.I ended up using the common.inc as you did.
  6. So, depending on where I include the header from, I would need different paths for including the lang file? If so is there any alternative? I will be using different paths multiple times.
  7. Hi, I'm having issues with included files within included files. This is my project: I browse my portfolio.php and I receive this error: [Wed Aug 21 19:50:01 2013] [error] [client 83.92.74.170] PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required '/home/thomsen/mikkel/html/portfolio/lang/main.php' (include_path='.:/usr/share/pear/') in /home/thomsen/mikkel/inc/header.php on line 3, referer: http://www.mikkel.thomsen.im/ In my portfolio.php I have: <?PHP require_once("../../inc/header.php"); $title = "Test"; ?> In my header.php I have: <?php require_once("../lang/main.php"); I don't know why it cannot get this file as I move up to my "project", into "lang" and fetch the file, which doesn't exists for some reason. This error is not caused by file permissions. Thanks in advance
×
×
  • 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.