Staredit Network

Staredit Network -> Computers and Technical -> PHP Help
Report, edit, etc...Posted by BeeR_KeG on 2006-04-15 at 15:31:52
Alright, so I'm making my own PHP game like the ones Moose has done during the past few months.
I'm starting to set up testing conditions that will later be replaced with SeN's MySQL.

I've got:
mt_rand(0 , 2500);

And I want to make $minerals equal to the number that mt_rand(0 , 2500); will generate. How do I do that?
Report, edit, etc...Posted by Kookster on 2006-04-15 at 15:38:03
first off what is this: mt_rand(0 , 2500);
looks like a trigger but ive never seen it before
Report, edit, etc...Posted by BeeR_KeG on 2006-04-15 at 15:40:38
It's PHP, a web-programming language,not Starcraft triggers or anything.

mt_rand(0 , 2500) will generate a random number between 0 and 2500.
Report, edit, etc...Posted by Centreri on 2006-04-15 at 15:44:58
$minerals = mt_rand(0, 2500);

Or did I misunderstand something? You can use functions when defining variables.
Report, edit, etc...Posted by Pie_Sniper on 2006-04-15 at 15:45:20
Just do:
CODE
$minerals = mt_rand( 0, 2500 );
Report, edit, etc...Posted by Kookster on 2006-04-15 at 15:46:52
gotchya, figured it was something random, but for that program i dont know it

can I download it from somewhere or does it cost money?
Report, edit, etc...Posted by thien on 2006-04-15 at 15:47:34
You can't download PHP... Lol. It's a programming language.
Report, edit, etc...Posted by Centreri on 2006-04-15 at 15:48:51
You can download support for PHP on a server hosted on your computer (probably apache), and then you can practice it on your local computer, or you can get online hosting with PHP support and use it there. It's free.
Report, edit, etc...Posted by Wilhelm on 2006-04-15 at 15:49:12
If you don't know what he's talking about, don't post. Why would he ask a trigger question in "programming & websites"?
Report, edit, etc...Posted by BeeR_KeG on 2006-04-15 at 15:49:33
Thanks guys.
I was doing $minerals=mt_rand(0 , 2500); so I was getting a parse error. I'll keep this thread open for all the PHP questions I'll be needing.

PHP is free, all you need is learn it and create with it. It's like HTML, only PHP is used to manipulate HTML on the server-side. You will need to download an Apache server tot hat your PC can parse the PHP code.
Report, edit, etc...Posted by Centreri on 2006-04-15 at 15:54:41
You got a parce error because you didn't put a space between text and the =? Never got that before.
Report, edit, etc...Posted by BeeR_KeG on 2006-04-15 at 16:25:17
It's possibly the version of PHP that I'm using. When I did PHP before re-downloading my current Apache, I didn't use spaces.
Report, edit, etc...Posted by Kookster on 2006-04-15 at 16:31:19
im talking about a program that can edit the code/create the code its self, you know something like visual basics/ c++.

But that doesnt matter since beer keg just said its html code I know how to edit that.

So dont assume i dont know what im talking about Wilhelm.

Besides the fact that is what this web site is for to ask questions to learn, not to be rude.
Report, edit, etc...Posted by BeeR_KeG on 2006-04-15 at 16:44:10
I said it's like HTML. It's used to create webpages.


Okay, I got this:

CODE
<?php
$minerals = mt_rand(0, 2500);
?>

This is data.php, it's used to create all the variables I need. For now, it only has minerals.

CODE
<?php
include_once "data.php";
echo "You currently have " . $minerals . " minerals <br />";
?>

This is index.php, there is more code in this file, but that's not important.

CODE
switch($minerals)
{
 case $minerals < $_POST["minbet"]:
 //error load the error page
}

This is form.php and where I need $minerals to also be included. The problem is that I can't include data.php again because it'll generate a different number. How to I include only 1 variable or a piece of code from one file to another and not getting a different number? I need the exact same number that was randomized on that specific pageload.
Report, edit, etc...Posted by Centreri on 2006-04-15 at 16:53:27
I might be wrong, but you can make the original variable global and erase it later. I'd use the $_SESSION thing for that. It might not work if you use an old version of PHP, though. If you don't want it to generate another number, either make it two seperate files, one which generates and one which doesn't, or make it so that when the second file recieves everything it sets a global boolean to 'true', and when the variable is set to 'true', the first file acts differently.
Report, edit, etc...Posted by Shmeeps on 2006-04-15 at 18:18:16
Just make it global

