ID:2069410
 
(See the best response by FKI.)
Code:
chainball
icon = 'chainball.dmi'
density = 0
pixel_x = -32
layer = FLY_LAYER
New()
Swing()
proc
Swing()
for(var/mob/M in view(src, 0))
view(M) << narrate("<b><font color = red> [M] is hit by the [src]!")
spawn(10) return.()
Click()
Swing()


Problem description:

Nothing wrong with the actual function of the proc as I've tested it with Click(), but calling the proc through New() doesn't seem to do anything? I've looked and looked but I can't find anything wrong with it.

Maybe it's something silly I've missed? Any takers?

-B
You need to include ..() in New()
Could you elaborate? I thought ..() was used for calling parent procs?
spawn(10) return.()

You shouldn't be using recursion here.

This is going to cause a stack overflow.
I'm gonna have to come clean and admit I don't know what recursion or stack overflow mean.
In response to GreatPirateEra
GreatPirateEra wrote:
You need to include ..() in New()

Could I please ask where abouts? And why I needed to do this?
Recursion is the concept of repeating the same steps. Recursion is more or less what you would think of as "looping".

A recursive algorithm is one that repeats the same steps multiple times. For instance, some genius thought it'd be hilarious to define recursion as:

Recursion:
the repeated application of a recursive procedure or definition.

The definition of recursion is recursive, meaning the definition of recursion uses itself to define itself.

Funny right?



Now, in programming, recursion means something a little bit different. Recursion is repeating the same proc within itself.

"." is the recursion operator. It calls the same proc from within itself when using the invocation operator: "()".


A "stack" is a buffer that holds pending instructions and local variables during the operation of a program. Stacks have a limited size. When you use more space in the stack than the stack contains, that's called an "overflow".



Actually, upon reviewing the code, spawn() prevents the overflow because it separates the recursion from the existing call stack and reinserts at depth 0. So it won't actually cause a stack overflow, but you still shouldn't be using recursion.

        proc
Swing()
for(var/mob/M in view(src, 0))
view(M) << narrate("<b><font color = red> [M] is hit by the [src]!")
spawn(10) return.()


The reason for this is that recursion has invocation overhead, and the spawn() instruction has reinsertion overhead that better, more robust patterns do not, and there are also stack trace issues that tend to arise from recursive calls that prevent intelligent debugging.

        proc
Swing()
set waitfor = 0 //sets this function as non-blocking
while(src) //could be while 1, but while src is fine
for(var/mob/M in view(src, 0))
view(M) << narrate("<b><font color = red> [M] is hit by the [src]!")
sleep(10)


In general, recursion should only be used where iteration cannot solve the problem at hand. Using recursion everywhere that iteration would complete the task, you are creating a recipe for disaster.
In response to Ter13
This is a revelation to me, Ter! I can't thank you enough for taking the time to reply to my help post. I've never used the set function before as I'm pretty much self taught.

Unfortunately the proc still isn't working when I put it under New(), this is really strange because it works when I put it under Click() and call it manually, any thoughts?
In response to Bumblemore
Mind showing the code for both testing methods?

The problem likely has to do with what GreatPirateEra hinted at, though it depends on how exactly the object is being used.
In response to FKI
Hi there, the code is exactly the same for the testing method, I just replaced New() with Click().

chainball
icon = 'chainball.dmi'
density = 0
pixel_x = -32
layer = FLY_LAYER
New()
Swing()
proc
Swing()
set waitfor = 0
while(1)
for(var/mob/M in view(src, 0))
view(M) << narrate("<b><font color = red> [M] is hit by the [src]!")
sleep(10)
Click()
Swing()
In response to Bumblemore
Where is the part where a chainball is created?
In response to FKI
The chainball is an object, I've put it on the map manually.
Weird. I've made several attempts to reproduce your issue and cannot.

Are you sure these are all of the relevant pieces of the puzzle?
In response to FKI
I believe so. It's weird, as New() still works with other procs, it's just Swing() which isn't working.
Is this something you'd be willing to send to one or more of us to look at? I wouldn't mind taking a look at the source code, as nothing stands out as far as what's in this topic.
In response to FKI
Sure thing, I'll link you.
In response to FKI
Ah.

proc/narrate(msg as text)
usr << output("[msg]", "info.text")

// ...

view(M) << narrate("<b><font color = red> [M] is hit by the [src]!")


The Swing() procs works. However, you aren't seeing the output because of the way you are using the above proc. You can confirm this by putting a regular message there and testing.

view(M) << "Hey [M]!"


narrate() should return text at the very least if it's going to be used like that.

Also, you might want to set your output (control id is info.text) as the default output. As it stands, you still won't see the above unless you directly output() it to the aforementioned control id.
In response to FKI
Hello again! Thanks for taking a look at the source, but the Swing proc still isn't working for me, even when I swap the entire contents of the proc with something simple like: world << "hello!"
    chainball
icon = 'chainball.dmi'
density = 0
pixel_x = -32
layer = FLY_LAYER
New()
Swing()
proc
Swing()
set waitfor = 0
while(1)
world << "Beepidy Boppidy Boop!"
sleep(10)
Click()
Swing()
Page: 1 2