? Def codes for making codes (Page 2) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Def codes for making codes

1 2 3 4
  • #21 ✎ 266 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength I made a multi sprite entity creation, deletion, and rendering group of DEFs and I'd chuck them into a spoiler here but they are far from complete, a bit messy, and need performance enhancement. Posted
  • #22 ✎ 1550 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website
    CHKPROJECT: Check if the project named P$ exists. ... This is probably the simplest way to do this check, but it's the most effective. If you give it a name that can't possibly be a valid project name it'll just tell you false, anyway.
    It's probably not a good idea to accept [SYS] and [DEFAULT] since none of the other file commands do.
    Posted
  • #23 ✎ 85 dfrost2 Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Minecraft Is Awesome! I love Minecraft! Express Yourself Here is one: DEF GET(ARRAY, OFFSET) DIM TEMP[3] COPY TEMP, 0, ARRAY, OFFSET,1 RETURN TEMP[0] END this command can get any element of an array regardless of size, number of dimensions, (and maybe type) I'm pretty sure that it's a type mismatch this could REALLY be useful in making a TYPEOF() function Posted Edited by dfrost2
  • #24 ✎ 85 dfrost2 Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Minecraft Is Awesome! I love Minecraft! Express Yourself May not see why it's useful. get()(once updated) can determine the type of array(string/number) by getting the first element. Posted
  • #25 ✎ 154 Warrior Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies ...What’s the point? Can’t you just do ? ARRAY[ELEMENT] Posted
  • #26 ✎ 85 dfrost2 Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Minecraft Is Awesome! I love Minecraft! Express Yourself No, that won't work. doing this: DIM A[20, 20] ?A[20] Syntax error Posted
  • #27 ✎ 1550 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website
    May not see why it's useful. get()(once updated) can determine the type of array(string/number) by getting the first element.
    How are you going to get the first element if you don't know the type already? You can't use COPY since you have to know the type when creating the temporary array.
    Posted
  • #28 ✎ 884 Y_ack Head Admin It seemed like dfrost was going to run the first (!!) element of the input array through their 67% accuracy typeof command to make a destination array of the correct type... Posted
  • #29 ✎ 154 Warrior Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    No, that won't work. doing this: DIM A[20, 20] ?A[20] Syntax error
    Its not that hard to just use correct syntax. ?ARRAY[ELEMENT,ELEMENT]
    Posted
  • #30 ✎ 1550 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website
    No, that won't work. doing this: DIM A[20, 20] ?A[20] Syntax error
    Its not that hard to just use correct syntax. ?ARRAY[ELEMENT,ELEMENT]
    I think the idea is that you can use GET if you don't know how many dimensions the array has.
    Posted
  • #31 ✎ 85 dfrost2 Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Minecraft Is Awesome! I love Minecraft! Express Yourself maybe I can copy it to a string array... you can "stringize" numbers so that they can fit into it While I'm at I might as well post this: DEF TOSTRING(X) IF X*0&&X*0==X*0 THEN RETURN X RETURN STR$(X) END Posted
  • #32 ✎ 266 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength DEF DESTROY_ARR A[] FOR I%=LEN(A[])-1 TO 0 STEP -1 TRASH%=POP(A[]) NEXT END This is a simple function which removes all elements from a single-dimension array. The FOR loop is "backwards" to help improve program speed when worked with large arrays in complex loops. Posted
  • #33 ✎ 165 Nathaniel Spring 2017 Contest Winner I won the SmileBASIC Source Spring 2017 Contest! Programming Contest Staff Pick "Your program is one of our favorites!" - Staff Achievements Helper Received for being very helpful around SmileBASIC Source Achievements
    DEF DESTROY_ARR A[] FOR I%=LEN(A[])-1 TO 0 STEP -1 TRASH%=POP(A[]) NEXT END This is a simple function which removes all elements from a single-dimension array. The FOR loop is "backwards" to help improve program speed when worked with large arrays in complex loops.
    Here's a slightly simpler version: DEF DESTORY_ARR A WHILE LEN(A) IF POP(A) THEN ENDIF WEND END
    Posted
  • #34 ✎ 266 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Yeah that one's better. Posted
  • #35 ✎ 86 Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies Yes, these are a bit higher-level functions, but considering all the debugging you'll go though to implement 32-bit-sensitive algorithms, I just saved you weeks of debugging. Took me a year and a half to figure this out in SmileBASIC. 'BOUND A NUMBER INTO 32 BITS (FROM -2147483648 TO 2147483647) DEF BOUND(N) WHILE N>2147483647 N=N-4294967296 WEND WHILE N<-2147483648 N=N+4294967296 WEND RETURN N END 'USING >> WILL ADD 1S TO THE LEFT SIDE OF NEGATIVE NUMBERS (WHICH TAKES FOREVER TO DEBUG) 'ZERO-FILLING RIGHT SHIFT, AKA THE >>> OPERATOR IN JAVASCRIPT DEF U_RSHIFT(A,B) A=BOUND(A) IF A<0 THEN A=A>>1 AND 2147483647 OR &H40000000 RETURN A>>B-1 ELSE RETURN A>>B END 'FINALLY A BITWISE ROTATION SHIFT IN SMILEBASIC! DEF ROTR32(A,B) A=BOUND(A) RETURN U_RSHIFT(A,B) OR A<<32-B END The leftmost bit of every number determines if its positive (0) or negative (1). So when you do bit operations on negative numbers, the results go crazy spawning a bunch of ones on the left side, this helps you manage that leftmost bit to make use of the full 32 bits. In most situations, negative inputs now return positive outputs (as expected), unless if another one fills up the left bit. Posted
  • #36 ✎ 93 niconii Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies I didn't realize SmileBASIC actually uses saturating math when going from floats to integers, so it was more difficult than expected, but I managed to improve the above functions a bit: VAR I32=2147483648 VAR U32=4294967296 DEF BOUND(N) RETURN N-FLOOR((N+I32)/U32)*U32 END DEF U_RSHIFT(A,B) A=BOUND(A) RETURN A>>B AND NOT (-1<<32-B) END 'Unchanged from original DEF ROTR32(A,B) A=BOUND(A) RETURN U_RSHIFT(A,B) OR A<<32-B END I think personally I'd stick to using integer variables as much as possible, and have BOUND(A) be something explicitly done when passing numbers in only when needed, rather than have it always be run in U_RSHIFT and ROTR32, but that's just my personal taste. Posted Edited by niconii
  • #37 ✎ 1550 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website
    DEF DESTROY_ARR A[] FOR I%=LEN(A[])-1 TO 0 STEP -1 TRASH%=POP(A[]) NEXT END This is a simple function which removes all elements from a single-dimension array. The FOR loop is "backwards" to help improve program speed when worked with large arrays in complex loops.
    Here's a slightly simpler version: DEF DESTORY_ARR A WHILE LEN(A) IF POP(A) THEN ENDIF WEND END
    Or you could just do this: DEF FREE() DIM NEW[0] RETURN NEW END FREE OUT ARRAY 'or ARRAY=FREE() The garbage collector will free the memory occupied by the array once there are no variables that point to it. Keep in mind that this can change the type of the array so if you want to use the array again you'll need different FREE functions for each type.
    Posted Edited by 12Me21
  • #38 ✎ 85 dfrost2 Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Minecraft Is Awesome! I love Minecraft! Express Yourself Here is a bunch of random code: DEF VOID A: END DEF BLANKARRAY() DIM A[0] RETURN A END DIM BLANKARRAY$() DIM A$[0] RETURN A$ DEF GET(ARRAY, INDEX) DIM TEMP[3] COPY TEMP,ARRAY,INDEX,1 RETURN TEMP[0] END DEF SET ARRAY, INDEX,VALUE FILL ARRAY,VALUE,INDEX,1 END DEF ForEach ARRAY, FUNCTION VAR I,L = LEN(ARRAY) - 1 FOR I = 0 TO L CALL FUNCTION, GET(ARRAY,I),I NEXT END DEF INCARR ARRAY, ITEM, INDEX, STEP SET ARRAY, INDEX,INDEX*STEP END Do you know what this means? a new ARYOP function for FREE Posted
  • #39 ✎ 266 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength
    Here is a bunch of random code: DEF VOID A: END DEF BLANKARRAY() DIM A[0] RETURN A END DIM BLANKARRAY$() DIM A$[0] RETURN A$ DEF GET(ARRAY, INDEX) DIM TEMP[3] COPY TEMP,ARRAY,INDEX,1 RETURN TEMP[0] END DEF SET ARRAY, INDEX,VALUE FILL ARRAY,VALUE,INDEX,1 END DEF ForEach ARRAY, FUNCTION VAR I,L = LEN(ARRAY) - 1 FOR I = 0 TO L CALL FUNCTION, GET(ARRAY,I),I NEXT END DEF INCARR ARRAY, ITEM, INDEX, STEP SET ARRAY, INDEX,INDEX*STEP END Do you know what this means? a new ARYOP function for FREE
    But with less speed.
    Or you could just do this: DEF FREE() DIM NEW[0] RETURN NEW END FREE OUT ARRAY 'or ARRAY=FREE() The garbage collector will free the memory occupied by the array once there are no variables that point to it. Keep in mind that this can change the type of the array so if you want to use the array again you'll need different FREE functions for each type.
    In my case that's perfect. I've only needed to clear numerical arrays so far.
    Posted
  • #40 ✎ 85 dfrost2 Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Minecraft Is Awesome! I love Minecraft! Express Yourself i know there has to be a way to create faster graphics(like a custom GPU). How come none of us compile our knowledge into the same project? Posted
1 2 3 4