Why can't I pass multiple arguments to a DEF subroutine/function
Root / Programming Questions / [.]
_Nyap_Created:
I'm not using GOSUB functions because they can't take any arguments at all in the first place, plz correct me if im wrong
Here's the code I'm having trouble with:
'---WINDOW HANDLER--- DEF MAKEWINDOW(XSIZE,YSIZE,PROGID) PROGRAMSXY[PROGID,0]=199 PROGRAMSXY[PROGID,1]=119 FOR E=119 TO 139 STEP 1 GLINE 199,E,199+XSIZE,E NEXT END '---TEST PROGRAM--- DEF TEST(ID) MAKEWINDOW(100,100,ID) ENDNote: this is just a snippet of the program, not the entire program. There's a syntax error on line 107 (the call to MAKEWINDOW), and removing the last 2 arguments fixes it. Any suggestions?
The way you define the function changes how it is supposed to be called:
variable=FUNC(args) FUNC2 args DEF FUNC(args) 'do something with the arguments RETURN something END DEF FUNC2 args 'do something with the arguments ENDThis means you'll want this code instead:
'---WINDOW HANDLER--- DEF MAKEWINDOW XSIZE,YSIZE,PROGID PROGRAMSXY[PROGID,0]=199 PROGRAMSXY[PROGID,1]=119 FOR E=119 TO 139 STEP 1 GLINE 199,E,199+XSIZE,E NEXT END '---TEST PROGRAM--- DEF TEST ID MAKEWINDOW 100,100,ID END
So if I use brackets it goes on the stack, and without brackets it doesn't?Well it's not a stack/heap issue. If you use parenthesis, it internally wants a return value. If you don't, it doesn't expect a return value. So
DEF FUNC(A,B,C) 'this will want a RETURN at the end of the block DEF FUNC A,B,C 'this is essentially a subroutineIt would be the same (in C#/Java) as doing:
public object func(a,b,c) //requires a return value...type doesn't matter public void func(a,b,c) //no return value
is that still one of the differences tho?Honestly I'm not sure. SB is a mainly interpreted language, so concepts like the stack and heap have much less to do with the programming aspect of the language. You could have concepts like the heap that are managed on the stack, and vice versa. I don't even worry about what's going on behind the hood when it comes to interpreted languages like SB.