Creating A Game - Object Changes By Itself - Shared Memory ?
Nov 6, 2011
I am creating a game in JavaScript!
It is going to be a clone of the game ChuChu Rocket! that I used to play on the Dreamcast.
The game is set up so that the levels sit inside a nested array of objects, like your typical JSON string. So that within levels[] there are objects with level names, an array of moveable items, an array of arrows you can place, etc.
I have set it up so that when the level is loaded in to the DOM, it also duplicates a part of the object, the part responsible for the positioning of the moveable items on screen so that when they are animated, and if there is a fail scenario (cat eats mouse, cat gets to rocket before mouse) you should be able to reset and it remembers your coordinates.
From what I have learned in my years of studying and using JavaScript, the following should always hold true: a=1; b=a; b++; // b would become 2, a would stay as 1 (they are separate variables)
I seem to have found an exception to this rule.
When creating a level, I duplicate the part of my object called o.chuchu and I call it o.chuchuMoving
If I make a change to anything in o.chuchuMoving, it also changes o.chuchu.
o.chuchu and o.chuchuMoving are arrays within the object. Formatted like this: [0,0,1],[1,0,1],[2,0,1],[3,0,1] ... etc
If I tell my object the following: o.chuchuMoving[0][0]=1... then o.chuchu[0][0] also becomes 1.
Please check the code at [url] when you get a moment
View 6 Replies
ADVERTISEMENT
Apr 8, 2011
I'm currently trying to code a jQuery base memory game for school. I however got one problem right now. The cards are supposed to change picture on mouseover and change back on mouse leave. However, if you click on a picture, that card isn't supposed to turn back right away. I thought I could fix this with classes, but it doesn't work. Here's a part of the code:
$(document).ready(function() {
$("img.spelkort").mouseover(function() {
$(this).attr("src","spelkort/kortbaksidahover.jpg");
$(this).addClass("hover");
});
$("img.spelkort.hover").mouseleave(function() {
$(this).attr("src","spelkort/kortbaksida.jpg");
$(this).removeClass(".hover");
});
$("img.spelkort").click(function() {
$(this).attr("src","spelkort/kort1.jpg");
$(this).removeClass(".hover");
});});
View 2 Replies
View Related
Dec 12, 2010
Has anyone noticed this behavior before? This really threw me off... I would have expected prototyped arrays to be private to each class instance rather than shared between all class instances.
HTML Code:
<html>
<head>
<script type="text/javascript">
[Code]....
View 3 Replies
View Related
Apr 4, 2010
what im trying to do is make a javascript pop-up message in real time alerting members who are online at that time to a game submitted i help run a fifa10 online league site and we are venturing into the 2v2 part of the site.
now when a player goes to the 2v2 page they are presented with a submit button to submit a 2v2 game to the system. then this already shows up on the pagebut what we are after is a little pop up box which after the game button is pressed to submit the game the pop-up shows to the whole site that a 2v2 game has been submitted for playing.
we want this so you dont have to sit on the 2v2 page to wait for a submitted game.
View 2 Replies
View Related
Mar 16, 2010
I am creating a frogger game. When the frog image collides with a vehicle image, I wish for the frogs position to be reset back to the start. Here is my code which is currently not working:
Code:
// Frog Collisions: (CURRENTLY NOT WORKING)
var cvehicle=new Array(0,
document.getElementById("car1"),document.getElementById("lorry1"),document.getElementById("car4"),document.getElementById("lorry2"),document.getElementById("car2"),document.getElementById("car3"),
document.getElementById("lorry3"),document.getElementById("car5"),document.getElementById("car6"),document.getElementById("car7"),document.getElementById("car9"),document.getElementById("car10"),
[Code] .....
View 3 Replies
View Related
Jul 23, 2005
I am a little confused how the memory for objects is allocated in
JavaScript. David Flanagan, in "javascript: The Definitive Guide,"
states that each property of a class takes up memory space when
instantiated. So space is created for aMethod three times in this
example: Code:
View 9 Replies
View Related
Oct 19, 2010
I am working on a simple javascript craps game program. I need some advice since it won't display who the winner is, keep tally of who wins/loses, and the number of total games played. After using the error console there's an error with document.forms [0].thrower.value not being defined.
<html>
<head>
<title> JavaScript Craps Game</title>[code]....
View 13 Replies
View Related
Mar 26, 2009
First the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function TextScroll(scrollname, div_name, up_name, down_name, top_name){
[Code]...
When I use mouse wheel in Firefox to scroll contents of the DIV, memory usage in Firefox goes through the roof. Code above is a fully working page, if anyone would like to see what's up, just load it up, and start moving your mouse wheel in the area with text. You don't actually have to scroll the text, just moving the wheel back and forth in that DIV will do. Memory usage will start going up quite fast, and after you stop moving the wheel, it will finally come down a bit after a short while. I've highlighted in red the line where mousewheel event is registered for Firefox. I'm not sure if it's really a problem, but since Opera and IE don't have any strange memory usage, and Firefox does, maybe I did something wrong. In everyday use it shouldn't matter [don't expect to have kilometers of content to scroll], but anyway, it is a bit unsettling.
View 2 Replies
View Related
Oct 7, 2011
Here's an example of the returned json which I'm trying to parse back into a js object:
{"name":"John"}
After setting that string to a js variable called modelJson, here's my code trying to convert it:
var dictModelList = $.parseJSON(modelJson);
then I test to see if it's null or not and it definitely shows null when this alert pops:
alert("dictYearList: " + dictModelList);
View 1 Replies
View Related
Jul 1, 2009
I have a Flash movie on a web page and I want to send parameters to it with JavaScript to have it go to a selected frame. The AS3 code receives its information via an ExternalInterface API. The following code parses the URL argument (?page=x) and I want to send the value (x) to Flash. Unfortunately, when creating the objMovie variable, it is always undefined, therefore getFlashMovie is undefined and Flash never receives the callback. Thinking that it was because the flash movie is not loaded yet, I created a button to call callToActionscript, and when I click the button, I get the same error.
(getFlashMovie("myFlashMovie") is undefined)
Also,
if (params)
always returns true, whether there are parameters or not. I don't understand that, either.
The code follows:
<script >
$(document).ready(function() {
var params=getQueryParameters();
if(params) {
callToActionscript(params[0]);
}});
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
var objMovie = (isIE) ? window[movieName] : document[movieName];
alert(objMovie); //Always return undefined
return objMovie;
} function callToActionscript(page) {
var myMovie=getFlashMovie("myFlashMovie").sentToActionscript(page);
} function getQueryParameters() {
var query = window.location.href.split('?')[1];
//query won't be set if ? isn't in the URL
if(!query) {
return { };
} else{
var param = query.split('=');
} return param[1];
}
</script>
View 1 Replies
View Related
Dec 5, 2011
I am doing javascript from a book called "Prentice Hall(which sounds very masonic) : Javascript by example".
my question is this. I am doing an practice dealing with "defining methods for an object" now i used this code verbatim
[Code]...
I did this code in the book exactly. I am just trying to warp my head around this and want to understand how is this an error when it is just the crating a new property.
View 1 Replies
View Related
Jun 29, 2010
how to search through siblings for shared attributes I have a a long list of links and I suppose Im going to apply a number of classes to each one [describing a number of attributes for each] and I want to do a conditional search probably in javascript/jquery so that when i hover over one of the links I highlight its relatives - those that have the same attributes.
What Im having trouble wrapping my head around is the idea of classes to ID these custom attributes. The attributes are coming from a database converted to XML. In my Javascript I essentially want to say that
for each link should the user mouseover or mouseclick for each of its sibling links if its sibling link share its attributes style or highlight these compliant siblings a certain way
how do I do the 'if statement' without spelling out every possible attribute entry? I know in plain OOP Java how I could test for this but in that scenario I have access to these entries as fields in an object's instantiation.
View 5 Replies
View Related
Apr 30, 2009
A remotely shared white board, using regular JavaScript,jQuery, the canvas element and PHP.I (or someone else) can get this thing working.The new 8:25 a.m. (US CST) version in http:[url].... should work -- though I still have not seen it work, perhaps.
View 2 Replies
View Related
Jul 9, 2010
To have multiple linked sliders that all share a maximum value, for example, I would have 10 sliders, each set to 50, with a pool of 10 additional points to spend. If I assign all 10 points to 1 slider, the other 9 are locked out, or I could spend 1 point on each slider.
View 1 Replies
View Related
Apr 13, 2011
$(document).ready(function() {
The SELECTor shows up in the document but it's not MULTIPLE, no ALT text, no CLICK event handler.
View 3 Replies
View Related
Apr 4, 2010
So, I read about the new method of passing an object map containing element properties when creating a new jQuery object (as discussed at the bottom of this article). The article says that it supports ALL events, but only gives examples of simple events that require no parameters. I'm trying to implement a live event using the following and can't get it to work:
var link = $('<a />', {
text: config.appendTextMore,
href: "#",
[code]....
View 1 Replies
View Related
Nov 14, 2011
Create a game where 6 dice are 'rolled' by you and 6 dice are 'rolled' by the player (simulated by the click of a button). Add up both rolls. The goal is to come as close to a score of 100 as possible, without passing 100. Have a STOP button to signify when you are ready to stop rolling and compute the winner. The highest score under 100 wins. Display the number of times you win and the number of times the computer wins using javascript. So far I have the following code, however, my dice images are not working(they display as little broken symbols when I run the game). The game itself is running just fine but I can't figure out how to get the game to do the "Add up both rolls" step and beyond.
View 1 Replies
View Related
Nov 2, 2011
I am creating a job ticket object that will interact with a database. It has to update the database on the fly via AJAX. Within the job ticket object, I have instances of a Component Object. Within the Component Object, I have an instance of an Editor Object. One of the methods of the Editor object is a function to edit some text and when it's submitted, it will update the database. All of that is working fine. My problem is that I need to refresh the screen with the new contents of the database. I have a method in the Component Object that refreshes the screen, but how do I call it from within the Editor Object? I believe it has to be called there because the editor object has a handler for the form submission and the AJAX function. So I'll have to reference a callback function once the AJAX request is handled, but I don't know how to call it.
I know that sounds kind of convoluted, so hopefully, this very simplified code will paint a better picture of what I'm trying to do:
Code:
Now I want to call refreshScreen, but I don't know how:
View 8 Replies
View Related
Sep 22, 2007
My site has a widget that runs by calling an external script on a server outside my control. Normally this runs within a div as the page loads and the widget is displayed within the div.
What I am trying to do is call the script AFTER the page loads rather than while it loads. To do this, I am adding the script to the DOM (in the div I want, not to the head) on window.onload. An alert shows that the script is being created in the div.
The problem is that the script does not appear to fire in IE6 and IE7. In Firefox it runs, but rather than adding the widget to the div, it creates a new page (everything else on the page is lost).
I have made a test page to show the problem, as well as another page showing how the widget normally loads when the called while the page is loading. Code:
View 1 Replies
View Related
Dec 23, 2010
is there any alternatives? My hosting is a Shared hosting so I guess somehow its limited...
View 4 Replies
View Related
Jan 4, 2010
My client will upload some pdf files in my php page.
I want to find a pdf file is normal file or shared review file. If it is shared review file then only i can allow to upload that file.
How can i find a pdf file is normal file or shared review file?
View 3 Replies
View Related
Jan 27, 2007
I need help with this code. its a counter.
var count= 0
function onm() {
atextbox.value=ffee
count++
setTimeout(onm(),100)
}
And in the body:
<body onload="onm()">
<input type="text" value="0" name="atextbox">
</body>
I get always an error: Out of memory
View 3 Replies
View Related
May 2, 2006
I've been putting together a small pet project. Once it was finished i realised it had a gigantic memory leak inside of it. I tried to read up on the subject, but couldn't find the source of the problem via the articals.
This site is very simple, so I'd think idenifying (and hopefully fixing) the problem would be easy. Here is the relavent portions of JS (followed by links to the full page incase you need to see that): Code:
View 6 Replies
View Related
Mar 26, 2006
I was wondering how good is JavaScript with memory management. I have
an object called MANAGER that has a list of other objects, each one
managing a single DOM nodes, etc. In my implementation of
MANAGER.reset(), I simply recreate my MANAGER.object_list = new
object(); and do a single MANAGER.domnode.innerHTML = '' as apposed to
getting my hands dirty. Is my app leaking memory?
View 4 Replies
View Related
Nov 20, 2006
Internet Explorer leaks memory when I update a div container using
innerHTML, this does not occur in firefox. This would not be a problem
except the webpage is required to be left on for weeks on end without
being restarted. I presume the issue with innerHTML is that Internet
Explorer apparently parses what you give it and then decides on how to
construct the dom elements itself, so never truely creates what you
give it.
I know that the innerHTML is the problem as I have successfully
narrowed down the leak to that line. It only leaks memory when I assign
content to the innerHTML of my containing DIV. Appending a text node,
for example, with the exact same information to the same div does not
leak. Note I have also tried using such existing AJAX packages like
Prototype etc. but to no avail.
I need to do it this way as my XML documents are styled using an XSL
stylesheet and then transformed using transformNode [I will omit
details regarding firefox as there is no problem there]. I have looked
into transformNodeToObject as a way to get a dom object that I
originally assumed could be appended [as a child] to my containing
element. This did not work and gave me compatibility errors.
I suppose I am either looking for someone who has solved this problem,
or who has an acceptable work around. Or someone to say that it cannot
be solved.
View 2 Replies
View Related
Mar 16, 2009
I am using javascript to load and parse a big xml file (around 1 mb) save some values to an array and draw a picture using google Flot. Unfortunately, this causes the browser to crash! Is there a way to clear the memory of the browser?
View 2 Replies
View Related