Author Topic: Jump without Lbl-Goto  (Read 6143 times)

0 Members and 1 Guest are viewing this topic.

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Jump without Lbl-Goto
« on: October 15, 2010, 07:38:32 am »
Is there any ways to jump to other part of program without using Lbl-Goto?
I heard that the Lbl-Goto slows down a game a lot :(
Sig wipe!

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Jump without Lbl-Goto
« Reply #1 on: October 15, 2010, 11:09:02 am »
You could make a second program that your main program calls when you want to use a specific piece of code, but that would require the user to have both of those programs on their calc when playing. I think it's faster than Goto, but I'm not sure.

EDIT: Oh, it seems like you already did use this. I don't know any other methods than Goto and subprograms.
« Last Edit: October 15, 2010, 11:12:06 am by JosJuice »

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: Jump without Lbl-Goto
« Reply #2 on: October 15, 2010, 11:25:04 am »
Instead of something like

Code: [Select]
Lbl 0
If something
Goto 1
If somethingelse
Goto 2
Goto 0
Lbl 1
Do stuff
Goto 0
Lbl 2
Do some other stuff
Goto 0

You would use

Code: [Select]
While 1
0->A
If something
1->A
If something else
2->A
If A=1
Do stuff
If A=2
Do some other stuff
End

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Jump without Lbl-Goto
« Reply #3 on: October 15, 2010, 03:40:18 pm »
Note that goto's themselves do not slow a game down, only is they are misused.  That and the fact that they take a bit of time to execute (since the OS searches your whole program for the Label to jump to) and could make parts of your game slower.

Goto can also make your game run slower if they are used incorrectly, try running this program

Code: [Select]
0->A
Lbl T
A+1->A
If getKey=0:Then
Output(1,1,A
Goto T
End

You will notice as the program counts, the numbers seem to increase slower and slower.  This is because you have a Goto inside of an If:Then block.  When the calculator enters the If:Then block, it sets aside a bit or memory so that it knows what to do when it gets to the End that closes the block.  However, you Goto out of this block and up into T.  The TiOS doesn't realize this, and so it still has that chunk of memory set aside.  Enter the If Block again and another chunk of memory is set aside.  Do this enough and eventually your program gets the dreaded Error:Memory!

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: Jump without Lbl-Goto
« Reply #4 on: October 15, 2010, 03:49:04 pm »
Note that goto's themselves do not slow a game down, only is they are misused.  That and the fact that they take a bit of time to execute (since the OS searches your whole program for the Label to jump to) and could make parts of your game slower.

Goto can also make your game run slower if they are used incorrectly, try running this program

Code: [Select]
0->A
Lbl T
A+1->A
If getKey=0:Then
Output(1,1,A
Goto T
End

You will notice as the program counts, the numbers seem to increase slower and slower.  This is because you have a Goto inside of an If:Then block.  When the calculator enters the If:Then block, it sets aside a bit or memory so that it knows what to do when it gets to the End that closes the block.  However, you Goto out of this block and up into T.  The TiOS doesn't realize this, and so it still has that chunk of memory set aside.  Enter the If Block again and another chunk of memory is set aside.  Do this enough and eventually your program gets the dreaded Error:Memory!
They can slow things down if the label is at the bottom of a 10 KB large program, though. In some cases, there's a 1 second loading time until the TI-OS reaches the appropriate lbl.

Offline Silver Shadow

  • Beta Tester
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +27/-7
    • View Profile
Re: Jump without Lbl-Goto
« Reply #5 on: October 15, 2010, 03:53:40 pm »
Yeah, so try not to use Gotos inside parts which are executed very often (such as key detects, grayscale,...).
Former Coder of Tomorrow


Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Jump without Lbl-Goto
« Reply #6 on: October 15, 2010, 03:55:15 pm »
Instead of something like

Code: [Select]
Lbl 0
If something
Goto 1
If somethingelse
Goto 2
Goto 0
Lbl 1
Do stuff
Goto 0
Lbl 2
Do some other stuff
Goto 0

You would use

Code: [Select]
While 1
0->A
If something
1->A
If something else
2->A
If A=1
Do stuff
If A=2
Do some other stuff
End


I use both methods when I do BASIC. I use If: Then commands to control small, fast routines and Lbl/Goto commands to implement subroutines. Subprograms take a bit of time to load, so I try to reserve them for loading entirely new areas of a program, such as a second menu.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

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: Jump without Lbl-Goto
« Reply #7 on: October 15, 2010, 03:56:16 pm »
Yeah, I noticed sub-programs seems to take a bit, especially when you have many or run low on memory. In Metroid II Evolution the speed drop is insane x.x

Offline Silver Shadow

  • Beta Tester
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +27/-7
    • View Profile
Re: Jump without Lbl-Goto
« Reply #8 on: October 15, 2010, 03:57:20 pm »
Yeah that's why I always try to have only 1 program.
Former Coder of Tomorrow


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: Jump without Lbl-Goto
« Reply #9 on: October 15, 2010, 03:59:10 pm »
THe issue, though, is when the sub program is extremly large, skipping the massive if condition seems to take a while too. Notice how long the pause is when an event is triggered in Reuben Quest. So in some cases, I am worried there may not be much of a difference.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Jump without Lbl-Goto
« Reply #10 on: October 15, 2010, 04:07:09 pm »
I actually have a method to speed up those If:Then lags. It eats up memory, but that's usually not a problem if you're working in BASIC ;)

Basically, you group all of the similar If: Then commands into one larger If: Then command. Then, when the program looks at the block, it evaluates only one If statement and it can simply skip computing the rest of the block. It won't make your program blazing fast, but it will make reasonably quick from painfully slow.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

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: Jump without Lbl-Goto
« Reply #11 on: October 15, 2010, 04:23:37 pm »
Yeah that's what I do with Illusiat 13. It speeds things up considerably. I think in Reuben, they're one after each others. I wonder if Reuben could have them grouped in a way that makes the game faster...
« Last Edit: October 15, 2010, 04:24:47 pm by DJ Omnimaga »

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Jump without Lbl-Goto
« Reply #12 on: October 15, 2010, 04:50:05 pm »
I used it with CAD, because there were a LOT of different If: then statements necessary and they were conveniently grouped by function.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

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: Jump without Lbl-Goto
« Reply #13 on: October 15, 2010, 04:50:40 pm »
I don't know if this is what you want but hers a piece of code using gotos but not that slow:

:Lbl 1
:stuff
:End
:While 1
:stuff
:Goto 1

and you can break out of it by changing the while condition.  and the goto isn't slow if the label is at the top.  ;)

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>

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: Jump without Lbl-Goto
« Reply #14 on: October 15, 2010, 05:55:31 pm »
Doesn't that cause an ERR:SYNTAX the first time it goes through Lbl 1, though? ??? (assuming that's at the program top)