ID:143756
 
Code:
mob
Bump(atom/A)
//Bump stuff. (Running into an enemy) Decides how many monsters in combat and other bump crap thats nessicary.
..()
var/mob/M = A
if(istype(M,/mob/monsters))
src.ran = 0
src.dead = 0
if(istype(A,/mob/monsters/Bosses))
amount = rand(2,4)
else if(src.monstersfighting == 0)
amount=rand(1,src.mobsinbattle)
src.monstersfighting = amount
else
if(!src.monstersfighting)
amount = rand(1,4)
src.monstersfighting = amount
else
amount = src.monstersfighting
monstergroup=list()
src.islocked = 1
M.islocked = 1
src.monstersinbattle = 0
for(var/index=1,index<=amount,index++)
var/mob/monsters/enemy=new M.type //Argh I break here.
src.monstersinbattle += 1
enemy.name = "[enemy.name][number2letter(index)]"
enemy.mhp += rand(-3,3);enemy.hp = enemy.mhp
src.monstergroup+=enemy
src.monstergroupnumber=src.monstergroup
src.monstersugot = src.monstergroup.len
monster_number="[M.name][plural(src,monstergroup)]"
monster_number2="[plural(src,monstergroup)]"
src.checkbattle = 0
MainBattle(src,M,monstergroup)
if(monstergroup.len == 0)del(A)


Problem description:
I haven't actually been working on my code in a while, but I know that this code was working fine until just now when I tried to test a new part of my battle system.

Apparently it gets to the first line of the for loop and just stops working. Period. As I said above, this code was working fine until now, and the last time I worked on it was about Beta 7 or 8, and I'm thinking maybe something that was changed is causing problems? I don't know but I have no idea why there's a problem all of a sudden.
You ought to be using Bumped(). You should also typecast after you check for atom seeing as how you aren't using it anywhere else. I don't see any real problem, though. Try posting your new code.
In response to CaptFalcon33035
I'm sorry, I might sound like an idiot here, but I've never heard the term 'typecast', so if you don't mind, can you please explain? I've been out of it for a while and when I was coding big time no one ever said to typecast, so I have no clue what you mean.

Sorry if I sound like a freak nub. =/
In response to Polantaris
Very interesting article on it, actually. It's only a billion pages within BYONDScape. :O

http://www.byondscape.com/ascape.dmb/YMIHere.2005-0322/
In response to CaptFalcon33035
I don't see what you mean for me to typecast after I check? You mean make M a mob/monsters instead of just a mob?

The thing is, and this is also the part that confuses me, is that this code hasn't been changed at all in any way in months, yet it was working fine a few weeks ago and now it doesn't.

If that's what you mean for me to typecast, I'll change it but I don't think it will have any effect.

Also, about the Bumped, if I change the Bump to Bumped and made the Bumped procedure the way I remember is correct, it makes matters worse. It ends up making it not work at all, instead of freezing without a runtime error. I'll post accordingly.

mob
Bump(atom/O)
..()
if(ismob(O))
O:Bumped(O)

mob
proc/Bumped(atom/A)
//Bump stuff. (Running into an enemy) Decides how many monsters in combat and other bump crap thats nessicary.
var/mob/s = A
if(istype(s,/mob/monsters))
var/mob/monsters/M = A
src.ran = 0
src.dead = 0
if(istype(A,/mob/monsters/Bosses))
amount = rand(2,4)
else if(src.monstersfighting == 0)
amount=rand(1,src.mobsinbattle)
src.monstersfighting = amount
else
if(!src.monstersfighting)
amount = rand(1,4)
src.monstersfighting = amount
else
amount = src.monstersfighting
monstergroup=list()
src.islocked = 1
M.islocked = 1
src.monstersinbattle = 0
for(var/index=1,index<=amount,index++)
world << M.type
var/mob/monsters/enemy=new M.type
src.monstersinbattle += 1
enemy.name = "[enemy.name][number2letter(index)]"
enemy.mhp += rand(-3,3);enemy.hp = enemy.mhp
src.monstergroup+=enemy
src.monstergroupnumber=src.monstergroup
src.monstersugot = src.monstergroup.len
monster_number="[M.name][plural(src,monstergroup)]"
monster_number2="[plural(src,monstergroup)]"
src.checkbattle = 0
MainBattle(src,M,monstergroup)
if(monstergroup.len == 0)del(A)

I get world<<M.type as /mob/monsters/Valley/WeakSlime (Which it should be), but it never sets my islocked for some reason anymore, and it still breaks at the for loop at the same spot.
In response to Polantaris
It's actually:
atom/proc
Bumped(O)
// O just Bump()ed into src.
// prototype Bumped() proc for all atoms

atom/movable
Bump(atom/A)
if(istype(A)) A.Bumped(src) // tell A that src bumped into it
..()


