ID:2554168
 
(See the best response by FKI.)
Code:
                        if(src.race == "C1P2Story")//This is a death code for one of my story mode bosses
if(usr:ally)//In some parts of the story you will have allies, this part of the code handles if they have the last strike
for(var/mob/characters/Ally in world)
if(Ally == usr.ally)
if(!src.boss&&!src.boss2&&!src.boss3&&!src.bijuuboss)
var/gain = round(src.maxpowerlevel / 337)
if(Ally.maxpowerlevel >= (src.maxpowerlevel / 10))
Ally.maxpowerlevel += gain
Ally.zenni += src.givezenni * 2
Ally.maxpowerlevel = round(Ally.maxpowerlevel)
Ally << "<b>You gained [src.givezenni * 2] zenni and your power increased [gain] from that kill!"
else
Ally << "<b>You gained [src.givezenni * 2] zenni from that kill"
if(src.alignment == "Evil")
Ally.karma += src.karmagive
if(src.alignment == "Good")
Ally.karma -= src.karmagive
Chapter2(Ally) //This send the Ally of the npc, which should be you the player, to the chapter 2 proc

else if(usr:owner)//The game also features pets, this part of the code handles if your pet lands the last strike
for(var/mob/characters/Own in world)
if(Own == usr.owner)
if(!src.boss&&!src.boss2&&!src.boss3&&!src.bijuuboss)
var/gain = round(src.maxpowerlevel / 337)
//var/
if(Own.maxpowerlevel >= (src.maxpowerlevel / 10))
Own.maxpowerlevel += gain
Own.zenni += src.givezenni * 2
Own.maxpowerlevel = round(Own.maxpowerlevel)
Own << "<b>You gained [src.givezenni * 2] zenni and your power increased [gain] from that kill!"
else
Own << "<b>You gained [src.givezenni * 2] zenni from that kill"
if(src.alignment == "Evil")
Own.karma += src.karmagive
if(src.alignment == "Good")
Own.karma -= src.karmagive
Chapter2(Own) //This send the pet owner, which should be you the player, to the chapter 2 proc

else if(!usr:owner&&!usr:ally)//This handles if you deliver the last strike, not much here as it follows a generic kill code
Chapter2(usr) //This sends you the player to the chapter 2 proc



Chapter2(mob/M)
src.loc=locate(1,1,11) //I decided to send the src which should be the boss to a void point until the proc does what it needs, after which the generic kill code will delete it
M.c1p2 = 1 //The player should now have 1 in this variable showing they have completed the chapter
switch(input(M,"Do you wish to continue?" , "Story Mode", text) in list ("Yes","No")) //They should then be given an option to continue
if("Yes")//If so they go on through the story
for (var/mob/S in world)
if(S.ally == M)
del(S)
M.loc=locate(23,92,17)
M.dir = 1
var/mob/U = new /mob/monsters/Ally/SYamcha
U.loc=locate(22,92,17)
U.dir=1
U.ally = M
var/mob/U2 = new /mob/monsters/Ally/STien
U2.loc=locate(24,92,17)
U2.dir=1
U2.ally = M
M << "<b>Defeat 20 saibamen!"
return..()
else if("No")// If not they are returned to the storymode npc
for (var/mob/S in world)
if(S.ally == M)
del(S)
M.loc=locate(100,84,11)
return..()
return..()


Problem description:
The proc runs as it should maybe 3 times after which the switch popup asking you to continue does not popup. I'm figuring that the chapter2 proc is not reporting back to the deathcode to let it know it finished, so it won't open a new one.

The first few times you kill the boss, it ask if you want to continue if you do you move on, if not it takes you to a safe zone basically
After 3 or so times instead it'll move the boss to the void point 1,1,11, but won't continue to the switch input

Here is a video of what happens


https://youtu.be/_pr767ZT5dU
Best response
In some proc (at the top), you are passing usr to Chapter2(), which may not be the object you think it is. Yet, your Chapter2() proc assumes M is always the right object.

Relevant: http://www.byond.com/forum/post/35932
I'm having the rework a lot of the code to try this method but I'll get back after i'm done. I'm learning coding on the side as a fun thing and I appreciate any/all help guys
So following the guide I've changed my code to the following including the entire top code

