AnimeSuki Forums

Register Forum Rules FAQ Members List Social Groups Search Today's Posts Mark Forums Read

Go Back   AnimeSuki Forum > AnimeSuki & Technology > Tech Support

Notices

Reply
 
Thread Tools
Old 2013-10-08, 07:34   Link #1
Soliloquy
Perpetually Nonchalant
 
 
Join Date: Mar 2011
Location: Trendy Backwater
Age: 28
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:
__________________
Zettai Ryouiki Addict
Soliloquy is offline   Reply With Quote
Old 2013-10-09, 23:34   Link #2
Auxilism
Yuri guides me
 
 
Join Date: Apr 2012
Location: I do not remember
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.
__________________
Auxilism
オークシリスム
3rd Yuri Division
Characters are from Madoka Magica, Symphogear and Sakura Trick.
Please see the uncompressed version on the right.
Click this for my gif request thread.Max quality version
I take gif requests here.
Please read the opening post (revised as of 22/8/2014).
Auxilism is offline   Reply With Quote
Old 2013-10-11, 05:13   Link #3
Soliloquy
Perpetually Nonchalant
 
 
Join Date: Mar 2011
Location: Trendy Backwater
Age: 28
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.:
__________________
Zettai Ryouiki Addict
Soliloquy is offline   Reply With Quote
Old 2013-10-11, 07:19   Link #4
Auxilism
Yuri guides me
 
 
Join Date: Apr 2012
Location: I do not remember
Quote:
Originally Posted by Soliloquy View Post
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 View Post
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.
__________________
Auxilism
オークシリスム
3rd Yuri Division
Characters are from Madoka Magica, Symphogear and Sakura Trick.
Please see the uncompressed version on the right.
Click this for my gif request thread.Max quality version
I take gif requests here.
Please read the opening post (revised as of 22/8/2014).
Auxilism is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 23:40.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
We use Silk.