ID:264653
 
So I was going through my code, coding my dna structuring system, when all of a sudden a few procedures stopped working. I inspected my set up and found an interesting solution to why it wasn't working.

First of all I have two code files, dna.dm comes first before inc_dna.dm does in this order:
dna.dm
inc_dna.dm


Now in dna.dm I have this:
#include "inc_dna.dm"

generate_structures()
world<<"generated"

I then have in my inc_dna.dm,
proc/generate_structures()


I learned that it wasn't calling the procedure in my dna.dm file but instead going to inc_dna.dm to call it, thus having no effect when I call the procedure. First of all dna.dm comes first, but calls in the code from inc_dna.dm defining the generate procedure. I then define the generate_structures procedure after the include line but I think it is then reading from the next code file; inc_dna.dm thus having a reversing effect on the procedure definition.

This is my theory, but what I find interesting is I have the same setup under multiple procedures only they are defined in datums and are not global. They work perfectly...? Has anyone else run into this problem? I mean I can easily get around it but I just find these circumstances interesting.

If you override a proc in the exact same scope, in separate files, then the behavior is as good as unspecified. The solution is not to do that.
In response to Garthor
Yes but I do that with other procs only the procs are defined in datums, and they work perfectly... I'm just wondering why that is?
In response to Smokey Joe
Because you aren't doing "that" in other procs. I doubt I can explain this to you in words, so I'll just give an example:

// OKAY:
mob
proc/dance()
src << "You dance"
dancer
dance()
src << "You dance really well"

// NOT OKAY:
proc/blah()
// stuff

blah()
// different stuff


On its own, it's poor design. When you start mixing them up in different source files, it starts messing things up.
In response to Garthor
Yes but I AM doing that in other procs, here look at this.
The file body.dm precedes inc_body.dm

This is body.dm:
#include "inc_body.dm"

datum

body
create(nam)
src.name = nam
dna = get_dna()
update_dna()

who = ckey(nam)
density = 1

get_dna(list/L,src.name)
var/datum/dna/d = new()
d.create_dna(L)

return d



Then in inc_body.dm I have this:
datum


body //the body datum

proc/create(name,species) //creates the body
proc/destroy() //destroys body


proc/tickle()
proc/get_dna(list/L) //grabs a new generated dna, L is anything specific
proc/update_dna() //update body status based on dna code
proc/change_dna()


Same setup as my dna files, yet this works while my dna procedures failed.
In response to Smokey Joe
Does it have anything to do with being global? The only difference between these two I can see is the dna procedures were global, these are not.
In response to Garthor
mob
proc
abc()
world << 1

abc()
world << 2
..()

abc()
world << 3
..()


You can override the datum function a million times in the same scope and it will work.

proc
abc()
world << 1

abc()
world << 2
..()

abc()
world << 3
..()


This however doesn't.
In response to Keeth
I just was wondering why that is? Maybe its not that big of a deal but things like this just bug me.
In response to Smokey Joe
I think the only guys who can answer this are the guys who work on the source.