Code:
mob
proc/Die(mob/A)
if(src.powerlevel <= 0)
if(A)
var/mob/M = A
M.fighting = null
if(src.npp == 0||src.safe == 0)
src.trainpl = (50000)
src.trainpl = round(src.trainpl)
if(src.race == "C1P2Story")//This is a death code for one of my story mode bosses
if(M:ally)//In some parts of the story you will have allies, this part of the code handles if they have the last strike
for(var/mob/characters/Ally in world)
if(Ally == M.ally)
if(!src.boss&&!src.boss2&&!src.boss3&&!src.bijuuboss)
var/gain = round(src.maxpowerlevel / 337)
if(Ally.maxpowerlevel >= (src.maxpowerlevel / 10))
Ally.maxpowerlevel += gain
Ally.zenni += src.givezenni * 2
Ally.maxpowerlevel = round(Ally.maxpowerlevel)
Ally << "<b>You gained [src.givezenni * 2] zenni and your power increased [gain] from that kill!"
else
Ally << "<b>You gained [src.givezenni * 2] zenni from that kill"
if(src.alignment == "Evil")
Ally.karma += src.karmagive
if(src.alignment == "Good")
Ally.karma -= src.karmagive
src.Chapter2(Ally) //This send the Ally of the npc, which should be you the player, to the chapter 2 proc
else if(M:owner)//The game also features pets, this part of the code handles if your pet lands the last strike
for(var/mob/characters/Own in world)
if(Own == M.owner)
if(!src.boss&&!src.boss2&&!src.boss3&&!src.bijuuboss)
var/gain = round(src.maxpowerlevel / 337)
//var/
if(Own.maxpowerlevel >= (src.maxpowerlevel / 10))
Own.maxpowerlevel += gain
Own.zenni += src.givezenni * 2
Own.maxpowerlevel = round(Own.maxpowerlevel)
Own << "<b>You gained [src.givezenni * 2] zenni and your power increased [gain] from that kill!"
else
Own << "<b>You gained [src.givezenni * 2] zenni from that kill"
if(src.alignment == "Evil")
Own.karma += src.karmagive
if(src.alignment == "Good")
Own.karma -= src.karmagive
src.Chapter2(Own) //This send the pet owner, which should be you the player, to the chapter 2 proc

else if(!M:owner&&!M:ally)//This handles if you deliver the last strike, not much here as it follows a generic kill code
src.Chapter2(M) //This sends you the player to the chapter 2 proc


The chapter2 proc is still the same and I'm still getting the same bug, thanks in advance
You are gonna have to do some debugging to figure out what the exact problem is. Start by making sure the mob, M, being passed to Chapter2() in your Die() proc, is the correct mob.

Since you were abusing usr, there could still be lingering design issues that are trickling down to create this problem.

But yeah, debug. A lot of programming is debugging, so consider this a lesson.
Any kind of tools, I could use for that? in the past I learned about using the profile viewer in dreamseeker, which helped me learned about procs that arent ending properly.

But what I hate the most is I fixed this a couples of months ago, but my kid deleted the code, now I'm working off a backup copy before I fixed the bug and I forgot what I did, oh well you live and learn
You don't need any tools. Just add some output messages throughout the code which show you relevant information. It'll give you a good idea of what's going on and where to investigate.

Example:
world << "Die() called on [A]"
Thanks bro, wish me luck
For future reference or if anyone else runs into this problem I was able to fix it by turning the switch(input) to switch(alert) because I only wanted simple yes and no but I believe input wanted me to store those values in a var which I didn't need
Also did some other tidying up of the code at the advice of some fellow members but this is basically it

Code:
        Chapter2(mob/M)
src.loc=locate(1,1,11)
M.c1p2 = 1
if(M)
switch(alert(M, "Do you wish to continue?", "Story Mode","Yes","No"))
if("Yes")
for (var/mob/S in world)
if(S.ally == M)
del(S)
M.loc=locate(23,92,17)
M.dir = 1
var/mob/U = new /mob/monsters/Ally/SYamcha
U.loc=locate(22,92,17)
U.dir=1
U.ally = M
var/mob/U2 = new /mob/monsters/Ally/STien
U2.loc=locate(24,92,17)
U2.dir=1
U2.ally = M
M << "<b>Defeat 20 saibamen!"
return..()
else if("No")
for (var/mob/S in world)
if(S.ally == M)
del(S)
M.loc=locate(100,84,11)
return..()
return..()
input() doesn't require you to store the result in a var. You can use switch(input()) just fine the same way you'd use alert(), but for a yes/no choice alert() is cleaner.

Just as a bit of advice, I'd suggest instead of using hard-coded numbers for your locations, you use tags instead. Find the turf on the map where you want the chapter to begin, and give it a tag. For the allies, either also tag the locations where they'll spawn, or just use get_step() to get a turf relative to your spawn point. The benefit of doing this is that it will free you to easily make changes to your map if you need to, and inserting another Z level at an earlier point won't mess anything up.
Thank you for the information