return;

Posted By: DLively

return; - 04/28/15 09:21

Quote:
Terminates the function


Is this required at the end of EVERY function?

what if its occupying an action inside of a while loop? still return every frame?

Code:
function groove(ENTITY* ent){
    vec_set(ent.x, my.x);
    return;
}
action radio(){
    while(good_song == playing){wait(1);
        groove(player);
    }
}



Thanks guys! laugh
Posted By: 3run

Re: return; - 04/28/15 09:39

Originally Posted By: DLively
Is this required at the end of EVERY function?
No, but if you want to terminate function at the middle or right at the beggining (if something is wrong, f.e. empty pointer?) you can use it.

Originally Posted By: DLively
what if its occupying an action inside of a while loop? still return every frame?

Code:
function groove(ENTITY* ent){
    vec_set(ent.x, my.x);
    return;
}
action radio(){
    while(good_song == playing){wait(1);
        groove(player);
    }
}

As far as I know, your example will just run a function (groove), which will move player at 'radio' entity position and then terminate.. It will be the same as if 'return' wasn't there at all, that's not the way 'return' meant to be used. Return can also terminate function with a loop inside, but if there is a 'wait' inside of that loop, return won't be able to return any value (f.e. if you want to return a variable), because (as the manual says) 'wait' already returns to the calling function before the final return statement is excecuted.

Anyway, it's not for the first time I see you putting 'wait' at the beginning of the loop, and I wonder why?
Posted By: DLively

Re: return; - 04/28/15 10:03

Thanks 3run.

I figured I didn't need them there, but wanted to make 100% sure.

I put my wait at the beginning for organizational purposes. It doesn't make any (real) difference in the way it runs.

Cheers!
Posted By: 3run

Re: return; - 04/28/15 10:13

Originally Posted By: DLively
I put my wait at the beginning for organizational purposes. It doesn't make any (real) difference in the way it runs.
Sure it does not, but it's not really a good way to organize your code, and I hope that you don't use such approach in your tutorials.

Cheers!
Posted By: DLively

Re: return; - 04/28/15 16:17

Oh? Please, Explain to me why its not a good way to organize my code because it seems you're bothered that I have a specific way of doing things...
Posted By: Quad

Re: return; - 04/28/15 16:25

where you put your "wait" actually depends on what you are doing.
Posted By: DLively

Re: return; - 04/28/15 16:35

Thanks for your response Quad.

Perhaps you can explain to me a bit better what it is you mean, because I don't understand entirely.
Posted By: 3run

Re: return; - 04/28/15 16:36

Originally Posted By: DLively
Oh? Please, Explain to me why its not a good way to organize my code because it seems you're bothered that I have a specific way of doing things...
There is no SPECIFIC ways to do things here. If you like specific ways, go and create your own language or game engine. With Acknex you can do things correct, or incorrect. Placing 'wait' in most of your code/situation (which I've been noticing for a quiet a while) at the beginning of the loop is incorrect (even if not noticeable for your eyes, cause it's only one frame!). And stop acting like that! If you don't like people helping you (by advice or anything else), don't ask for help and be on your own.

Cheers!

Edit: technically you wait one frame before the loop, and then run the script, but normally loop should run the script and then wait for one frame and run it over again! It may mix things up at the end (you and me pointers f.e.), and you'll be trying to find your mistake endlessly!

Edit2: if you still trying to be a smart ass, open manual and read about 'wait'. Especially read about 'Scheduler List' and the order it's stored! Also take a look at this:
Originally Posted By: Manual
* wait(1) is often used at the end of a while loop which is to be executed once per frame cycle.
Don't try to reinvent the wheel, instead just try to learn the engine with it's functionalities!
Posted By: DLively

Re: return; - 04/28/15 16:43

Quote:
And stop acting like that! If you don't like people helping you (by advice or anything else), don't ask for help and be on your own.



Like what?
Im asking you to tell me the correct reason since you'd seemed to have it. I didn't realize you'd have your own secret reasons. You still never told me why its incorrect.
Posted By: 3run

Re: return; - 04/28/15 16:47