Although I might call spawn() before that A.Bumped(src) call. This procedure is straight from sd_procs by Shadowdarke. In Bumped, O is the mover and src is the atom that was Bumped into.
In response to CaptFalcon33035
Ah my bad, I'll change that and see if it helps any.

atom/proc
Bumped(O)
// O just Bump()ed into src.
// prototype Bumped() proc for all atoms

atom/movable
Bump(atom/A)
if(istype(A)) src.Bumped(A) // tell A that src bumped into it
..()

mob
Bumped(atom/A)
//Bump stuff. (Running into an enemy) Decides how many monsters in combat and other bump crap thats nessicary.
var/mob/s = A
if(istype(s,/mob/monsters))
world << "herE"
var/mob/monsters/M = A
src.ran = 0
src.dead = 0
if(istype(A,/mob/monsters/Bosses))
amount = rand(2,4)
else if(src.monstersfighting == 0)
amount=rand(1,src.mobsinbattle)
src.monstersfighting = amount
else
if(!src.monstersfighting)
amount = rand(1,4)
src.monstersfighting = amount
else
amount = src.monstersfighting
monstergroup=list()
src.islocked = 1
M.islocked = 1
src.monstersinbattle = 0
for(var/index=1,index<=amount,index++)
world << M.type
var/mob/monsters/enemy=new M.type
src.monstersinbattle += 1
enemy.name = "[enemy.name][number2letter(index)]"
enemy.mhp += rand(-3,3);enemy.hp = enemy.mhp
src.monstergroup+=enemy
src.monstergroupnumber=src.monstergroup
src.monstersugot = src.monstergroup.len
monster_number="[M.name][plural(src,monstergroup)]"
monster_number2="[plural(src,monstergroup)]"
src.checkbattle = 0
MainBattle(src,M,monstergroup)
if(monstergroup.len == 0)del(A)

I had to switch A.Bumped(src) to src.Bumped(A) because it was sending the monster the proc, and making me the thing that its checking (like in the istype, and to create more of it) and because of that it wasnt getting anywhere. Once I did, I end up with the same problem. It breaks at the same line, and for no reason. There's nothing wrong with that line, and it always worked before now, in fact thats the exact same code I've used since I first started one of my older projects, like a year and a half ago, so there's no excuse why it should have just ceased to work.

I tried several debugs.
I did world << M.type and got /mob/monsters/Valley/WeakSlime, which is what it should be. Then I tried world << A.type (In case there was some freak problem that caused a change or something) and I got the same result, /mob/monsters/Valley/WeakSlime. Then I added if(M.type == A.type), just to be sure, world << "Yes" and got Yes. ALL of this is RIGHT before the line that it breaks. And to make sure it still does break on the same line, I added a line world << "Before" before the line and world << "After" after the line, and never get After but get Before.

The thing is, its not like this line is that complex. I've remade types of things plenty of times before just this way, and yet this one only causes a problem. Or does it? Actually, in this exact project, I have another instance I can test, that doesnt use this code at all. If that still works, I have no idea whats wrong. But if it doesnt, I have no idea what could be wrong, because that code has also worked for at least a month, probably more.

Okay, now I don't know whats wrong. The other code, which should be the one more likely to break, doesn't. It uses a variable list of items that you pick through and create the item off of that list. For example if you want a weak herb it will create a /obj/items/weakherb in your inventory.

AHHA! Perhaps? Could the problem be that I am not giving the new Slimes a location? Maybe it is confused when it tries to create it at 0,0,0? Its a possibility.
In response to Polantaris
Bump >_<
In response to Polantaris
Polantaris wrote:
Bump >_<

Heh :P

Try this. Instead of using 'new M.type', set up a variable with the value of M.type, and make a new one of those.
var/tempType = M.type
var/mob/monsters/enemy = new/tempType()

In response to Flick
I think you meant
new tempType
instead of
new/tempType()

If so, no effect =/ Same problem occurs, it breaks on the same line, I still have 2 debugs, one before the line and 1 after, and I still only get the one before and nothing continues.

This is retarded! It's like some retarded error with Byond Beta 10 (Or if its a full release now, then with that version, whatever the latest is). It just REFUSES to work, but it used to about 2-3 months ago.
In response to Polantaris
Could you post the runtime error?
In response to Elation
Thats the problem. There isn't one. I have Define DEBUG on, I have everything that would normally be used to get correct runtime errors, but it just FREEZES at the new line, as if it breaks from a bug or something.

That's the thing that annoys me the most. I might have been able to figure it out myself if I actually got a runtime error, but I don't =/
In response to Polantaris
Oh, then look at your mob/monster's New() proc. It's probably never returning (possibly going into a while() loop that never ends), thus "freezing".
In response to Elation
Ah, thank you! That was the problem. In the monster's New() proc, it set them to randomly walk, but since they were created in no where, I just set a check to make sure they had a loc, and now it works. I'm surprized there was no runtime error for this, seeing as how it would try to move them in no where. No matter, now it works, and I thank you for this assistance.