ID:1460411
 
(See the best response by Ter13.)
Not sure if this should be in the help area, or the design philosophy area. Either way, I have a question about something that I can't really answer myself.

I've played some games, which got me back into BYOND programming, starting off on AI programming this time.
I will have several professions in the game, which the AI can be switched to. (E.G Building, cleaning, whatever, think of something)

Although I am unsure how to approach this. My initial thought was to turn it into some kind of job manager with datums. (/datum/job_manager/etc)

But I do not believe this would work, if at all.
So my second way would be to use a generalized mob proc with a switch in it. So it can just get to the code for the profession it is assigned to at that point.

How would I approach this at all? Are my methods even going to work?

I understand I write as random as one can possible be, so I hope you understand the question in this post.

- Laser.
Best response
I don't understand why you think that a generalized approach using datums won't work.

It will work fine. More than likely, your second approach, using switches won't be as clean, and harder to debug later, so you might want to stick with a more generalized approach using datums to manage and process jobs for NPCs.
My thoughts were that datums couldn't work as AI procs, in the way that they aren't really designed for mobs.

I wrote up a small "test" proc through a datum which I think would work, but since I haven't ever worked with datums before, I have no clue.

http://puu.sh/66ToV.png

^^ Would the above image's code work in such way?
In response to Laser50
As long as you pass the NPC to the datum, it can do anything to it.
Your linked image is empty. Use DM tags to show code on the forums.

Anyway, datums work just like any other object, so long as they have exposure via variables to whatever other objects they need to function, they can do anything, for the most part.

The only thing that makes a mob different from a datum, is that mobs are one of the internal datums that BYOND uses to display and interact with the world by default.

Datums are just objects. Mobs are just specialized datums.
How is it even possible to use datums to make a mob carry out an action, anyway?
In response to GamerMania
Not all programming only directly uses usr and src, you know.
In response to Kaiochao
I still don't understand. It seems to me that all a datum is is just another object that can be applied to atoms. How could that replace a proc?
In response to GamerMania
GamerMania wrote:
I still don't understand. It seems to me that all a datum is is just another object that can be applied to atoms. How could that replace a proc?

Datums can be applied to atoms can be applied to datums.

Programming 101: Objects and methods can modify the public properties of any object they are given a handle to. Thus, a datum could affect a mob if it was given a handle to that mob, just like a mob could affect the properties of a datum if it was given a handle to that datum.
To try to put it simpler, if you use a datum, you can do much more than you could do with one proc. You can have multiple procs in a datum, and therefore one datum can be used to encompass a whole slew of actions while keeping them in one centralized and organized area. All you need is to give the mob a variable reference to the datum.
In response to Albro1
Albro1 wrote:
To try to put it simpler, if you use a datum, you can do much more than you could do with one proc. You can have multiple procs in a datum, and therefore one datum can be used to encompass a whole slew of actions while keeping them in one centralized and organized area. All you need is to give the mob a variable reference to the datum.

Could you post an example similar to what OP was getting at? I still don't quite understand. How can a datum have control over an atom?
mover
var
dir = SOUTH
mob/mob
state = 0
delay = world.tick_lag
proc
start()
set waitfor = 0
if(!state)
state = 1
while(state)
step(mob,dir)
sleep(delay)
stop()
if(state)
state = 0
toggle()
if(state)
stop()
else
start()
New(dir,mob,state,delay)
src.dir = dir
src.mob = mob
src.state = state
src.delay = delay
if(state)
start()


This would be a datum that makes the supplied mob walk in one direction continuously. This is a not very useful example, but still an example.
Ah, it makes more sense, now. Thank you.
My current code, which I wrote rather quickly. My friend is still a bit skeptical about the capabilities BYOND has (I just love optimization work..)
(I hope this comes out okay..)
datum/jobmanager/builder
// BUILDER JOB

datum/jobmanager/builder/proc/FindBuilds(mob/M)
if(needsbuild && needsbuild.len > 0)
var/obj/building = null
for(var/obj/O in needsbuild)
building = pick(O)
return building

datum/jobmanager/builder/proc/StartBuilds(mob/M, var/obj/O)
if(M && O)
step_to(M, O, 1, 16)
if(get_dist(M, O) <= 1)
for(var/mob/MO in ohearers(world, M))
MO << "\icon [M.name] Starts construction on the [O.name]."
sleep(100) // 10 second buildtime for now.
O:stage = 1
O.icon_state = "r_wall_[O:stage]"


I am pretty sure this will work, if not, it shouldn't be hard to solve.
However, how would I go around calling this on a mob? I've tried using the "help" panel, but it didn't include that.
Managed to call him, I call this a victory, as I had no idea how that stuff worked previously.
Any way, proc testd, the guy moves. Fak yeah! thanks, all!
You don't have to start datums with /datum. Any type you define is automatically a datum (including atom subtypes, of course).
I write it out full because it makes the code easier to understand. No point in taking shortcuts if it messes my brain up :P
In response to Laser50
I think it would mess up your understanding more to think you might be able to define a type that isn't a datum.