ID:1658613
 
(See the best response by Kaiochao.)
http://pastebin.com/fyFwfzXg (uploaded cut code there because formatting here doesn't work)

For some reason that code doesn't want to work despite "spawn(0) .()".

Also, i'd been reading reference for hours, but i still can't understand why it's said
spawn while (1) will work as "ticker".

Isn't code in "spawn" block executed once? In this case that will work next way:
1. Because of spawn(0) we wait till other code is done.
2. When it's done, it starts infinite while_loop and it freezes.

while(1) spawn in this case will work, but not reverse.
Best response
"spawn(0) .()" causes an infinite loop without a delay, which is bad.
"spawn(0) .()" causes an infinite loop without a delay, which is bad.

But it should wait until other code is done, shouldn't it? But it causes freeze when you start your world.

Also, i accidentaly created the thread in "Design Philosophy".
In response to EditorRUS
You should probably take a look at this post.
The . proc creates a recursive loop. Calling it will make the current proc repeat itself over and over; in this case without a delay.

Also, you don't need to put the 0 in there, as spawn's default value is spawn(Delay=0). Simply spawn() would work. However, you'd need to indent the code to be under spawn(), otherwise it wouldn't do anything.
in this case without a delay.

I don't get it - why no delay now? I set it to 1 now, but still - no idea why it doesn't work. Moreover, set background = 1 doesn't help a bit.

Also, you don't need to put the 0 in there, as spawn's default value is spawn(Delay=0). Simply spawn() would work. However, you'd need to indent the code to be under spawn(), otherwise it wouldn't do anything.

I know, i can even use just spawn for that.
In response to Reformist
Just want to mention (as I didn't get why it would loop) - It calls the current proc, constant with a filesystem, not the parent.
There's no such proc called Start() in datum/explosions.
Moreover, /datum/explosions doesn't exist at all, it's just to make controller, explosion marker and explosion_data distinguisable and belonging to one system.

Just want to mention (as I didn't get why it would loop) - It calls the current proc, constant with a filesystem, not the parent.

So, what i wanted to do? I wanted to send to the event_handler of BYOND call for this procedure to call it _by the end_ of other events. It's a controller, isn't it? So, Start() proc is basically starts this controller, so it will check its state every tick and do something depending from the state.

But instead i can't get this
_by the end of tick_
with spawn(0), which works this way according to reference.
Here is what your code does:

Call start()
Queue call start()
finish start()
finish New()
work queue
Queue call start()
finish start()
work queue
Queue call start()
finish start()
work queue
Queue call start()
finish start()
... (you get the point)


Most likely you want to not call .(), and instead indent the rest of your code in a spawn(1). You've not given us what the intent really is to do yet though, so that is just a guess.
Most likely you want to not call .(), and instead indent the rest of your code in a spawn(1). You've not given us what the intent really is to do yet though, so that is just a guess.

Well, i have replaced spawn(0) to spawn(1) already and it works, but i still don't get why it freezes as if i made never-ending recursion.
In response to EditorRUS
spawn(0) will wait for any other scheduled events to finish in the current tick before running. Because it thinks you want a delay of zero, it won't let the next tick occur until it finishes. Because you created an infinite loop with .(), it will never finish, and the game will freeze as it can't move to the next tick.

Also, you can post code on the forums by surrounding it in <dm> YOUR CODE HERE </dm> tags:
            Start()
spawn(0) .()
switch(state)
// ...
Oh, now i get it.
Spawn(0) puts intended code in _the end_ of event_handler's list?

Therefore:
event_handler.events_to_do[][]
...
spawn(0) -> event_handler.events_to_do[0] += event where 0 means current tick...

In this case that was misunderstanding because i thought:
spawn(0) -> event_handler.events_to_do[1].Insert(1, event) //Put an event in _the start_ of event_handler's next tick list.

So, basically:
spawn(n<0) -> event_handler.events_to_do[0].Insert(1, event)
spawn(n) -> event_handler.events_to_do[n] += event

Or even more shorter:
spawn(n) -> event_handler.events_to_do[max(n, 0)].Insert(event_handler.events_to_do.len*floor(min(n,1))+1, event)

But i still don't get any point in spawn while (1).
So you can have a ticker process in the background that doesn't block the parent proc. For example, suppose you wanted to run a proc named do_any_possible_random_event() every 10 minutes.

world/New()
start_event_ticker()
..()

/proc/start_event_ticker()
spawn()
while(1)
sleep(600)
do_any_possible_random_event()


Without the spawn, world/New() would try to wait until start_event_ticker() finished running, which it never would.