• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

HELP With Fishing NPC (HeavenMS)

Newbie Spellweaver
Joined
Jul 31, 2013
Messages
30
Reaction score
21
Looks like the help section doesn't get much attention... Anyways, your curly braces are a little messy, are you using an IDE? You should practice formatting your code or at least let your editor do it for you. VSCode, Atom, IntelliJ, Netbeans, Eclipse all have built-in code formatting. Notepad++ can do it too although you need a plugin.

In my opinion, you should always put your curly braces, even in one-line statements. When you're confident you'll never run into this problem again is when you can omit the curly brace.

I believe you need an extra curly brace after line 92, then you have 3 extra curly braces at the end of your code that you can delete. You also need to parseInt your fee variable since it's a String and what you need is a number.

XHV7xVC - HELP With Fishing NPC (HeavenMS) - RaGEZONE Forums



You should also stay consistent with your chain of if-else statements. In status 2 you do an if-else but it should be an if-else if.

Code:
} else if (status == 2) {
    if (selection == 1) {
        //...
    } else {
        if (selection == 2) {
        } else if (selection == 20) {
        } //...
    }
} else if (status == 3) {

There's no reason to break the chain then continue it in the else block unless you have extra processing or variables to make. Instead, keep everything aligned to keep your flow of code and maintain readability.

Code:
} else if (status == 2) {
    if (selection == 1) {
        //...
    } else if (selection == 2) {
    } else if (selection == 20) {
    } //...
} else if (status == 3) {

As for making your script more efficient, it really depends on the purpose of your Npc. What I like to do is make my scripts automatically expandable by using arrays (a little bit advanced depending on the size and variety of features in your Npc).

If you make an AIO shop with 62 different shops are you going to manually code each shop in a chain of 62 if-else if statements? No, you shouldn't. Use a loop to print each section then use the selection variable to index the array.
 

Attachments

You must be registered for see attachments list
Upvote 0
Junior Spellweaver
Joined
Jan 4, 2010
Messages
123
Reaction score
9
Thank you man, and yes this forum is pretty dead!
I ended up joining a few javascript based discord servers and got the same information from folks there.
It's pretty apparent that I need to refresh myself on the basics of formatting and my indentations to prevent little mistakes like this.
It's just force of habit i suppose.. I managed to get the script some what working, just need to go back over it and check a few of the brackets as I ended up having to retype the code.
I did hear from the discord servers that Prettier is a good tool as well as ESLint but I am not too familiar with the tools.
I do code in NP++ and just test the NPC I am working as I go, maybe that's where I start getting confused not too sure.

Again thanks for the information man!!
-Add me on discord if you'd like @ Ɩıɱცʂ #2516
 
Upvote 0
Back
Top