GOSUBS totally new LOOP?
Blitz3D Forums/Blitz3D Beginners Area/GOSUBS totally new LOOP?
| ||
;My code looks something like this ;graphics3d 800,600,16 ;;; create global variables ;;;etc ;;; ;; While not key down(0) ;gosub updatetime ;other gosubs ;frame limiting code end while .updatetime if time<600 time=time +1 endif Return .othergosubs return ;;;MY QUESTION is I have frame limiting code in my while loop, do I have to Include the frame limiting code in my GOSUBS also for my program to run at the SAME speed while in a gosub? In other words, while in a gosub does the program just LOOP their until it hits the return statement? For example in my updatetime gosub, the time variable increases until it hits 599. Does the time variable increase at the COMPUTERS fatest process time or does it computes this at the frame limittting code time I have in the main loop. |
| ||
Programs are executed line by line. The main loop can't continue until the subroutine returns so the answer is no, you don't need the frame limiting code in the subroutine also. It behaves exactly as if you'd in-lined the subroutine:;graphics3d 800,600,16 ;;; create global variables ;;;etc ;;; ;; While not key down(0) if time<600 time=time +1 endif ;other gosubs ;frame limiting code end while .othergosubs return Hope that helps clear things up a bit. |
| ||
using functions is a lot better than using gosubs...you can make reusable functions that can be used in other games...saves a lot of programming down the road and your code will be easier to understand and follow... |
| ||
I disagree. If your subroutine is a subroutine, define it as a subroutine. If it's a function then define it as a function. They're different things with different overheads -- it's worth preserving the distinction for the sake of code clarity (and you can cut and paste one as easily as the other). |
| ||
GOTO or GOSUB IS AWFUL to be honest! I did rather do case select and while loop or repeat until which all are very good. |
| ||
I hate using labels because 1. They seem really messy 2. I don't completely understand the difference Gosub and Goto(I did read the command reference but I don't remember what it does because I don't use the command) 3. Lack of End Label. Even though it's not needed, I'm just used to using the ending commands like EndIf End Function Next Forever Until End Post ;hehehe |
| ||
Lack of End Label. Even though it's not needed, I'm just used to using the ending commands DON'T LOOK AT IT!! :P |
| ||
I agree with Sledge, if you need absolute speed, in say a path finding algo. Thousands of iterations per function/subroutine call. If it's for a specific global function, then i don't see the need to not use them. If your code runs well, and your probably not going to revise it, then :D |