Noob here self-teaching with a question that seems like it should be obvious.
I'm making a game in which a character (a movable image) touches one of many images on the screen, and when a key is pressed a function specific to the image being touched runs.
I've created an object with several properties defining placement of the image etc, with the last parameter being a function (a function as an object property is called a method, right?). Here's the object:
var obj1 = {xleft:0, xright:800, ytop:0, ybottom:500, action:"Test", text:"Whoop whoop", func:alert('Eureka!')};
So when my character is within these parameters (touching the object) and the key is pressed, this function runs:
function action(){
document.getElementById('Text').innerHTML = obj1.text;
obj1.func();
}
When the key is pressed, the text appears as it should, but the function doesn't run (more specifically, in this incarnation the function runs when the screen loads, which isn't what I want). I've tried several other possibilities but nothing has worked.
Can anyone help?