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.

Author
Message
Baldielocks
7
Years of Service
User Offline
Joined: 28th Mar 2017
Location: Grimsby, England
Posted: 21st Jan 2020 12:44
Hi folks, used APK classic a couple of years ago, bought APK studio, I used gosub to got to other routines , Studio does not seam to have this function , has it been replaced or does it not exist in APK studio ?
Cheers
Chrissell
11
Years of Service
User Offline
Joined: 2nd Apr 2013
Location:
Posted: 21st Jan 2020 19:15
I used this code in AppGameKit Studio and it worked fine:

do
gosub Printer:
Sync()
loop

Printer:
Print("Hello")
return


C.R.Sellen
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 21st Jan 2020 20:01 Edited at: 21st Jan 2020 20:02
It definitely works fine in Studio here too. Or do you mean jump to the code within the IDE itself? The gosubs are listed in the Functions list, so you can jump to the code there within the IDE.
Baldielocks
7
Years of Service
User Offline
Joined: 28th Mar 2017
Location: Grimsby, England
Posted: 23rd Jan 2020 18:46
Cheers Folks.
GreekToMe
14
Years of Service
User Offline
Joined: 27th Oct 2009
Location: Colorado
Posted: 25th Jan 2020 17:06
It will make things easier if you use the "#include" command in your setup portions of your project and point your gosub there.
For example:
#include "somefile.agc"
Then inside this file you could have a label like :

SomeSubroutine: (notice the collon)
code follows here
return

Then from somewhere in your setup or inside the Do Loop portion of your program, you will call
Gosub SomeSoubroutine (no colon here)
And because of the #include the program knows where to find it.
Of course you will have to create a new source file named "SomeFile.agc" as part of your project and you can store one or many subroutines, which will keep things tidy.
Of course you can still call the "Gosub" routine in the normal top down way.
I hope this helps
Cheers to you too!

I hope this helps
gerdich
6
Years of Service
User Offline
Joined: 16th Apr 2018
Location:
Posted: 26th Jan 2020 20:37
BTW: An array of "Gosubs" would be nice. Would be a game changer.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 26th Jan 2020 20:54 Edited at: 26th Jan 2020 21:10
Quote: "BTW: An array of "Gosubs" would be nice. Would be a game changer."

They are pretty much obsolete nowadays because it is way more efficient to use a function
and a function may be called as many times as you like, there are even such things as recursive
functions that call themselves over and over again until the final output results. Which
can make three lines of code replace 100 and it will also run faster

an example of a recursive function is the common factorial function

just try and replace that with gosubs if/then etc and just see how large and complex your code ends up
Quote: "
I think it would make a great programming challenge to create a factorial routine that doesn't use recursion"
MerryChristmas Everyone
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
gerdich
6
Years of Service
User Offline
Joined: 16th Apr 2018
Location:
Posted: 27th Jan 2020 01:29
An array of "Gosubs" would allow to jump with an index. This is not possible with functions. Event handlers could be such arrays. Also a job list ... You could construct a for loop to work on the Gosubs.
I see many ways of use for an array of "Gosubs".

BTW: Every recursive function can be translated in an iterative one.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 27th Jan 2020 06:04
Personally, I'm not a friend of gosub and goto's.
But everyone should use the one that gets him to his goal the best.

The counterpart of a gosub array would be the switch/case functionality.
Surely the spelling would be a bit shorter with a gosub array.
But you lose the readability of your code.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 27th Jan 2020 07:39
function pointers would be the go
gerdich
6
Years of Service
User Offline
Joined: 16th Apr 2018
Location:
Posted: 27th Jan 2020 14:27
There are no function pointers in Basic. An array of Gosubs would correspond to an array of function pointers, where you can freely add functions and start them by index. In each Gosub you can call whatever function you want with the parameters you need. A Gosub is like an anonymous function without parameters.

Login to post a reply

Server time is: 2024-04-19 04:26:02
Your offset time is: 2024-04-19 04:26:02