JavaScript!

Probably my most recent achievement in computer science has to be website JavaScript, what is JavaScript you ask?

Well JavaScript is just on of many script types such as boo, C#, etc, a script is just a bunch of plain text, but the special thing about scripts is that computers can read them. JavaScript is like stage scripting in concept, but not in execution, for example:

lets say you want a box to move from right to left:
Stage Scripting version:
….. then the box moves from right to left …..

JavaScript version (not exactly but similar)
var moveBox = true;
var xPosition = 0;

function Update ()
{
box.position.x = xPosition;
}

function Awake ()
{
xPosition = mathf.lerp (0, 100, 0.6);
}

I can read it, can you? In fact I used a js VERY similar to that one to make a box x position always equal the x position of a ball, I used a math.lerp function to make it go smoothly, so that if the ball is moving fast enough the block can not keep up allowing the ball to pass:

}

var xAxis = false;
var speed = 1.0;
var Marble : GameObject;
var startx = 0.0;
var endx = 0.0;
var starty = 0.0;
var endy = 0.0;
var startz = 0.0;
var endz = 0.0;
var fspeed = 0.0;
function Update ()
{
Invoke (”positionUpdate”,0);
}

function positionUpdate ()
{
fspeed = speed / 100;
startx = transform.position.x;
endx = Marble.transform.position.x;
starty = transform.position.y;
endy = Marble.transform.position.y;
transform.position.y = Mathf.Lerp(starty, endy, 1);
if (xAxis)
{
transform.position.x = Mathf.Lerp(startx, endx, fspeed);
}

}

The key difference though is that all of those are Gaming JS examles not website JS examples

In fact JS was the first programming language that I ever learned (perhaps html came first), I immediately took off upon figuring it out. However only recently I have learned website JS (I will knock off the bolding now).

Website JS was surprisingly different.. yet the same! here is one of the scripts that I made:

var timeleft = 59;
var count = true;
timeout()
mes()
function timeout()
{
if (count == true)
{
setTimeout(”document.getElementById(’M').innerHTML=’you will automatically be redirected in ‘ + timeleft + ‘ seconds’”,1000);
setTimeout(”timeleft = timeleft – 1″,1000);
setTimeout(”timeout()”,1000);
if (timeleft == 0)
{
window.location=’http://menar.plexpedia.com’;
}
}
if (count == false)
{
ab()
}
if (timeleft == 10 – 1)
{
countz()
document.getElementById(’mes’).innerHTML=”10 seconds to go!”;
}

if (timeleft == 5 – 1)
{
document.getElementById(’mes’).innerHTML=”Alert 5 seconds left”;
}

if (timeleft == 30 – 1)
{
document.getElementById(’mes’).innerHTML=”30 seconds!”;
}

}

function countz()
{
var r=confirm(”you have 10 seconds left” + ‘\n’ + “press cancel to abort redirect” + ‘\n’ + “press ok to continue”);
count = r;
}
function ab()
{
setTimeout(”document.getElementById(’M').innerHTML=””,1000);
setTimeout(”document.getElementById(’mes’).innerHTML=’Aborted!’”,1000);
}
I have to say I simply LOVE doing JS, I have a passion for it, just the fun of making a program and seeing it work is enough to satisfy me… But there is more!

Not only is JS fun, but it is useful, you can make popups, bookmarks, program videogames etc, it overall is a POWERFUL thing that can be used to do MANY things, many…. (says in ninja voice) Interactive things! Here is my FIRST ever website script, and this time I will not spam your computer with my craziness, I will just give it to you in action:
Ok for some reason it is not working, just click here instead.

Anywho, hopefully I have successfully expressed my opinions on JavaScript.

~Geo Larsnick

3 Responses to “ JavaScript! ”

  1. Aubrey Says:

    …And the most fun of all is when the distinction between “game” javascript and “website” JavaScript begins to disappear!

    I would highly recommend you try out the MooTools library – it makes advanced techniques like ajax a piece of cake, handles browser compatibility without you even having to worry about it, and includes tons of super fancy effects like Robert Penner easing transitions right out of the box:
    http://mootools.net/

    Happy Coding!

  2. admin Says:

    Thank you Aubrey! I must say I was surprised (pleasantly) to see that you had read my blog! Thank you for the link to MooTools, I tend to find your advice very helpful!

  3. bunny Says:

    Awesome post!

    ______________
    Thank you!

    -Geo

Leave a Reply