LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

How to dim in an instruction out of an instruction

Root / Programming Questions / [.]

randoCreated:
I am making a code library and want to make a data array in a user defined instruction but have it useable outside of it. Is there a way I can do this? Is it like defs where I could go common dim arr[i,1000] or is there some other way? I would like to know how I can do this if I can. Thank you!

Also, while we're talking about user instructions, is there a way to make some arguments optional like in alot of sb codes?

Just make a function that returns the array Slot 0:
USE 1
DIM A[0]
A=EXAMPLE(3)
Slot 1:
COMMON DEF EXAMPLE(I)
 DIM ARRAY[I,1000]
 RETURN ARRAY
END
Unfortunately there's no COMMON DIM/VAR (Though, this might be a good thing, otherwise OPTION STRICT wouldn't work) but you can also use VAR() to access variables in other slots: Slot 0:
USE 1
PRINT VAR("1:TEST") '3
VAR("1:TEST")=10
PRINT VAR("1:TEST") '10
Slot 1:
VAR TEST=3

Just make a function that returns the array Slot 0:
USE 1
DIM A[0]
A=EXAMPLE(3)
Slot 1:
COMMON DEF EXAMPLE(I)
 DIM ARRAY[I,1000]
 RETURN ARRAY
END
Unfortunately there's no COMMON DIM/VAR (Though, this might be a good thing, otherwise OPTION STRICT wouldn't work) but you can also use VAR() to access variables in other slots: Slot 0:
USE 1
PRINT VAR("1:TEST") '3
VAR("1:TEST")=10
PRINT VAR("1:TEST") '10
Slot 1:
VAR TEST=3
WOW can't believe I didn't think of return values. Thanks.

I need help on a rainbow color changing code. It says UNINITIALIZED VARIABLE USED but I don't see how. Here is my code:
WHILE BUTTON(2)!=16
 VSYNC
 RAINBOW A,C,D OUT R,G,B
 A=R
 C=G
 D=B
WEND
Here is my def:
COMMON DEF RAINBOW A,C,D OUT R,G,B
 VAR MODE=0
 IF A>254 THEN MODE=1
 IF D<1 AND MODE==1 THEN MODE=2
 IF C>254 AND MODE==2 THEN MODE=3
 IF A<1 AND MODE==3 THEN MODE=4
 IF D>254 AND MODE==4 THEN MODE=5
 IF C<1 AND MODE==5 THEN MODE=0
 IF MODE==0 THEN R=A+1
 IF MODE==1 THEN B=D-1
 IF MODE==2 THEN G=C+1
 IF MODE==3 THEN R=A-1
 IF MODE==4 THEN B=D+1
 IF MODE==5 THEN G=C-1
END

You have to set the values of all the OUT variables

You have to set the values of all the OUT variables
Ok thanks

It works now! Thanks!