English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. AMOS

 
 
Thread Tools
Old 26 June 2020, 10:30   #1
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
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
The manual details on how to jump in and out of procedures using variable values, but not labels.
Brick Nash is offline  
Old 26 June 2020, 16:33   #2
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
No. Not possible.
Samurai_Crow is offline  
Old 26 June 2020, 18:46   #3
Exodous
Registered User
 
Join Date: Sep 2019
Location: Leicester / England
Posts: 201
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
Exodous is offline  
Old 01 July 2020, 09:52   #4
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Wow that's interesting! Thanks for that Exodous.
Brick Nash is offline  
Old 01 July 2020, 15:53   #5
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,408
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.
roondar is offline  
Old 02 July 2020, 20:07   #6
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by roondar View Post
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.
Yes I think that's the kind of thing I'm looking for. I love the fact that Procedures can be closed and compact to one line which is very tidy (I wish subroutines could do that), and I was trying to use them like subroutines but obviously they are a bit more detached than that.
Brick Nash is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 22:36.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09110 seconds with 13 queries