Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Why use subroutines?

Author
Message
Drifter
21
Years of Service
User Offline
Joined: 24th Jun 2003
Location:
Posted: 26th Jun 2004 04:50
Why use subs when you can just put stuff in the loop etc?

"Sun makes me sneeze but thats a different story"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 26th Jun 2004 04:57 Edited at: 26th Jun 2004 05:00
Simply because your loop becomes very crowded and hard to read. It's easier to look at, and follow the game logic

do
gosub getinput()
gosub calcai()
gosub chkcollision()

sync
loop

functions are better to use in certain situations. Especially if they have their own static variables, this way they can be used in other programs. They can return values and be used in "if" conditions. They make programs easier to troubleshoot. If a function has been tested and works as long as it's passed the write variables it will work in another program.

In addition:
subroutines are also good for developing & bug-testing. It's easier to rem out the gosub call rather than needing to rem out all the lines in your game loop. If you need to bypass a certain portion of code, just place rem infront of the gosub call. When you need it bvack you only need to remove the singel rem statement.


~zenassem


CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 26th Jun 2004 05:00
Not to mention using subs and functions makes your code reusable.


* DBP_NETLIB_v1.4 - w/VARIABLE WATCHER & CONSOLE! * Click Logo
Drifter
21
Years of Service
User Offline
Joined: 24th Jun 2003
Location:
Posted: 27th Jun 2004 07:48
k thanks

"Sun makes me sneeze but thats a different story"
Zero Blitzt
20
Years of Service
User Offline
Joined: 18th Jan 2004
Location: Different Stages
Posted: 27th Jun 2004 08:09
I wrote an IRC bot in DarkBasic Pro, and no matter what I did, it would not execute any of my functions, but when I turned the functions into Subroutines, they worked fine. You have to be careful when using both, like after your subroutine code, always remember to put return.

GameXaero forums - www.t4e0.4cybiko.com
Rush owns--> www.Rush.com ---> I'm going to see them Aug. 7

Login to post a reply

Server time is: 2024-11-26 22:30:04
Your offset time is: 2024-11-26 22:30:04