Goto And Gosub Instructions Don't work With Me

Just starting out? Need help? Post your questions and find answers here.
Fasasoftware
Posts: 47
Joined: Tue May 26, 2015 11:22 pm

Goto And Gosub Instructions Don't work With Me

Post by Fasasoftware »

Dear friends,

I treyed to make a label, for example PIPPO: and then put goto code like this:

Code: Select all

START:
bla bla bla code

Goto PIPPO

bla bla bla code

PIPPO:
CanvasGadget(#GADGET_Canvas, 10, 10, 380, 380, #PB_Canvas_ClipMouse | #PB_Canvas_Border)
  
  If StartDrawing(ImageOutput(#IMAGE_Color))
    Box(0, 0, 35, 35, CurrentColor)
    StopDrawing()
  EndIf
Goto START



The same for Gosub.

Code: Select all


bla bla bla code

Gosub PIPPO

bla bla bla code

PIPPO:
CanvasGadget(#GADGET_Canvas, 10, 10, 380, 380, #PB_Canvas_ClipMouse | #PB_Canvas_Border)
  
  If StartDrawing(ImageOutput(#IMAGE_Color))
    Box(0, 0, 35, 35, CurrentColor)
    StopDrawing()
  EndIf
return


The Compiler says "Syntax Error"! Why?

Can Somebody Help Me?

Thanks A lot.

Lestroso :oops:
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Goto And Gosub Instructions Don't work With Me

Post by Peter »

it seems that Goto und Gosub are not implemented.

Greetings ... Peter
Fasasoftware
Posts: 47
Joined: Tue May 26, 2015 11:22 pm

Re: Goto And Gosub Instructions Don't work With Me

Post by Fasasoftware »

It's Strange, goto and gosub are very important to jump from code. I hope in the next releases it will be implemented.

Best regards,

Lestroso :P
User avatar
SinisterSoft
Posts: 77
Joined: Sun Apr 06, 2014 11:41 pm
Location: Preston, UK
Contact:

Re: Goto And Gosub Instructions Don't work With Me

Post by SinisterSoft »

They need a way of faking labels as I don't think they are available in javascript.
User avatar
eddy
Posts: 124
Joined: Thu Mar 27, 2014 8:34 am

Re: Goto And Gosub Instructions Don't work With Me

Post by eddy »

SinisterSoft wrote:They need a way of faking labels as I don't think they are available in javascript.
Faking GOTO command is possible with some limitations. (article : http://zo0ok.com/techfindings/archives/1904)
You'll have to define code section that allows GOTO jumps.

Code: Select all

Macro SQ
  '
EndMacro ; ugly macro xD

Macro Label_(LABEL)
  !case SQ#LABEL#SQ:
EndMacro

Macro Goto_(LABEL)
  !GotoLabel=SQ#LABEL#SQ;continue RETURN_POINT;
EndMacro

Macro GotoBlock()
  !var GotoLabel='';RETURN_POINT:while(true){ switch(GotoLabel) { case '':
EndMacro
Macro EndGotoBlock()
  !default:break RETURN_POINT;}}
EndMacro

; *********************
; EXAMPLE 
; *********************

Procedure Test(a=1)
  GotoBlock()
  Label_(task1)     ;task1:
  Debug "task1 a="+a
  a+1
  If a<5
    Goto_(task1)    ;Goto task1
  Else 
    Goto_(task2)    ;Goto task2
  EndIf   
  
  Label_(task2)     ;task2:
  Debug "task2 a="+a
  a-1
  
  Label_(task3)     ;task3:
  Debug "task3 a="+a
  If a=0 : ProcedureReturn : EndIf 
  Goto_(task2)      ;Goto task2
  
  EndGotoBlock()
EndProcedure

Debug "Start"

GotoBlock()
  Goto_(LabelC) 
  
  Label_(LabelC)    ;LabelC:
  Debug "Execute C"
  
  Label_(LabelD)    ;LabelD:
  Debug "Execute D"
  Test()
  Goto_(LabelA)     ;Goto LabelA
  
  Label_(LabelA)    ;LabelA:
  Debug "Execute A"
  
  Label_(LabelB)    ;LabelB:
  Debug "Execute B"
EndGotoBlock()

Debug "Stop"
Second example with another keyword syntax

Code: Select all

; *********************
; EXAMPLE 2 
; *********************

Macro GotoJumps()
  GotoBlock()
EndMacro
Macro EndGotoJumps()
  EndGotoBlock()
EndMacro

Debug "Begin ..."

GotoJumps()
  Goto_(LabelB) 
  
  Label_(LabelA)    ;LabelA:
  Debug "Execute A"
  
  Label_(LabelB)    ;LabelB:
  Debug "Execute B"
EndGotoJumps()

Debug "In progress ..."

GotoJumps()
  Goto_(LabelD) 
  
  Label_(LabelC)    ;LabelC:
  Debug "Execute C"
  
  Label_(LabelD)    ;LabelD:
  Debug "Execute D"
EndGotoJumps()
  

Debug "Stop ..."
Post Reply