I will post a more updated version which is refactored.If you'd want to use this, sure, nice. Just a few things I noticed.
- Statusses are usually used to keep things chronological. In this script It's 0, then -1, then forced to 1. I'm not sure I understand.
- Why is another NPC suddenly used to deliver the last message?
- Why do you initialize the array thrice during the usage of this npc? (Every time action is called, you initialize it, while you can initialize it during the start method and use it later on)
1. Why not start in start (seems pretty obvious to me)
2. Like luxray said, why tell status is 0, then instantly change it to -1
3. Why not make the array a global variable?
4. Why not increase status when mode === 1 instead of force setting it
5. This is javascript, not java, use === and == accordingly to keep from shoothing youreslf in the foot.
6. Why save currentKey in a variable, its only used once, one line later.
7. Luxray mentioned that you initialize the array 3 times, but you also loop through all those items and place them in a variable which you only use once.
8. What the hell is cm.sendNextNPC(message, 3, 9209001); im not sure i wanna know...
9. What is the use of status 3 in your npc?
Well the NPC works... I guess? I didn't test it, but from the looks of it you can still improve a LOT.
I liked how the array is structured (besides the fact that its made multiple times)
Your npc will never actually change the song, nor is it logical to go from status -1 to status 1.That's.. an awfully ugly code. I hope you formatted it properly on your end.
For readability:You must be registered to see links
Are you aware that the status is not special and that we have this statement on the beginning, which will send the menu option to the client?Your npc will never actually change the song, nor is it logical to go from status -1 to status 1.
Are you aware that the status is not special and that we have this statement on the beginning, which will send the menu option to the client?
if (status === -1) { cm.sendSimple(text); status = 1; return;}
As you can see the script is returned, but it's not disposed, so it will do the evaluation on you the next npc talk.
Anyways, I'm implementing the same away GMS does, I will post the implementation of this script in the new way, as soon as I implement the basic npc scripting api.
If you don't ever touched the leaked files from BMS, here is how the npc chat looks like there, which is the correct way:
x = self.askYesNo("Test");
if(x == 1)
foo()
else
foobar()
Lol.
I liked how the array is structured (besides the fact that its made multiple times)
Yep, that script is missing an return statement. Didn't notice that, but it will play the song anyways, since the changeMusic method is inside the if branch that checks if status = 3.I meant the continuity of the script. Going from -1 to 1 isn't logical and might confuse users who are new to NPC Scripting.
Also, I didn't mean that the NPC would never start, but that the NPC is disposed before ever reaching status 3.