Originally Posted By: DLively
Like what?
Im asking you to tell me the correct reason since you'd seemed to have it. I didn't realize you'd have your own secret reasons. You still never told me why its incorrect.
Do I need to remind you about my help I offered with creating some basic tutorials? And then you just got 'sad' somehow and advised me to create tutorials on my own? Only cause I wanted to create something more basic that fps tutorials you are working and advised to use better input than having tons of if/else for just making player move in XY directions?

Originally Posted By: DLively
Okay, then based on your last answer your wrong.
I had this discussion on this forum already. It doesn't make a difference.
I've edited previous post, plus share a link where you can prove me that I'm wrong?
Posted By: DLively

Re: return; - 04/28/15 16:54

Okay, then based on your last answer your wrong.
I had this discussion on this forum already. It doesn't make a difference.



If an entity creates entities in the middle a while loop (wait can be on either end of ent_create) and each created entity has a while loop as well that they are just starting. Then None of those while loops will ever be in sinc... I hope you don't think a while loops wait keep all while loops in sinc...



And quit assuming im being a smart ass.



ALSO: I had not accepted your offer because you were making suggestions I didn't like - So I declined. I didnt get 'sad'. I just didn't like your ideas.

I really hope your not still butthurt about that.
Posted By: 3run

Re: return; - 04/28/15 17:01

You already got answered by Sid about this, here. Read this quote from him once again, and then read what I've wrote about mixing things up and leading to some crap results (with f.e. you and me GLOBAL pointers) which you'll try to find out and lose your time for nothing!
Originally Posted By: WretchedSid
The only difference you will see is when your function yields back to others and when it performs its operation. You can also have a wait in the middle if that tickles your fancy, your local variables and my and you will be restored. However, note that wait() allows other functions to resume execution which may or may not have side effects on globals that you have to take into account. Of course only if it applies to your use case.
Anyway, why should I care? I only wanted to help you once again.

Cheers smarty pants wink

Originally Posted By: DLively
I really hope your not still butthurt about that.
No bad feelings from my side anyway. Peace, pal.
Posted By: DLively

Re: return; - 04/28/15 17:18

Just because you talk doesn't mean everyone is going to listen, Helpping someone entails that THEY WILL TALK BACK and give you their input and thoughts too (even if they may be inccorect [thats learning baby]) -- If you don't want people to give you their thoughts then make that clear when you post that you expect them to take your advice and close the thread (this is the second thread I see you pull this in less than a month).

I couldn't find that post to re-read it, so thanks for digging that up.
-----------------------------------------------------------

Quote:
Of course only if it applies to your use case.


I've been using this method forever and have not had any issues with it at all. Everything works and does what I tell it to.

only recently have I found a reason I might ad-hear to the above rules which is why I came back to find out - TO MAKE SURE. But apparently no one can argue their side with 3run (unless you want him to scold you for nonsensical reasons.)

Quote:
Anyway, why should I care? I only wanted to help you once again, but I see you are clever enough by your own, so no help from my side any more.

Soon 3run wont have anyone to help if he keeps telling people this...
Posted By: 3run

Re: return; - 04/28/15 17:20

Originally Posted By: DLively
Just because you talk doesn't mean everyone is going to listen, Helpping someone entails that THEY WILL TALK BACK and give you their input and thoughts too (even if they may be inccorect [thats learning baby]) -- If you don't want people to give you their thoughts then make that clear when you post that you expect them to take your advice and close the thread (this is the second thread I see you pull this in less than a month).

I couldn't find that post to re-read it, so thanks for digging that up.
-----------------------------------------------------------

Quote:
Of course only if it applies to your use case.


I've been using this method forever and have not had any issues with it at all. Everything works and does what I tell it to.

only recently have I found a reason I might ad-hear to the above rules which is why I came back to find out - TO MAKE SURE. But apparently no one can argue their side with 3run (unless you want him to scold you for nonsensical reasons.)
grin
Posted By: txesmi

Re: return; - 04/28/15 17:22

Originally Posted By: Quad
where you put your "wait" actually depends on what you are doing.
© 2024 lite-C Forums