ID:264150
 
Code:
turf/Click()
if(usr.detonating)
if(usr.stamina<10) return
usr.stamina-=10;usr.staminaexp+=rand(0,2);usr.StaminaLevelUp();usr.detonating=0
var/obj/Nothing/N=new();N.loc=src;flick('Target.dmi',N)
spawn(10)
flick('Explode.dmi',N)
spawn(5)
del(N)
for(var/mob/M in view(N,1))
damage = round(usr.str*1.5);damage+=rand(1,damage/1.5);damage=round(damage*1.[usr.anger])
view(M)<<"[M] takes [damage] damage from the explosion!"
M.health-=damage;M.Death(usr)


Problem description:

I've looked the code over several times and found nothing wrong with it. It worked fine the last time I tested it which was a few days ago, but now it just displays the following runtime error and I didn't change any of the code.

runtime error: cannot read from list
proc name: Click (/turf/Click)
usr: Wrath (/mob)
src: (91,70,7) (/turf/dirt)
call stack:
(91,70,7) (/turf/dirt): Click( (91,70,7) (/turf/dirt), "mapwindow.map", "icon-x=10;icon-y=14;left=1")

I clicked the turf right next to me as the target of the explosion, but i can't figure out what's wrong. I've tried targeting the turf under me and near other mobs and I get the same error. Can anyone tell me what's wrong?
            spawn(5)
del(N)
for(var/mob/M in view(N,1))

Even though you have a spawn statement there, it's possible N is being deleted before the loop finishes. Instead of calling view(N, 1), you could try view(src, 1) since they'll both always be in the same tile and the turf is never deleted.
In response to Nickr5
That isn't the case since that spawn statement was originally after the loop and it still generated that error. I also have already tried callng view(src,1) instead and that failed as well. This problem is just so stupid and that is why I brought it to the forums after beating myself up over it for two hours. Thank you for trying though. I appreciate it.
In response to Nickr5
Nickr5 wrote:
Even though you have a spawn statement there, it's possible N is being deleted before the loop finishes.

I don't really think so. It would only, possibly, if he had sleep() there.
The problem is this line:
damage=round(damage*1.[usr.anger])


When the brackets are used outside of strings it's usually for list indexes, you can achieve the effect that I believe you're looking for with text2num(). =)

damage=round(damage*text2num("1.[usr.anger]"))


Also, I don't see damage declared anywhere, it's not a turf variable is it? I don't see any reason not to make it local. I also wouldn't recommend compacting lines as you have, the error was easier to spot when I expanded the proc.
In response to YMIHere
I have damage declared globally since it's used so often. Anywho the thing you mentioned worked out. I do recall not testing it after I added the anger statement, I just compiled to see if it got that far. Thank you guys a lot for your help, I appreciate it.
In response to Demon Wrath4
You know that you'll get damage bugs if you define it globally? Even if you reset it. There are multiple instances every second in a PvP game where the damage var will be used so it's a bad idea to use it as a global var. It will work single player but it will be disastrous when hosting it.
In response to Kakashi24142
I never thought about it that way. I haven't done any real testing since I switched it to be global. Thanks for the tip.
In response to Kakashi24142
Not really, no. DM is single-threaded, and only one proc runs at a time. Something like you've described would only happen if you've messed with sleep() and spawn(), as that would let something else run, and delay your code so things can change.
But if you only do something like this:
var/dmg
mob/proc/TakeDamage(amount)
dmg = [...]
src.hp -= dmg

Nothing disastrous will happen. Note the variable is reset every time before it's used so the old value doesn't have any impact.

Of course, it's still better to declare the variable only where it's needed, but you don't need to have false fears. >_>