26 June 2020, 10:30 | #1 |
Prototron
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 421
|
Jumping to a label in another procedure
Is it possible to jump to a label within a procedure from another procedure? I've been trying to do this but with not much luck, and it'd be REALLY handy if it were possible.
For example, if Label_1 is inside Procedure 2 and Procedure 2 is called from inside Procedure 1: Code:
Procedure 1 Goto Label_1 Proc Procedure 2 End Proc |
26 June 2020, 16:33 | #2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,200
|
No. Not possible.
|
26 June 2020, 18:46 | #3 |
Registered User
Join Date: Sep 2019
Location: Leicester / England
Posts: 203
|
It's 20+ years since I last did any AMOS, but you could "sort of" do it by passing an argument to the second procedure and, if that argument is a set value go to that label as below.
Any usage of "PRC2" will need an argument so, if you don't want to jump to the label, use something like PRC2[0]. It's not particularly nice programming though. If you need the same code in more than one procedure then put it in it's own procedure and just call that procedure from where it is required, or just merge both procedures and use If Then statements. Code:
' Run procedure PRC2 without jumping to the label PRC2[0] ' Run procedure PRC1 which in turn runs PRC2 jumping to the label PRC1 ' The first procedure Procedure PRC1 Print "In Proc1" ' Call the second procedure with a '1' to jump to the label section. PRC2[1] End Proc ' The second procedure - call this with a '1' to jump to the label, or anything else to not. Procedure PRC2[ARG] If ARG=1 Then Goto LABEL1 Print "Not jumping" Goto PRC2END LABEL1: Print "Jumped to the label" PRC2END: End Proc |
01 July 2020, 09:52 | #4 |
Prototron
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 421
|
Wow that's interesting! Thanks for that Exodous.
|
01 July 2020, 15:53 | #5 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,438
|
A different way of looking at this would be to split up the procedures into separate components. That saves the need for using goto's and is a good way to functionally split your program up into smaller components.
Such a method can help getting you smaller (sometimes even faster) and also easier to read/debug programs. So, in this example you'd have Procedure 1, Procedure 2 and Procedure shared_1_2 (naming is for the example only, choose a name that fits what the procedures do ) Then, you'd call proc 1 or 2 and they'd call proc shared_1_2 as needed. |
02 July 2020, 20:07 | #6 | |
Prototron
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 421
|
Quote:
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
AmigaOS 3.9 / 4xEIDE´99 install procedure and recommendations | DreamT_2018 | support.Apps | 10 | 18 March 2018 23:27 |
Floppy drive cleaning disk procedure | Vaninna | support.Hardware | 1 | 19 May 2017 00:34 |
how to quit procedure? | aszu | Coders. AMOS | 6 | 08 April 2016 23:59 |
Screen fip procedure | arti | Coders. System | 2 | 28 September 2014 19:40 |
Procedure for Saving WHDLoad | jamespstevenson | support.WinUAE | 8 | 14 April 2009 20:30 |
|
|