JavaScript Canvas Lightning Effect

Like always still messing around creating random things using JavaScript and the Canvas element. My most recent side project was implementing some Action Script lightning code posted by Rybar over on the Flixel forums. Here is what I came up with Theres definitely a lot to be desired. Was trying to think of some cool things to do with it. It’s a work in progress until a good idea comes to me.

MySQL Stored Procedures IF NOT EXISTS()

I have been using MSSQL with ASP.NET alot lately, and I really wanted to get some of the benefits of stored procedures into a PHP application I’m writing. I’ve known MySQL has supported them for a while but I guess I was always a bit too lazy to go through old code and convert it. I used the tool HeidiSQL to make the process a bit more painless.

The first stored procedure I attempted to write accepted 3 parameters and based on one of them checks a lookup table, and creates a new value in it if the same value does not already exist. Normally I would use an IF NOT EXISTS clause, which in Microsoft SQL would look like this

@SomeParam varchar(50),
	DECLARE @SomeId int

	IF  NOT EXISTS(SELECT (1) FROM lookup_table WHERE someField = @SomeParam )
			INSERT INTO lookup_table (someField) VALUES(@someParam)
			SELECT @SomeId = @@identity
			SELECT @SomeId = id FROM lookup_table WHERE someField = @SomeParam

	-- Do some other stuff here with the id you just received and other data

The above snippet would take a value, check a table for it, get its id, and if the record doesn’t exist in the database create it and return the id. Then you could continue on and insert that id into another table or what have you.

Accomplishing the same thing with a MySQL stored procedure is a bit different. The code below shows how you would accomplish the same task.

CREATE PROCEDURE 'someProc' (IN 'in_SomeParam' INT)  
	DECLARE SomeId int;
	DECLARE CheckExists int;  
	SET CheckExists = 0;  

	SELECT count(*) INTO CheckExists from lookup_table WHERE someField = in_SomeParam;   

	IF (CheckExists > 0) THEN  
		SELECT id INTO SomeId FROM lookup_table WHERE someField = in_SomeParam;  
		INSERT INTO lookup_table (someField ) VALUES(in_SomeParam);  

	# Do some other stuff here with the id you just received and other data

I’m sure I will find some more differences in things I am used to doing with stored procedures using T-SQL, and when I do I’ll post them here.

Minecraft fun and editing

Recently came across this awesome java game Minecraft basically the whole goal of the game (multiplayer that is) is to create and destroy things. At first I was pretty skeptical, the concept is so simple.. until i found myself spending hours recreating Mario, and others pixel by pixel, and creating a staircase to lava.

Mario brothers in Minecraft

Stairs to Lava

Don’t let the look of the game fool you, anyone no matter the age group can easily become addicted.

What really peaked my interest are some of the game modes people have put together, such as a zombie mode where you are chased by zombies (other players who have been turned) and you need to either hide, or build your way away from them. Theres also a falling lava mode where lava fills the level and you need to build structures as to not get stuck in it.

What I really wanted to do was create some of my own game modes, but it was pretty hard to even figure out where to begin. I eventually settled on Opencraft, which is an opensource Java server for the game. It looks like development has ceased so I have had to implement a few things already. I plan on releasing any changes I make so others can create some interesting game modes as well.