Jump to content

  • Log In with Google      Sign In   
  • Create Account


Javascript Won't Run with Tutorial GitHub Code

  • You cannot reply to this topic
4 replies to this topic

#1 Frolicks   Members   -  Reputation: 128

Like
0Likes
Like

Posted 12 July 2014 - 12:23 PM

So as you all know, I am an absolute beginner to all things Javascript and HTML.

I do have some prior knowledge from CodeAcademy courses and general youtube videos, but it's not anything to go by in terms of game development.

 

I've been following this tutorial http://www.lostdecadegames.com/how-to-make-a-simple-html5-canvas-game/ (thanks to Avalander for the link)

on the topic of making a simple canvas game. 

 

My problem is this. It doesn't run. After failing to run on my own hand-written code, I opted to copy/pasting the GitHub code instead. Didn't work either.

 

Maybe it's an issue with the way I connect the .png's to the code? Possibly. However, I've tried: 

 

Downloading the images and putting it in the same folder, naming everything correctly

 

Including a direct internet link in the HeroImage.src = "http://xxxxxx.png

 

Putting the entire .js code into the html file as <script> </script>. Although the images didn't show up, I was able to see the document.write ("This code ran!") I included and the height of the canvas by highlighting it with the cursor. 

 

Any thoughts on what the problem could be? My Javascript education would seriously take a hit if I keep doubting my own browser/computer.

 

 

Might be worth mentioning that I've had tutorials fail me in the past. 

 

This would work: https://www.youtube.com/watch?v=8YBKAsJF9Jg

While this would not: https://www.youtube.com/watch?v=jZh4BMfXv6o

 

Thanks for reading, gaiz. 


Edited by Frolicks, 12 July 2014 - 03:41 PM.


Sponsor:

#2 Avalander   Members   -  Reputation: 752

Like
6Likes
Like

Posted 12 July 2014 - 01:03 PM

I downloaded the github project and it runs in Firefox without problem. There are a couple of things I think can be happening.

  1. You have a browser that doesn't support html5. Without support to html5, your browser won't run anything with canvas. All major browsers support html5 nowadays, just make sure you don't have an outdated version and you are not using internet explorer.
  2. You haven't created an html file that includes your JavaScript file. The tutorial doesn't explain this and you may not be aware. If you haven't done it, you can copy the file index.html from the github repository (just make sure that the '<script src='game.js' />' points to the correct path). Otherwise, maybe you can show us your html file, perhaps the issue is there.

Another thing, are you using a debugger? Firefox has the firebug addon, and I know Chrome ships with its developer tools.

 

Without more information is hard to diagnose your problem. If your browser supports html5 and you have an html file that includes properly your JavaScript source, test with some debugger tool if your code is throwing some kind of error message.

 

And last, you've tagged your post with the 'Java' tag. Just for your information, Java and JavaScript are two unrelated languages. In fact, mistaking Java for JavaScript is like mistaking 'Ham' for 'Hamster'.

 

Hope I've been helpful.


Edited by Avalander, 12 July 2014 - 01:05 PM.


#3 TheChubu   Crossbones+   -  Reputation: 3952

Like
6Likes
Like

Posted 12 July 2014 - 01:10 PM

Just one thing: Java != JavaScript


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#4 Lactose!   GDNet+   -  Reputation: 3064

Like
1Likes
Like

Posted 12 July 2014 - 01:49 PM


In fact, mistaking Java for JavaScript is like mistaking 'Ham' for 'Hamster'.



#5 Frolicks   Members   -  Reputation: 128

Like
1Likes
Like

Posted 15 July 2014 - 11:54 PM

I downloaded the github project and it runs in Firefox without problem. 

 

Thanks to you, I realized that I could download Github projects.

 

My problem was, I didn't understand how to properly write the "src" to connect to my images. Downloading the file and seeing all the folders helped me realize that, thanks.







PARTNERS