Just started to learn php and was wondering if someone could give me a tron script they've made, so that I can try and figure out what it does just by reading it.
Not anything too hard yet, only learned a few things.
Learning PHP
Re: Learning PHP
This is a pretty simple script, I made it in my earlier years of php when I didn't use tabulars yet, I would say about 2013.
Code: Select all
#!/usr/bin/php
<?php
$player_enter = array(
"Hello",
"Hi"
);
While(!feof(STDIN))
{
$line = rtrim(fgets(STDIN, 1024));
$split = explode(" ", $line);
if(preg_match("/^PLAYER_ENTERED/", $line))
{
$val = rand(0,(count($player_enter)-1);
echo "say {$player_enter[$val]}\n";
}
if(preg_match("/^SHUTDOWN/", $line)) exit();
}
?>
Re: Learning PHP
Cheers, Nelg, keep um coming.
I can gather that it randomly says "Hello" or "Hi" when a player enters, but that's most likely all I get so far. There's few things there I've not learned yet.
Am I right in thinking that I'd have to learn whatever commands and directories to make scripts for tron (or any other game).
Another thing I'm wondering (dunno if it sounds daft or not... Learning). Is there variables that I can't use because they'd conflict?
Btw, a lot of what I ask may sound stupid, I'm only 50% through the PHP lessons on Codecademy, thank's for directing us to it, Sinwav.
I can gather that it randomly says "Hello" or "Hi" when a player enters, but that's most likely all I get so far. There's few things there I've not learned yet.
Am I right in thinking that I'd have to learn whatever commands and directories to make scripts for tron (or any other game).
Another thing I'm wondering (dunno if it sounds daft or not... Learning). Is there variables that I can't use because they'd conflict?
Btw, a lot of what I ask may sound stupid, I'm only 50% through the PHP lessons on Codecademy, thank's for directing us to it, Sinwav.
Re: Learning PHP
Here's a tutorial I wrote about a year ago ..
http://forums3.armagetronad.net/viewtop ... 12&t=23539
And here's little script for map rotation without any explanation ..
http://forums3.armagetronad.net/viewtop ... 32#p280733
http://forums3.armagetronad.net/viewtop ... 12&t=23539
And here's little script for map rotation without any explanation ..
http://forums3.armagetronad.net/viewtop ... 32#p280733
Re: Learning PHP
Thanks.
I had a quick read through it and it looks really helpful.
I'll have a thorough look tomorrow, it's starting to give me a sore head lol.
Think I'm trying to work things out that I've not yet learned, doesn't help.
I had a quick read through it and it looks really helpful.
I'll have a thorough look tomorrow, it's starting to give me a sore head lol.
Think I'm trying to work things out that I've not yet learned, doesn't help.
Last edited by ConVicT on Thu Mar 26, 2015 2:06 pm, edited 1 time in total.
Re: Learning PHP
A sidenote: You should probably use
While(!feof(STDIN))
instead of
While(true) or While(1) etc etc
Why?
If the server shuts down with While(True) it will generally eat your CPU and RAM, which I'm sure is a problem in dukevin's scripts...
Thank you to Durf for pointing that out in my scripts. I wouldn't have known because I originally learned php from looking at other scripts initially. (Dukevin's... go figure... I guess it just shows how easy PHP is)
While(!feof(STDIN))
instead of
While(true) or While(1) etc etc
Why?
If the server shuts down with While(True) it will generally eat your CPU and RAM, which I'm sure is a problem in dukevin's scripts...
Thank you to Durf for pointing that out in my scripts. I wouldn't have known because I originally learned php from looking at other scripts initially. (Dukevin's... go figure... I guess it just shows how easy PHP is)
- dukevin
- Round Winner
- Posts: 219
- Joined: Mon Aug 30, 2010 8:25 am
- Location: Southern California
- Contact:
Re: Learning PHP
No that doesn't. The former method is only useful if you terminate scripts with KILL_SCRIPT, I use screen sessions.aP|Nelg wrote:A sidenote: You should probably use
While(!feof(STDIN))
instead of
While(true) or While(1) etc etc
Why?
If the server shuts down with While(True) it will generally eat your CPU and RAM, which I'm sure is a problem in dukevin's scripts...
You make it sound like my scripts are bad...aP|Nelg wrote: I originally learned php from looking at other scripts initially. (Dukevin's... go figure... I guess it just shows how easy PHP is)
@Convict I have a tutorial here: http://rxtron.com/scripts/tutorial.html
Re: Learning PHP
Well it does with my setup though. (and it doesnt use SPAWN_SCRIPT/KILL_SCRIPT) though I'm thinking about switching to it since I fixed the bug in the CP.dukevin wrote:No that doesn't. The former method is only useful if you terminate scripts with KILL_SCRIPT, I use screen sessions.
Sorry about thatdukevin wrote:You make it sound like my scripts are bad...