Author Topic: Why never to use Goto.  (Read 23408 times)

0 Members and 2 Guests are viewing this topic.

Offline Magic Banana

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 371
  • Rating: +77/-1
  • It's not an apple, it's a ... magic banana.
    • View Profile
Re: Why never to use Goto.
« Reply #15 on: August 09, 2010, 10:47:20 pm »
I use Goto all the time.  It's pretty useful if you know what you are doing.
^This.

I still find a use for it, although whenever I use it I just do some checks to make sure no loops are being jumped out of or just kinda force it out (if condition, End, End, End, etc. until you are out then Goto.) I use it to jump back to the top of my code, where I can go anywhere depending on certain variables.
I do sprites and stuff, so yeah.

Quote from: yunhua98
i'M NOT SURE WHAT A SWORD SKILL IS BUT HERE'S THE SWORD ANIMATION FROM THE TWO SPRITES ON PG 13

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Re: Why never to use Goto.
« Reply #16 on: August 09, 2010, 10:48:28 pm »
I usually write my code so I don't need Gotos.
I've never encountered something that couldn't be reworked easily. (But then, I've not done much coding where Gotos would be useful)

EDIT: 100 posts!
« Last Edit: August 09, 2010, 10:48:48 pm by MRide »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Why never to use Goto.
« Reply #17 on: August 09, 2010, 10:55:29 pm »
The best scenario i use goto in is this.  If a goto is called at the very beginning of a program, it can be the fastest way to get to the bottom of the program.  When i have large amounts of map data lets say, i have things like this

If T=1:Goto1
If T=2:Goto2
...

Lbl 1
MapData1
Return

Lbl2
MapData2
Return

Horribly memory inefficient, but faster than putting every room inside If:Then Blocks. 

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Re: Why never to use Goto.
« Reply #18 on: August 09, 2010, 11:03:55 pm »
Hm... that's faster?  I'll have to try that out then.  coincidentally, I'm actually doing the exact same thing right now.

Offline tifreak

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2708
  • Rating: +82/-3
  • My Kung Fu IS strong...
    • View Profile
    • TI-Freakware
Re: Why never to use Goto.
« Reply #19 on: August 09, 2010, 11:19:54 pm »
I stopped using Gotos and Lbls once I found an article on BASIC Guru that said it was possible to create games without them. That was.. I don't know, 10 years ago? I made my second game because of that article that used not one lbl or goto.

Simply by using a While loop as a main loop, and utilizing while loops and If:Then conditionals inside that loop, I can maneuver around in a program much faster than any silly Goto/Lbl combo.

The only draw back to coding with While loops in that manner is that the code can get confusing, so you have to take lots of notes on what you are doing, but once you get it figured out, it is worth using. Plus, lack of risking memory leaks is kinda nice. :p
Projects: AOD Series: 75% | FFME: 80% | Pokemon: 18% | RPGSK: 60% | Star Trek: 70% | Star Trek 83+: 40% | TI-City: 5%

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Why never to use Goto.
« Reply #20 on: August 09, 2010, 11:29:01 pm »
I never use Goto's to create loops, only for special jumps or the like.  I sometime abuse them within subprograms if i know the memory leak is going to be erased 1 second after it is created :P

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Why never to use Goto.
« Reply #21 on: August 10, 2010, 12:34:43 am »
Sadly, those memory leaks were not documented very well back in the days and tutorials on which it was were hard to find, so if you play stuff like Illusiat 11 or 12 or even ROL2, I suggest that you save often, else you can end up with ERR:MEMORY. Just to say how badly documented it was back then, FFTOM series have the game quit completly and tell the user to press ENTER to resume gameplay after exiting menus, before/after battles or even in the middle of battles.
Yep, I remember those days. The dark ages of TI-BASIC... :P It was odd, because alot of us knew about ERR:MEMORY occuring, we just had the damnedest time figuring out what the hell was causing it, many times which GOTO was the culprit. It's great that so many more things are documented these days and newbs starting out have access to so much good information. :)

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Why never to use Goto.
« Reply #22 on: August 10, 2010, 01:40:47 pm »
Sadly, those memory leaks were not documented very well back in the days and tutorials on which it was were hard to find, so if you play stuff like Illusiat 11 or 12 or even ROL2, I suggest that you save often, else you can end up with ERR:MEMORY. Just to say how badly documented it was back then, FFTOM series have the game quit completly and tell the user to press ENTER to resume gameplay after exiting menus, before/after battles or even in the middle of battles.
Yep, I remember those days. The dark ages of TI-BASIC... :P It was odd, because alot of us knew about ERR:MEMORY occuring, we just had the damnedest time figuring out what the hell was causing it, many times which GOTO was the culprit. It's great that so many more things are documented these days and newbs starting out have access to so much good information. :)

it's heros like you guys that figured it out for our gen. :D
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline eriktheorange

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +1/-0
    • View Profile
Re: Why never to use Goto.
« Reply #23 on: August 10, 2010, 01:48:16 pm »
I try to avoid using goto, but often I'm just too lazy.

Need to get back to a bit at the very start of the program? Whatever, goto. I'm just making dumb little games because I'm bored in class, so what?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Why never to use Goto.
« Reply #24 on: August 10, 2010, 02:18:55 pm »
There's one trick to reduce the slow down caused by Gotos in games. The trick is to put the game main menu at the complete bottom of the code. Start the program with Goto 0, which goes to the menu, and after Goto 0, the game engine and stuff should be there.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Why never to use Goto.
« Reply #25 on: August 10, 2010, 04:58:08 pm »
There's one trick to reduce the slow down caused by Gotos in games. The trick is to put the game main menu at the complete bottom of the code. Start the program with Goto 0, which goes to the menu, and after Goto 0, the game engine and stuff should be there.

interesting, i will do that :)
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Why never to use Goto.
« Reply #26 on: August 10, 2010, 05:02:11 pm »
I generally prefer using subprograms and then recalling it it in and then use goto to go to it and loops broken by the goto's that jump back.  Like:

:Repeat 1
:Goto A
:End
<code>
:Label A
<subroutine>
:End

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

_player1537

  • Guest
Re: Why never to use Goto.
« Reply #27 on: August 10, 2010, 05:36:15 pm »
I generally use them to jump back to the beginning of the code, or like this:
:For(A,0,1
:If Not(A
:Goto AA
:End
<code>
:Lbl AA
<subroutine>
:End

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Why never to use Goto.
« Reply #28 on: August 10, 2010, 06:29:27 pm »
The best scenario i use goto in is this.  If a goto is called at the very beginning of a program, it can be the fastest way to get to the bottom of the program.  When i have large amounts of map data lets say, i have things like this

If T=1:Goto1
If T=2:Goto2
...

Lbl 1
MapData1
Return

Lbl2
MapData2
Return

Horribly memory inefficient, but faster than putting every room inside If:Then Blocks. 
It's too bad there's no switch statement in TI-BASIC like there is in C.

Offline patriotsfan

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 118
  • Rating: +2/-0
  • Go Pats!
    • View Profile
Re: Why never to use Goto.
« Reply #29 on: August 10, 2010, 06:59:20 pm »
I don't think I have ever used Goto unless I am creating my own custom menu.


Doomsday: 12/21/2012 6:11 AM EST 11:11 AM GMT