Page 1 of 1

Goto And Gosub Instructions Don't work With Me

Posted: Wed May 27, 2015 5:27 pm
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:

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

Posted: Wed May 27, 2015 6:12 pm
by Peter
it seems that Goto und Gosub are not implemented.

Greetings ... Peter

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

Posted: Thu May 28, 2015 6:27 pm
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

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

Posted: Sat May 30, 2015 11:20 am
by SinisterSoft
They need a way of faking labels as I don't think they are available in javascript.

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

Posted: Sat May 30, 2015 1:58 pm
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 ..."