? How to dim in an instruction out of an instruction (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

How to dim in an instruction out of an instruction

  • #1 ✎ 695 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Video Games I like to play video games! Hobbies 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! Posted
  • #2 ✎ 695 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Video Games I like to play video games! Hobbies Also, while we're talking about user instructions, is there a way to make some arguments optional like in alot of sb codes? Posted
  • #3 ✎ 1756 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself 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 Posted Edited by 12Me21
  • #4 ✎ 695 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Video Games I like to play video games! Hobbies
    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.
    Posted Edited by random_god
  • #5 ✎ 695 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Video Games I like to play video games! Hobbies 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 Posted Edited by random_god
  • #6 ✎ 1756 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself You have to set the values of all the OUT variables Posted
  • #7 ✎ 695 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Video Games I like to play video games! Hobbies
    You have to set the values of all the OUT variables
    Ok thanks
    Posted
  • #8 ✎ 695 random_god Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Video Games I like to play video games! Hobbies It works now! Thanks! Posted