-->

Posts Tagged ‘programming’

Tutorial Thursday - Global variables in ActionScript 3.0

Thursday, March 27th, 2008

Ohi.
Been a while, ain’t it?
Here’s a small and sweet post about Flash.

A global variable is a variable that you can call throughout your program.
For instance, if you are making a game, and you want to add points to the score and display it in the top right of the screen, you would make a global variable varScore and call it twice.

Now, in ActionScript 2.0, this was fairly straightforward:

//define your variable
_global.varScore = 0;
//call your variable (adding 100 points)
_global.varScore += 100;

Now, apparantly, Adobe figured this was too easy or something, and they gave the programmers a big fat middle finger when it came to global variables.
This, apparantly, because if you have a global variable in your code, and you don’t know where each instance is, and you change it somewhere, you might not know its value.
Even though, you could, like, do

trace(_global.varScore); //this will give you its value!!!

So they decided to not have global variables alltogether.
Yes, that’s right.

Thank the Flying Spaghetti Monster, there is a way to have global variables in ActionScript 3.0.
-make a new ActionScript file, call it GlobalVars.as
-in this file, write the following:

package
  {
  public class GlobalVars
  {
  //stuff!
  }
  }

-at the stuff, write your global variables like so:

public static varScore:Number = 100;

-to call your variable, first import your ActionScript file, like so:

import GlobalVars;

-and then, finally, you have global variables:

GlobalVars.varScore += 100;

This took me three days and 12 forum posts to figure out.

Fuck you Adobe.

-knite

Tutorial Thursday - Hello World in AutoIt

Thursday, October 4th, 2007

Tutorial Thursday.

Yes, ladies and gentlemen, today is going to be the very first Tutorial Thursday.
Which, as you might have guessed, is going to be a recurring event.
Today’s Tutorial Thursday (reiteration lawlz) is going to be about a dinky little programming language called AutoIt.

AutoIt originally started as an automation tool.
It’s very easy to make small programs with it and have them automate certain tasks.
This also gives it… certain… virussy… properties, but it’s like chemistry: you can use it to make bombs or purify water.

But we’re not going to make virussy things today, today we’re going to do that stupid little thing that every programming book ever will tell you to do:

[dramatic pause]

Make a “Hello World!”.

Now, I know a bunch of programmers (just kidding, I don’t know anyone) who absolutely loathe the “Hello World!” tutorial.
I like to refer to them as “twats”.
Saying you don’t like “Hello World!” because EEEEVERYBODY uses it as a tutorial is like saying you don’t like “2 + 2 = 4″.
It’s just cute, fucktards.

Now, before you start download PSPad.
This is not a request, this is a friggin demand.
Why?
Because it’s AWESOME. \m/ >_< \m/
In fact, it’s so awesome, it’s going to deserve its own blog post.

So what do you need for this tutorial:
-Windows (no Mac or Linux for you)
-PSPad (or, like, Notepad or whatever)
-The AutoIt package (available at www.autoitscript.com)
-A keyboard

Now, in theory, this is going to be extremely easy.

Open your respective text editor and type:

MsgBox(64,"Hello World!","Hello World!")
exit

Save the file as “helloworld.au3″.

Now load up AutoIt.exe and select the file and press OK to compile and load it.

YES.
THAT IS IT.
YOU HAVE JUST MADE YOUR FIRST AUTOIT PROGRAM, CONGRATULATE YOURSELF AND EAT A COOKIE.

Now, what this program does:

AutoIt: hey, uhm, Computer, is it okay if I like, make some classes and stuff, and do something with them?
Computer: K.
AutoIt: awesome :-) i would like to make the class class “MsgBox” and it will display a box
Computer: Whatever.
AutoIt: and then it will have a nice information bubble icon next to it, which i define using the flag “64″.
Computer: You’re annoying.
AutoIt: and then i define that the message box will have “Hello World!” in its caption
Computer: Stop talking.
AutoIt: and then the message box will read “Hello World!”
Computer: Goddamn you’re annoying.
AutoIt: and when i’m done doing that, i will close the program
Computer: You’re not sitting next to me at lunch anymore.

The next tutorial will be pretty much the same, except we’ll first make a GUI around the message.

CAN YOU WAIT FOR IT?
I SURE CAN’T!

-knite

Next week: Hello World in a GUI

Hello world!

Thursday, October 4th, 2007

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

echo “Hello World!”;
document.write = “Hello World!”;
MsgBox(64,”Hello World!”,”Hello World!”)
draw_text(0,0, “Hello World!”)

Bonus points to those who can recognize every one of the programming languages I used.

-knite