ID:179643
 
I'm not sure if this is even possible and I'm sure my code is probably completly inane, but how would I return variables to a proc from three levels in?

e.g.
mob
proc
proc1()
do stuff
proc2()
proc2()
do more stuff
proc3(something, another, one_more)
proc3()
do even more stuff
variable1
variable2
Evilkevkev wrote:
I'm not sure if this is even possible and I'm sure my code is probably completly inane, but how would I return variables to a proc from three levels in?

e.g.
mob
proc
proc1()
do stuff
proc2()
proc2()
do more stuff
proc3(something, another, one_more)
proc3()
do even more stuff
variable1
variable2


not sure, but maybe ..() would work.
Evilkevkev wrote:
I'm not sure if this is even possible and I'm sure my code is probably completly inane, but how would I return variables to a proc from three levels in?

e.g.
mob
proc
proc1()
do stuff
proc2()
proc2()
do more stuff
proc3(something, another, one_more)
proc3()
do even more stuff
variable1
variable2

Are you talking about this?

/mob
proc
proc1()
do stuff
return proc2()
proc2()
do more stuff
return proc3(something, another, one_more)
proc3()
do even more stuff
return variable1

verb
do_stuff()
world << proc1()


The above code (assuming it was actual code) would print the return value of proc3 to the world. When you return from a procedure, you can use the return value (which goes in the place of the procedure call) just like you would any other value--you can assign the value to variables, use it in if statements, and fortunately for you, use it in return statements.
In response to Leftley
proc3()
do even more stuff
return variable1


How would i return variable2 also?

[EDIT]
I'm guessing I could do this in a list and then return the list which can be broken down later, but if there is a better way, please let me know.

[Again]
That seemed to work, but how would I then use the results from the list and save them as variables in proc1?
In response to Evilkevkev
Evilkevkev wrote:
proc3()
do even more stuff
return variable1


How would i return variable2 also?

Hrm... that depends on the situation, I think. One way, if variable1 and variable2 can be found more or less separately, you should just use different procs. Even if one variable depends on the other, it's relatively easy to use separate procs to find each:

/mob
proc
proc1()
var/a = 2
return proc2(a)
proc2(b)
return b + 2
proc3(c)
return c + 5
verb
do_stuff()
var/c = proc1()
world << c
world << proc3(c)

The first output line will display 4 to the world; the second will display 9. If you really need to get the values for two variables and don't feel like separating the procs you use to get them, you could make a list with the values:

/mob
proc
proc1()
var/a = 2
return proc2(a)
proc2(b)
var/c[] = list()
c.Add(b + 2)
c.Add(proc3(b + 2))
return c
proc3(d)
return d + 5
verb
do_stuff()
var/c[] = proc1()
world << c[1]
world << c[2]

I'm pretty sure that would do the same thing as the above example.

Lastly, if variable1 and variable2 and a few other associated variables are ones that you need to use in sets a lot, you might want to define a datum type to handle the information in sets:

/thingy
var
a
b
proc
proc1()
a = 2
return proc2()
proc2()
a = a + 2
b = proc3()
return src
proc3()
b = a + 5
return src

/mob
verb
do_stuff()
var/thingy/T = T.proc1()
world << T.a
world << T.b

This does the exact same thing, but it's an incredibly silly example... come to think of it, they're all incredibly silly examples. I'm guessing you're probably looking for something along the lines of the first two examples anyways.