PHP change max execution time
Posted 30 March, 2009 in Other Stuff
Having trouble with your PHP scripts timing out? You need to change the max execution time. Try one or both of the following:
ini_set(“max_execution_time”, 60); // Set to 60 seconds
set_time_limit(60); // Set to 60 seconds
For no time limit try:
set_time_limit(0); // No time limit
You might still run into problems of your server is running PHP in safe mode. Also your server will have a timout that might need to be changed.
If you have access to php.ini then try changing max_execution_time to a higher value. This will however effect all your PHP scripts.
HTML for beginners
Posted 20 December, 2008 in Other Stuff
HTML or HyperText Markup Language is a set of tags added to text that give instructions regarding the display and structure of the text.
- HTML is just a text file
- Web pages are HTML documents
- HTML documents can be created and edited in any text editor such as notepad in windows
- Tags start with an open angle bracket “<” and end with a closed angle bracket “>”
- Generally there is a start tag and an end tag. One to start the change in text style and one to end it.
- HTML files end with file extension .htm or .html. Which extension you use is up to you and makes no difference.
- Generally browsers such as Internet Explorer or Firefox are used to view HTML files
Editing HTML files
To edit an HTML file you will need a text editor such as notepad. Don’t use Word or any other fancy word processor as you want the text to remain free of any hidden characters and tags such software packages often add to a text file.
Notepad is the simplest editor, but there are hundreds of editors out there including WYSIWYG (What You See Is What You Get) editors such as Dreamweaver (expensive) and Nvu (free). For now it is best to stick to a simple text editor.
First web page
Start a new file. Save this file as test.htm. Now we need to add some basic tags that tell the browser a little about the file. Add the following lines to the text file:
<html>
<head>
<title>
Test File
</title>
</head>
What are the tags telling the browser?
<html> – HTML starts here
<head> – Start header tags such as the page title. Header tags are not visible, but provide important information for the browser
<title> – The title of the page starts here
Test File – This is the wording for the title. It can say anything you like but make it relevant to what ever the page is about. This will show up in the bar at the top of your browser window.
</title> – End the title wording
</head> – End the header tags
Now that we have told the browser a little about the page, we can begin to add the body text. Add the following to your HTML file:
<body>
Hello World!
</body>
</html>
As you can see the body starts with the <body> tag. The body area is what is to be shown in the browser. What do they mean?
<body> – Start the viewable page text. Tags will still be hidden but will effect the look and layout of the text
Hello World! – Sample body text. This will be shown by the browser.
</body> – End the body of this HTML page.
</html> – End the HTML document
Save it and view it in your browser. Hello World!
HTML Tags
There are many tags but below are a few of the most common.
<p></p>
Paragraph. This defines a paragraph. Anything inside this tag is part of the same paragraph. Ex: <p>Hello World!</p>
<br />
Line break. This tag does not have a closing tag. It creates a line break on the page.
<b></b>
Bold. This tags makes text bold.
<i></i>
Italic. This tag makes text italic.
<h1></h1>
Header 1. This is used to define the main header of a page.
<h2></h2>
Header 2, 3, 4, 5, 6. This tag as well as h3, h4, h5, h6 all define sub headers.
Putting it together
<html>
<head>
<title>Test File</title>
</head>
<body>
<h1>Hello World!</h1>
<p>This is a website. A simple one but it counts.</p>
<p>Lets try <b>bold</b></p>
<p>Lets try <i>italic</i></p>
</body>
</html>
Hyper links
The magic of the internet is the ability to link to other pages. This is done using the <a>this is a link</a> tag. The “a” in this case stands for anchor. In this tag we need to tell it where to link to. This is called the “href”. Put is together and you get:
<a href="http://www.futtock.co.uk" mce_href="http://www.futtock.co.uk">this is a link</a>
You put the address in the href and put what ever text you like where it says “this is a link”
Images
If you know the address of an image, or you have uploaded one to your web server you can place it on your page using the <img /> tag. As you can see it does not have a closing tag. It looks like this:
<img src="http://www.google.co.uk/intl/en_uk/images/logo.gif" />
You just place the address of the image in the src property.
Using the <img> tag inside an <a></a> tag you can now also make images link to other pages.
So what’s next?
Outlined above are the very basics of HTML. If you want to know more, the next thing to look into are CSS (Cascading Style Sheets) and probably tables.
Database driven scripts
Posted 24 October, 2008 in Other Stuff
I am currently working on a Scala InfoChannel project where the entire script needs to be database driven so clients can log into an online portal, and change the order of screens without the need for any technical knowledge.
This is done by the Scala script talking to a VBScript that in turn gets the data for the current page.
The trick is the use of the OnNotification function. Using this function you can tell the Scala script to jump to a certain location when a variable has changed.
Take the following OnNotification function and stick it into the first “Group:” before the “Sequence:” begins. Then set “VARIABLE” to anything you want. “VARIABLE” is then shared with a VBScript. When ever the VBScript changes “VARIABLE”, the OnNotification function send the script to “HandleAction”.
OnNotification("VARIABLE", Use("HandleAction"));
Then put the following :”HandleAction” event within the first Group Sequence. Perhaps at the bottom of the script.
The following example shows how if “VARIABLE” is the name of an Event, it will be sent to this event.
:"HandleAction"
{
Sequence:
GotoExpr(VARIABLE, Bookmark(bookmark));
}
For more on Scala Infochannel database driven scripts see:
http://www.futtock.co.uk/category/scala-infochannel/
Connect to MSSQL database
Posted 21 October, 2008 in Other Stuff
The following code can be used in VBScript to connect to a database. It uses both a timout and ping to make sure there is a connection to the database.
This is very handy when creating database driven Scala Infochannel scripts. It also uses error traping to make sure the script does not stop running when no connection was made so that you can use an alternative source of data such as text files.
' These are the database connection details. Change the IP address, Username and Password.
DBdetails = "Driver=SQL Server; Server=IPADDRESS; Database=sms; Uid=USERNAME; Pwd=PASSWORD"
' This is the IP address again
DBipaddress = "IPADDRESS"
On Error Resume Next ' Enable error handling
' Try to ping the database
Set WshShell = CreateObject("WScript.Shell")
PINGFlag = Not CBool(WshShell.run("ping -n 1 " & DBipaddress,0,True))
If PINGFlag = True Then
' Connect to the db
Set myConnection = CreateObject("ADODB.Connection")
myConnection.ConnectionTimeout = 5
myConnection.Open DBdetails
Else
Err.Number = 1
End If
If Err.Number <> 0 Then ' There was an error when connecting to the DB.
Else
' Code goes here if database was contacted
End If
Change Cursor Colour
Posted 21 October, 2008 in Other Stuff
When using input text boxes in Scala InfoChannel Designer, the default colour for the cursor seems to be yellow. There does not seem to be an obvious way to set this colour. The way around this is to change the yellow in the pallet to what ever colour you want or go straight to the source code and chagne the pen(11) value to one of the other colours such as Pen(1) for black.
Offline database driven scripts
Posted 21 October, 2008 in Other Stuff
Running a database driven scala script is great but what do you do if the connection to the database goes down?
The solution is to not have a database driven script!
Seriously though, make the script text file driven, so that all the data required by the script comes from a text file. Then have a VBScript (or what ever windows script you use) update the text file.
You can have the Scala script run the “updater” VBScript, but remember to have Wait turned off, otherwise the scala script will stop everytime it ries to update the text file.
Scala InfoChannel Get Player Name
Posted 21 October, 2008 in Other Stuff
In Scala InfoChannel if you want to get the name of the player there are two ways to do this:
1.
The variable Billing.PlayerName will return it.
Ex: playername = Billing.PlayerName;
2.
If using VBScript the following will get the player name
Set WshNetwork = CreateObject(“WScript.Network”)
playername = WshNetwork.ComputerName
Mouse not working with MovieClip
Posted 4 July, 2008 in Other Stuff
Clicking not working in AS3?
If you change your mouse to a movieclip by say using: Mouse.hide(); and then simply make the movieclip’s x and y equal to the mouse x and y (stage.mouseX & stage.MouseY) you will run into trouble if the point mouseX and mouseY are not clear. You will always be clicking on your new “mouse cursor” movieclip.
Make sure the exact x and y are clear, so a new arrow for example would be placed just to the left and just down from the mouseX and mouseY point.
This is in actionscript 3.0. I can’t remember how this works in 2.0.
Smooth MovieClip Key Control in AS3
Posted 3 July, 2008 in Other Stuff
In Flash Actionscript 3.0 it is not as simple as AS2 to create a smooth control of a movieclip’s movement. You may find the key engages, then pauses for half a second, then continues. This is no good for gaming. Also the basic KeyboardEvent.KEY_DOWN event listener will only handle one key at a time, so you can not for example hold down the up, and right arrow keys to move diagonally.
The following is a class called Smooth.as. To use it you need an fla 300×300 pixels and with a spaceship MovieClip called Spaceship (in the linkage call the class Spaceship). You also need to save Smooth.as to the same folder and make Smooth the the stage’s document class under properties.
Or just download the source file: smooth
Use the arrow keys to move the ship.
package { import flash.events.*;
import flash.display.*; public class Smooth extends MovieClip {
// Set vars for key codes. Arrow up is 38 for example
static const upKey = 38;
static const downKey = 40;
static const rightKey = 37;
static const leftKey = 39;
// Set vars for current ship speed and maximum speed
private var speed:Number = 0;
private var maxspeed:Number = 4;
// Set vars to keep track of which keys are pressed. This is a Boolean true or false. True if key is pressed.
private var keyPressedRight:Boolean;
private var keyPressedLeft:Boolean;
private var keyPressedUp:Boolean;
private var keyPressedDown:Boolean;
// Create the spaceship MovieClip from a pre-made Spaceship() MovieClip in flash
var spaceship:MovieClip = new Spaceship();
public function Smooth() {
// Set the game/animation loop
stage.addEventListener(Event.ENTER_FRAME, StageController);
// Set event listeners to track key presses for both up and down
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpListener);
// Add the spaceship to the stage and give it starter settings
addChild(spaceship);
spaceship.x = 150;
spaceship.y = 150;
spaceship.rotation = -90;
}
// This function sets the Boolean vars based on whether the relevant key has been pressed
public function keyDownListener(e:KeyboardEvent):void {
switch (e.keyCode) {
case leftKey:
keyPressedRight=true;
break;
case rightKey:
keyPressedLeft=true;
break;
case upKey:
keyPressedUp=true;
break;
case downKey:
keyPressedDown=true;
break;
} }
// This function sets the Boolean vars based on whether the relevant key has not been pressed
public function keyUpListener(e:KeyboardEvent):void {
switch (e.keyCode) {
case leftKey:
keyPressedRight=false;
break;
case rightKey:
keyPressedLeft=false;
break;
case upKey:
keyPressedUp=false;
break;
case downKey:
keyPressedDown=false;
break;
}
}
// This is the main game/animation loop
public function StageController(e:Event):void {
// This rotates the ship if key is pressed
if(keyPressedLeft && speed != 0){
spaceship.rotation -=4;
}
if(keyPressedRight && speed != 0){
spaceship.rotation +=4;
}
// This increases the ship's speed if the up key is pressed
if(keyPressedUp && speed < maxspeed){
speed +=0.1;
if(speed > maxspeed){speed = maxspeed;}
}
// This decreases the ship's speed if the down key is pressed
if(keyPressedDown && speed > -maxspeed/2){
speed -=0.1;
}
// This decreases the ship's speed if neither up nor down key are pressed.
if(!keyPressedDown && !keyPressedUp){
if(speed < 0){
speed +=0.1;
}
if(speed > 0){
speed -=0.1;
}
}
// This moves the ship forward based on ship's angle
var scangle:Number = spaceship.rotation * Math.PI / 180; // Ship's angle in radians
spaceship.x += speed*Math.cos(scangle); // Move the ship on the X axis
spaceship.y += speed*Math.sin(scangle); // Move the ship on the y axis
// This makes sure the ship never leaves the viewable stage
if(spaceship.x < 0){spaceship.x = 300;}
if(spaceship.x > 300){spaceship.x = 0;}
if(spaceship.y < 0){spaceship.y = 300;}
if(spaceship.y > 300){spaceship.y = 0;}
}
}
}
AS3 Tips
AS3 Tutorial
Move ship based on angle AS3
Posted 30 June, 2008 in Other Stuff
Imagine you are writing a game and you have a space ship that needs to move towards a target in a smooth fasion. It needs to turn towards the target, all the while moving forwards. The following is a function/method in a class used to control the movement of the ships in the game. The ships all have home worlds that the ships will head for.
public function ShipControler(e:Event):void {
var ss = e.target; // Set ss to the event target. ss is nicer to use than e.target
// Get target x,y of target
var tx:Number = world[ss.targ].x; // ss.targ is a number. It is the ID of the world the ship is heading for
var ty:Number = world[ss.targ].y; // ss.targ needs to be defined in the ship's own object
var dist_x:Number = tx - ss.x; // Distance to target on X axis
var dist_y:Number = ty - ss.y; // Distance to target on Y axis
var angle:Number = Math.atan2(dist_y, dist_x); // The angle of target relative to ship in radians
var ta:Number = angle/Math.PI*180; // The angle of target relative to ship in degrees
var range:Number = Math.sqrt(Math.pow(dist_x,2) + Math.pow(dist_y,2)); // Distance to target
// Calculate closest angle to turn ship
// There might well be a cleverer way to do this, but my brain started melting so I did this.
// It works out if the ship needs to turn left or right depending on which every way has the
// smallest angle. Imagine moving the ship to face angle 0 (facing right) then moving
// the target so that it still has the same relative position. If the target's angle is
// less that 0 the ship needs to turn left. If the target's angle is more than 0 the
// ship needs to turn right.
if (ss.rotation < 0){
ta = ta + ss.rotation * -1;
if(ta > 180){ta = ta - 360;}
}else{
ta = ta - ss.rotation;
if(ta < -180){ta = ta + 360;}
}
var rot:Number = new Number; // How fast and which direction the ship turns
if(ta > 0 ){
rot = 5;
}else{
rot = -5;
}
if(range < 30){rot = rot * -1;} // Turn ship away if too close to target
ss.rotation += rot; // Turn the ship
// Move ship forward based on ship's angle
var ssangle:Number = ss.rotation * Math.PI / 180; // Ship's angle in radians
var speed:Number = 2; // Set the speed of the ship
ss.x = ss.x + speed*Math.cos(ssangle); // Move the ship on the X axis
ss.y = ss.y + speed*Math.sin(ssangle); // Move the ship on the y axis
}




