You have some debugging output, what kind of results are you getting? I'm failing to see where the issue is without being able to identify what exactly the issue is.
|
Something I've Noticed:
Should I actually comment out the AI_Wander() call in the New(), most of the issues are actually resolved. Those issues being: o -- Created Mobs have the correct fields o -- Both Created Mobs and the Original Mob have the correct, "Family Members" in their Family-list variables. o -- The for-loop is actually completing all of its intended cycles without issue, creating the right amount of mobs. |
Hmm...try using recursion like this, rather than your while loop in AI_Wander():
mob/proc/AI_Wander() |
Well Albro, with the AI_Wander() statement in, I'm getting results such as:
State: Amnt: 4 | Mem: 2 | Cycle: 2 State: Amnt: 3 | Mem: 5 | Cycle: 2 State: Amnt: 1 | Mem: 1 | Cycle: 1 The for-loop terminates after the first Cycle regardless of anything else. And the variables which should hold new information in the Created Mob based on the Original Mob are blank. Should I take out the AI_Wander() call however... State: Amnt: 2 | Mem: 4 | Cycle: 2 State: Amnt: 3 | Mem: 1 | Cycle: 3 State: Amnt: 4 | Mem: 2 | Cycle: 4 The for-loop runs through all of its intended cycles without issue. This has lead me to believe the problem is a loop-related one, like an endless loop / some anomaly being created in the loop / something. |
Oh ho! Thank you Albro1! You've nailed it, mate!
Tell me, what exactly does that mean? That it can only work via recursion? Haha, I'd like an explanation on this! |
In response to YoukoSieg
|
|
Recursion vs. Iteration. It can be argued back and forth, but basic facts are that recursion is usually slower and it will fill up the call stack. This means that it will run into overflow errors quicker than an infinite loop. However in the case of DM, there are times where recursion is just...needed.
In this case, the difference is that the while loop continuously ran. It did not let anything get in front of it in the line. It went up, bought its ice cream, then stood there to buy some more rather than letting the next person in line go. (I'm not sure, but this issue may be solved by using set background = TRUE - you may want to test that out rather than use recursion) Recursion, however in this case, does everything you need it to do right away, then uses spawn, which basically is just like sleep, but it lets other procedures go ahead and execute while it is waiting. The thing you have to remember though is that loops like while won't wait on a spawn that is inside of it. If you use spawn instead of sleep in a while loop, the loop will just keep on going because the spawn is letting it. The main advantages of recursion are that it is easier to manage (Rather than a ton of nested loops) and you can make it more elegant. |
Ahhh, I see! Basically, it's all about the order and priority of the functions. Also, I always thought that recursive procedures were faster than the typical iteration procedures? (at least, that's what they taught me in University, haha).
P.S. -- No, it does not work with the while loop and "set background = TRUE". Just tried it and the old issues came back. I guess this would be one of those times that recursion is simply a must, haha. |
At any rate, many thanks again Albro1! Likewise to the rest of you that tried helping out as well. With this, I can press with the rest of my work to be done.
Again -- Thank you all. |
To be specific, the issue was that AI_Wander() never returned, causing mob/New() to never return. Because of that, your AI_GenerateFamily() was getting stuck at:
var/mob/Lady_Wife/A = new(src.loc, 0) The spawn() in Albro1's recursive loop allowed AI_Wander() to return, which allowed mob/New() to return, which allowed that branch of AI_GenerateFamily() to continue. As an alternative to recursion, you can also just spawn the the while() loop: mob/proc/AI_Wander() |
Previous Remarks
Huh... Thanks Dark for pointing that out. New Dilemma So, after finding a solution to my previous problem, I continued on about with testing my code for the AIs. I'm also trying to develop a procedure which will allow players to actually assign tasks to the AI and have them follow through with orders / missions. Here is the code: Code: AI_Tasks() For Clarity: So, for clarity's sake, the Tasks are defined in such a way: Task/var How it Works: So, I've already created some pre-defined Tasks to test out this little system. The AIs with the Tasks are expected to go chasing along their Route if there is one. This list will consist of a series of location coordinates that the AI will try to get as close as possible to, to follow to reach their Target(s). Should there not be a Route, then the AI will simply pursue their Target(s) by rushing in that direction and then checking if they are still proceeding in the right way every few seconds. Upon reaching their Target(s) they will then carry-out the Action which corresponds with each Target accordingly in the list. After that Target has been successfully dealt with, he is added to the Completed List and removed from the Targets List, so as not to cause confusion and to keep track of the Progression of the overall Task. When the final Target is dealt with, the overall Task has been Completed and would be remove. For the time being however, I have simply made debugging statements to simulate for the Completion of the Task. Simple, right? The Issue: Once the AI has found its first Target, he does not follow through the rest of the code to carry out the required Action for that Target. Furthermore, through the use of the various debugging statements placed throughout the code, I've found that the AI doesn't even leave AI_ChaseCheck() as his "State" Variable always remains as "Found [Target]..." instead of, "Cycling in Actions with [M]..." Again, thank you all in advance for any input you give on this matter. P.S. Please assume that AI_Task is called near the end of AI_Wander. Also, I've recently changed AI_Wander to reflect what Dark had noted earlier. |
Well then, to anyone else who isn't lazy - preferably someone who has responded to my previous issue in the matter and not someone new; like the above guy?
P.S. Compared to what I've put up earlier, it's really not that long... I think you're either just lazy or trying to be a troll, Hebrons. |
In response to YoukoSieg
|
|
YoukoSieg wrote:
Well then, to anyone else who isn't lazy - preferably someone who has responded to my previous issue in the matter and not someone new; like the above guy? I lold at the Asker's pick Anyway, I'll get to work on this when I'm done making my coffee. And maybe one more Payday 2 heist. |
Meh, it was me being sarcastic. In retrospect, I should not have bothered with doing that.
Thanks for taking the time out to try when you get the chance though, Rushnut. |
I may be completely wrong here, it's hard to visualize this situation without writing out the code myself and testing it, but it looks as though this could be a problem with you using spawn(Timer).
The AI_Tasks() proc is halted by the AI_Chase() proc, to allow them to, well, chase. You then spawn() more code in to continue chasing, which will allow AI_Tasks() to continue operating, at the same time as your AI_Chase(). The simple fix (albeit untested and completely conceptual) would be to turn the spawn() into a sleep(). |
Yes, I've actually tried that already; with using sleep() instead of spawn(), and the results were not exactly what I wanted.
When I tried this, it made the mobs move only 1 at a time to their respective Target(s) to carry out their Task. I guess this would be so because AI_Tasks() is actually called by AI_Wander() [which uses the spawn() proc], which is called by New(). In a nutshell, it is as if I'm waiting on one Mob to complete its Task before another Mob can begin to do the same, where I want the result to be that all the mobs would be going about their own business, performing their Tasks without having to wait on someone else. Edit: It does however though, get the Mobs continuing along the AI_Tasks() procedure. |
How are you having all the mobs in the world's ai called? Are you just looping through them or are they actually routines placed on the mobs that get called upon New()?
Or something more funky? If you're doing the loop option (which I suspect you are from the way you're describing the situation), then you need to spawn() everything within each iteration of the loop. |
Yup. It's the looping option. And yup, that's why I had the spawn() stuff. And yet, I'm stuck with this AI_Chase() procedure stuff. So I don't know if I'm missing something or not; like another spawn() proc somewhere? (Though I've no idea where it'd go...)
|
2 -- The AI_StartUp() does in fact generate the "House" value and therefore should be placed before the AI_GenerateFamily(). Corrected that just now.
3 -- The reason for that if(x == Num) condition was so I could see where the procedure was being terminated (whether inside the loop, or outside the loop). Not sure myself why I had a break-statement though, haha.
With the things you have just pointed out changed Albro1, the issue(s) still persist, I'm afraid.