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 / differences for 'gosub' and 'function'?

Author
Message
Anti Human
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Good ol\' West Virginia
Posted: 1st Aug 2008 07:16
alright, so my codes a mess and i'm trying to clean it up.

as it was, every thing was ran off subroutines from the main do loop, or in some cases from those subroutines.

it took a bit of rewiring and heavy use of varius If statements, but i managed to get every gosub from in a gosub to return, then return again, to the main do loop (not placing the loop in a subroutine and then gosub'ing to that from with in a tier 2 subroutine).

that was then, this is very not then. tried adding xp, lvl's, and a shop to my little battle sequence and now every thing is SNAFU.

so i'm wondering if i shouldn't try out functions. i'v never actually used a function before, so i'm going over 60's tut on them; but i couldn't find where any one has said at which one should use a function over a subroutine, or vise-versa.

thanks

Today is a good day, at least compared to tomorrow.
And every day is a good day to die, because then, there is no tomorrow
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 1st Aug 2008 17:33
quick simple answer is if you want to past some info to part of your code say the id x y z position of something the with a gosub you would have to set it up either with a global varable or x=xx, with a function you can do this with tellfunction(id,x,y,z) the other part would then be function tellfunction(newid,newz,newy,newz) and endfunction to return.
eg
gosub way


or in functions
function way


hope that helps.

Dark Physics makes any hot drink go cold.
Anti Human
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Good ol\' West Virginia
Posted: 1st Aug 2008 19:03
sweet. thanks Howdo

umm, one thing. i'v read that you can use arrays to return more then one value from a function, but i can't find where i read that now and am not sure how to set that up. a link or psuedo?

Today is a good day, at least compared to tomorrow.
And every day is a good day to die, because then, there is no tomorrow
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 1st Aug 2008 19:15
If you'er meaning Dim Mydim(200) then this is global, or if you are asking can a function return a value or string then yes but only one.

eg:
endfunction value
or
endfunction string$

Dark Physics makes any hot drink go cold.
Anti Human
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Good ol\' West Virginia
Posted: 1st Aug 2008 19:33
but can you dim mydim(200) then modify the data inside the array from with in a function?

sorry if you just answered that, comperhension is almost as bad as my spelling.

Today is a good day, at least compared to tomorrow.
And every day is a good day to die, because then, there is no tomorrow
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 1st Aug 2008 21:34
Learning how this works does get a bit in the deep end.

when you do dim mydim(200) it like getting a filing cabinet with 200 draws in it, All of which empty to start, then you go through them adding information.

so if you said mydim(93)=1 then did a for next loop

eg
for x= 0 to 200
print mydim(x)
next x

when it got to 93 it would show a one.

Dark Physics makes any hot drink go cold.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Aug 2008 00:26
Quote: "but can you dim mydim(200) then modify the data inside the array from with in a function?"

Yes.



Anti Human
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Good ol\' West Virginia
Posted: 2nd Aug 2008 05:08
Thanks, gonna see what i can work out on straighting the code some.

Today is a good day, at least compared to tomorrow.
And every day is a good day to die, because then, there is no tomorrow

Login to post a reply

Server time is: 2024-11-25 19:45:04
Your offset time is: 2024-11-25 19:45:04