is possible a variable goto or gosub? maeloterkim Junior Member Posts: 47 Threads: 22 Joined: Mar 2019 Reputation: 0 09-27-2021, 01:50 PM (This post was last modified: 09-27-2021, 02:03 PM by maeloterkim.) Hi in the original  ZX spectrum basic you can do this goto MyVariable  or gosub MyVariable  where this variable must be a line number this way we can goto or gosub to diferents routines that are in diferents line numbers but i tried this example with the compiler and says error: Syntax Error. Unexpected token 'MyRoutines' This is the example you can try: dim MyRoutines(2) as uInteger => {  @MyRoutine1, _    '' address of my routine 1                                                        @MyRoutine2, _    '' address of my routine 2                                                       @MyRoutine3 _    '' address of my routine 3                                                   }                                 dim myVariable as uByte = 1 gosub MyRoutines(myVariable)     '' you can try goto too myLoop: goto myLoop MyRoutine1: print "MyRoutine 1" return                    MyRoutine2: print "MyRoutine 2" return                    MyRoutine3: print "MyRoutine 3" return        Is possible do something like that without a lot of ifs ? I think i found a solution The solution i found is this: dim MyRoutines(2) as uInteger => { @MyRoutine1, _ '' address of my routine 1 @MyRoutine2, _ '' address of my routine 2 @MyRoutine3 _ '' address of my routine 3 } dim myVariable as uByte = 0 poke uInteger (@pokeGosub1 + 1), MyRoutines(myVariable) pokeGosub1: gosub MyRoutine1 myLoop: goto myLoop MyRoutine1: print "MyRoutine 1" return MyRoutine2: print "MyRoutine 2" return MyRoutine3: print "MyRoutine 3" return I do a poke with the routine direction just before the gosub maybe you can implement this with the compiler this way the behaviour is more like the original ZX spectrum boriel Administrator Posts: 1,757 Threads: 55 Joined: Aug 2019 Reputation: 24 09-28-2021, 07:41 PM (This post was last modified: 09-28-2021, 07:42 PM by boriel.) (09-27-2021, 01:50 PM)maeloterkim Wrote: Hi in the original  ZX spectrum basic you can do this goto MyVariable  or gosub MyVariable  where this variable must be a line number maybe you can implement this with the compiler ... this way the behaviour is more like the original ZX spectrum You don't need all of this. Use ON ... GOTO /  ON GOSUB instead. Code:```on myVariable gosub MyRoutine1, MyRoutine2, MyRoutine3 myLoop: goto myLoop MyRoutine1: print "MyRoutine1" return MyRoutine2: print "MyRoutine2" return MyRoutine3: print "MyRoutine3" return``` Try this, and let me know if it works. maeloterkim Junior Member Posts: 47 Threads: 22 Joined: Mar 2019 Reputation: 0 09-28-2021, 09:56 PM (This post was last modified: 09-28-2021, 09:56 PM by maeloterkim.) (09-28-2021, 07:41 PM)boriel Wrote: (09-27-2021, 01:50 PM)maeloterkim Wrote: Hi in the original  ZX spectrum basic you can do this goto MyVariable  or gosub MyVariable  where this variable must be a line number maybe you can implement this with the compiler ... this way the behaviour is more like the original ZX spectrum You don't need all of this. Use ON ... GOTO /  ON GOSUB instead. Code:```on myVariable gosub MyRoutine1, MyRoutine2, MyRoutine3 myLoop: goto myLoop MyRoutine1: print "MyRoutine1" return MyRoutine2: print "MyRoutine2" return MyRoutine3: print "MyRoutine3" return``` Try this, and let me know if it works. Yes it works  But i didnt found this   ON .. GOTO OR GOSUB in the documentation ( https://zxbasic.readthedocs.io/en/docs/identifier/ ) maybe there is something or a lot more that we dont know boriel Administrator Posts: 1,757 Threads: 55 Joined: Aug 2019 Reputation: 24 09-29-2021, 08:07 AM (09-28-2021, 09:56 PM)maeloterkim Wrote: (09-28-2021, 07:41 PM)boriel Wrote: (09-27-2021, 01:50 PM)maeloterkim Wrote: Hi in the original  ZX spectrum basic you can do this goto MyVariable  or gosub MyVariable  where this variable must be a line number maybe you can implement this with the compiler ... this way the behaviour is more like the original ZX spectrum You don't need all of this. Use ON ... GOTO /  ON GOSUB instead. Code:```on myVariable gosub MyRoutine1, MyRoutine2, MyRoutine3 myLoop: goto myLoop MyRoutine1: print "MyRoutine1" return MyRoutine2: print "MyRoutine2" return MyRoutine3: print "MyRoutine3" return``` Try this, and let me know if it works. Yes it works  But i didnt found this   ON .. GOTO OR GOSUB in the documentation ( https://zxbasic.readthedocs.io/en/docs/identifier/ ) maybe there is something or a lot more that we dont know Unfortunately (I checked yesterday) GOTO / GOSUB and IN documentation is lost (I moved the wiki long ago, some documents were not restored correctly). I'll put them back. Thanks for reporting. If you find any other broken link, please let me know. « Next Oldest | Next Newest »