CODE
global $minerals;


In the page that has the include.

Or you could store it in a session, or another superglobal.

Also, why are you using include? You should use require, so that if it can't be included the script will fail. Prevents cheating and whatnot.
Report, edit, etc...Posted by BeeR_KeG on 2006-04-16 at 11:24:39
Alright, I'm getting some sort of parsing error, but I can't seem to get it fixed.

CODE
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\easyphp1-8\www\form.php on line 12


form.php
CODE
<?php  
echo date("l dS of F Y h:i:s A"). "<br />";
echo "Welcome {$_POST["name"]} <br />";
switch($minerals)
{
 case ($minerals < $_POST["minbet"]):
 echo <<<HTML
 <meta http-equiv="refresh" content="3; URL=127.0.0.1/error.php">
 HTML;
 break;
 [b]case ($minerals >= $_POST["minbet"]):[/b]  
 include"dice_func.php";
 break;
 //insert array case to get error page when any character other than an integer is placed in $_POST["minbet"]
 //array must give true to symbols and letters
}
?>


I'm not seeing anything wrong with line 12.

==========

Then I went the to $minerals variable, but it still doesn't transfer.

index.php
CODE
<?php
session_start ( );
//This page is purely for testing purposes to create a non-existant MySQL which will represent SeN's
echo date("l dS of F Y h:i:s A");
echo <<<HTML
<form action="form.php" method="POST">
Enter your username: <input type="text" name="name" /><br />
Enter the amount of minerals you wish to bet: <input type="text" name="minbet" /><br />
<input type="submit" />
</form>
HTML;
require "data.php";
echo "You currently have {$minerals} minerals <br />";
//Need code to prevent players from playing within the same day (not 24 hour interval)
?>


form.php
CODE
<?php  
echo date("l dS of F Y h:i:s A"). "<br />";
echo "Welcome {$_POST["name"]} <br />";
echo $minerals;
?>


data.php
CODE
<?php  
$minerals = mt_rand(0, 2500);
global $minerals;
//The dice roll will be generated here
?>
Report, edit, etc...Posted by Centreri on 2006-04-16 at 11:38:51
When I use include, I make it in this format ..
CODE
include("file.extension");

It might be that your version doesn't support absence of the (), but other then that I don't know what might be the problem there. Is disc_func.php in the same directory as the file including it?

In index.php, for some reason you have <<<html with 3 in front and no closing to the tag.. It should be <html> (of course tongue.gif). What's the HTML; thing for?

And the rest looks fine..
Report, edit, etc...Posted by BeeR_KeG on 2006-04-16 at 12:20:52
Yoshi told me that those are the tags to do HTML in an echo.

echo <<<HTML <--open up HTML
Put your HTML code here
HTML; <---close HTML and echo

Yes, dice_func.php is in the same directory, it's a future file I'll have to code, it only containts some comments.
Report, edit, etc...Posted by Doodle77(MM) on 2006-04-16 at 14:50:00
Theres no space between include and "dice_func.php"
Report, edit, etc...Posted by Centreri on 2006-04-16 at 14:57:40
Those tags open and close the HTML in echo? I really doubt it. You can almost certaintly use the standard <HTML> and </HTML> tags.
Report, edit, etc...Posted by BeeR_KeG on 2006-04-16 at 15:59:29
Thanks.
As for the variable $minerals issue, what I was told to do was this:

Put session_start(); in every php file.
Then put $minerals = $_SESSION['minerals']; in form.php and data.php. It won't be put in index.php because data.php is included in index.php. It's sort of like a global session-only variable.

ADDITION:
I've got:
case ($minerals < $_POST["minbet"]):

Which I want to combine with:
case ($minerals <= 0):

How do I put it in once case so that the oucome is something similar to:
case ($minerals < $_POST["minbet"] && $minerals <= 0):
Report, edit, etc...Posted by Centreri on 2006-04-16 at 16:11:46
CODE
case(($minerals < $_POST['minbet']) && ($minerals<=0))

Oh, and it might be easier if you add this to the page recieving the post..
CODE
$minbet = $_POST['minbet'];

Much easier to work with.

Report, edit, etc...Posted by Doodle77(MM) on 2006-04-17 at 13:41:53
$minbet = $_POST['minbet'] or die('You are trying to manually edit URL's -.-')
Report, edit, etc...Posted by Centreri on 2006-04-17 at 15:00:40
Why shouldn't it work?
Next Page (1)