ID:151985
 
Okay, so I made a code, so that the various things would stack, by delaying one thing after another if something was happening.
if(something)
//code
else
spawn(number)
//exact same code as before
What I was wondering was how could I have an else statement such as that without putting the exact same code twice.
I thought of using a proc, but it's not really the best choice for something that is only used once right there in the code.
A universal proc wouldn't work either, because in the places I'm using this, the code is quite different.
I was thinking maybe a goto statement, but I'm looking into that.
Just posting this so I could get an idea of what you guys would do.
EDIT: Found a fix that gave me an outcome I liked.
label
if(something)
//code
else spawn(number) goto label
//OR
//The following way is without an infinite loop:
if(!something) spawn(number) goto label
label
if(something)
//code

The first way will cause an infinite loop until something is true, which in my case was the outcome I liked, and I think it could be replaced with a while loop that uses the sleep proc. The second one doesn't cause a loop, and can cause the wanted result, but not the way I wanted it to, strangely.
Do you think it's a justified use of the goto statement?
I'd simply use a proc. Might be a #define instead, only if it's really more applicable.
A very quick workaround you could do, if the side effects are no bother, is:
var/number = time + rand(1,1) //just whatever you already have
if(Condition) //if the condition is true, you didn't want to delay it
number = null
spawn(number)
MyCode


(the more condensed, less clear, un-var-modifying version would be:)
spawn(Condition? null : number)
MyCode


Of course, like I said, remember your spawn()ed code will only run once the current proc either finishes or encounters a sleep()-like instruction, so it's not exactly the same as porting the code to a proc would be. Of course, you could stick a sleep() (empty arg, or null) directly afterwards to make it run, but that obviously has natural disadvantages to your proc, well, depending on what it does. Naturally.

EDIT: Since I don't really know what you're doing, if I used goto, I'd do it simply like this more efficient way:
if(something) goto Label
else spawn(x) goto Label
//end of proc, or whereever needed
Label
MyCode


As for being justified use of goto, I'm not really sure. Perhaps you can manage with using sleep() to delay the proc itself in this manner?
if(!Condition) sleep(number)
MyCode


If that happens to be suitable for what you're trying to do, that'd be the better approach.
In response to Kaioken (#1)
I ended up wanting the affect caused by an infinite loop, so here is what I needed:
while(!condition) sleep(number)
//code
And happy 4th of July if you're in America (or you celebrate it nonetheless).
Note: The problem I found with using a loop like this or a goto or any of the examples I showed, was that it had to be at the end of the code, otherwise everything below wouldn't happen for a while or would happen repeatedly.