mob
proc
AutoSave()
set background=1 // is it a good idea to use set background here?
src.Save()
spawn(600)
src.AutoSave()
Followtheotherguy(mob/M)
set background=1
src.loc=M.loc
sleep(1)
src.Followtheotherguy(M)
ID:161803
![]() Mar 30 2008, 6:07 am
|
|
I'm kind of new to byond and things such as 'set background' are new to me as well. I heard that setting background makes the call sleep, then recalled again, something like that. I just don't know where it's correct to place it.
|
Takoma wrote:
Mind pointing some out for me? Of course not. Well, both your procs call themselves recursively to achieve a loop. There isn't an advantage in using it just like that, and it is better to just use a looping construct like for() or while() to loop the whole thing without calling new procs all the time. Remember, you can use 'infinite loops' (they'll loop without conditions, like your code does now) with them too; using while(TRUE) ('TRUE' is just a macro for '1') will loop indefinitely because, of course, 1 will always be a true value every time the loop checks it. Using for(), just like that, with no arguments, also quickly creates an infinite loop, that doesn't need to check any condition. In your second proc there are much larger problems though. Firstly, the implementation of making a mob follow another by repeating a simple src.loc=M.loc every single iteration (!!!) is, no offense intended, very very bad. It should definitely NOT be done this way to make a movable automatically follow another, and you should also usually refrain from forcing setting the 'loc' variable when dealing with movement, since it's not as "complete" as using the full fledged Move() proc or similar. If you're familiar and used procs like Enter() Exit() Entered() etc, forcing setting loc will not trigger them, as only Move() will call them, so your code there will not run. Also. In the 2nd proc you forgot to put a spawn() before calling a new instance of the proc. This means, the current, 1st proc, will wait until the new 2nd one finishes, but it never will because it creates a 3nd one and waits for it to finish, etc etc, calling new procs over and over until a crash error. Using spawn() stops the procs from waiting for the procs they've called to finish, so they exit gracefully and not remain. |
"In the 2nd proc you forgot to put a spawn() before calling a new instance of the proc."
Like this? mob |
That will technically work, but it's still the wrong way to do things. It should be the job of the thing that is moving to have any followers follow it:
mob |
..() and .=..() just get deep into my nervs. I've tryed looking for a guide about those on byond 'Help On' with dreammaker, gave a look around the tutorials, and found nearly anything that explains that nicely and understandable. <.<
|
..() is "do the previously defined action". . is the variable that will be returned by default (if you have no return statement, the proc will return . by default when it ends).
|
I'm the same... I know the basics of '..()', but .=.. +.... or what ever, just confuse me.
mob Confusing. |
First of all, you can't define a proc twice. Only the first one needs the verb in front of it. Once it's been defined with "proc" or "verb" you can override it with just the proc name (like what you do with Move() or Enter()).
Additionally, the ..() is in the wrong one. To do what you're trying to do there: mob |
It might be hard to understand that setting (. = ..()) at first from Garthor, my, or the DM Reference's explanations. It is rather simple actually; I'll show you exactly how it works just without actually using the . variable so it's clear. But it will be a problem if you don't know about 'return' yet though. Look it up and learn about it if that's the case...
mob/Move() //overriding a proc. the default Move() returns true or false according to the success of the movement |
This might help you understand ..()
Whenever you are looking up a proc in the DM F1 help and you see a Default action section, think to yourself "so this is what ..() means" |
Well, did you look it up in the DM Reference, since it's new to you? You don't need to count on what you've heard/what you remember you've heard, the documentation is right there. It explains it pretty well, but, no, both your procs don't really need it. They have other problems, though.