AnimeSuki.com Forum

AnimeSuki Forum (http://forums.animesuki.com/index.php)
-   Tech Support (http://forums.animesuki.com/forumdisplay.php?f=24)
-   -   Javascript Game Coding (http://forums.animesuki.com/showthread.php?t=122265)

Soliloquy 2013-10-08 07:34

Javascript Game Coding
 
Hi, I'm trying to learn Javascript. Here I'm trying to modify the game coded a few years ago. It's a puzzle game known as Sokoban and in that page, you can select what level you want to try. Basically if you finish a level, the window pops up for a highscore name. I want to make the code go to next level instead so how do I go about doing this?

Spoiler for Original Link:


Spoiler for Source Code:

Auxilism 2013-10-09 23:34

I only have a minor background in C++ so feel free to ignore me.

What have you tried so far? Unless you're telling me that you are completely new to javascript and don't know what are if-else statements, variables, functions, etc then you should learn them first before modifying a game's code.

Let's say you actually typed that source code and for some reason you don't know how to change it to do what you want; at least show us the logic that you used so we can clear any misconceptions that we can see and tell you why that didn't work.

Until you show that you actually tried reading and/or changing some code, I'll only give a hint.
Code:

if (correctlyPlaced == numberOfObjects) { // Player has finished the game
Change the code in this statement since this triggers when the level is won.

Soliloquy 2013-10-11 05:13

Actually I'm not really a complete beginner but not all that good either. So far I do know about basic stuff like Loops, conditional and logical statements however I'm not all so familiar with lot of terms like setAttribute, appendChild. I know I have to put something in the if statement to direct it next level if finished, but don't know.

if (correctlyPlaced !== numberOfObjects) {
loadLevel();
}

I'm not really sure but I made this conditional statement false, so it goes to the original level.
So far I have tried to delete the function that sets high score window to appear but it was still appearing.

Spoiler for The function I deleted.:

Auxilism 2013-10-11 07:19

Quote:

Originally Posted by Soliloquy (Post 4866077)
if (correctlyPlaced !== numberOfObjects) {
loadLevel();
}

I'm not really sure but I made this conditional statement false, so it goes to the original level.

I'm not following. != means not equal and == means equal to. Which are you trying to check for? Did you mean when correctlyPlaced==numberOfObjects the level that was selected originally is loaded again?

Quote:

Originally Posted by Soliloquy (Post 4866077)
So far I have tried to delete the function that sets high score window to appear but it was still appearing.

Spoiler for The function I deleted.:

Then the if statement is empty as such?
Code:

if (correctlyPlaced == numberOfObjects) { // Player has finished the game
}

If so, nothing should be happening when the level is 'finished'.

Try replacing the if statement entirely with this:
Code:

if (correctlyPlaced == numberOfObjects) {
          alert("I am an alert box!");
}

Does an alert box come out? If not, maybe the way you're running it is not loading your code (using the default one instead) or there is much more code in the background. I don't know how to run javascript so I can't help you there.

Assuming the alert code works, this is my logic for loading the next level instantly.
Code:

if (correctlyPlaced == numberOfObjects) {
          document.forms[0].newLevel.selectedIndex++;
          if (document.forms[0].newLevel.selectedIndex >= maxNumOfLevel){ //where maxNumOfLevel is a variable that keeps track of the total number of levels you have
                  document.forms[0].newLevel.selectedIndex = maxNumOfLevel-1; //since array index starts from 0
          }
          loadLevel();
}

The code above should load the next one after the one in progress is completed unless it is the last level. If it is the last level, it will load the last level again. If you look at the first line of the loadLevel code,
Code:

var currentLevel = document.forms[0].newLevel.selectedIndex;
currentLevel is then used to retrieve the strings to load the level so the whole function is dependant on document.forms[0].newLevel.selectedIndex. (Skip the rest of this paragraph if javascript's classes don't have public, protected and private types.) Since currentLevel can directly equate to document.forms[0].newLevel.selectedIndex, it should be a public variable so we can change it to whatever we want as long as it is in scope.


All times are GMT -5. The time now is 18:08.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2015, vBulletin Solutions, Inc.