? Vector2 (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Vector2

  • #1 ✎ 34 KHypno I want a way for ONE variable to have 2 values. (x and y) How do I do that? Posted
  • #2 ✎ 1069 snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements DIM VEC[2] VEC[0] = x VEC[1] = y Posted
  • #3 ✎ 1284 rando Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Second Year My account is over 2 years old Website Forum Leader Hidden Achievements
    DIM VEC[2] VEC[0] = x VEC[1] = y
    lol yes Is there another way?
    Posted
  • #4 ✎ 1848 12Me21 Power User Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself It's usually better to just use 2 variables though Posted Edited by 12Me21
  • #5 ✎ 453 MasterR3C0RD Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements Third Year My account is over 3 years old Website osu! Is Awesome! I love osu! Express Yourself If you're okay with only having 16 bits of information, you could probably use bit shifting VAR VEC2 = 0 ' To set values: X = 5 Y = 10 VEC = VEC AND ((X AND &HFFFF) << 16) AND (Y AND &HFFFF) ' To get values: VEC2X = VEC >> 16 AND &HFFFF VEC2Y = VEC AND &HFFFF (tihs might not work, I haven't used SB in a long time) Posted
  • #6 ✎ 246 Avery First Week Joined in the very first week of SmileBASIC Source Website Third Year My account is over 3 years old Website Disguised Hidden Website psst, this is what DEFY's TOPOINT() does though it's written kinda poorly at the moment. tell you what, I'll rewrite today Posted
  • #7 ✎ 246 Avery First Week Joined in the very first week of SmileBASIC Source Website Third Year My account is over 3 years old Website Disguised Hidden Website Here are the new POINT functions. COMMON DEF TOPOINT(X%,Y%) RETURN (X% AND &HFFFF) OR (Y% AND &HFFFF<<16) END COMMON DEF GETX(P%) RETURN P%<<16>>16 END COMMON DEF GETY(P%) RETURN P%>>16 END If you wanna have a laugh, look at how insanely long wrote the original functions in comparison. COMMON DEF TOPOINT(XI,YI) VAR X=XI VAR Y=YI VAR XS,YS,R,S IF !CLASSIFY(X) THEN X=CAP(ROUND(X),-&H7FFF,&H7FFF) XS=SGN(X)==-1 X=ABS(X) ELSE X=0:XS=1 ENDIF IF !CLASSIFY(Y) THEN Y=CAP(ROUND(Y),-&H7FFF,&H7FFF) YS=SGN(Y)==-1 Y=ABS(Y) ELSE Y=0:YS=1 ENDIF R=0 FOR S=0 TO 14 R=SETBIT(R,S,READBIT(X,S)) R=SETBIT(R,S+16,READBIT(Y,S)) NEXT R=SETBIT(R,15,XS) R=SETBIT(R,31,YS) RETURN R END COMMON DEF GETX(P) VAR X,XS,S X=0 FOR S=0 TO 14 X=SETBIT(X,S,READBIT(P,S)) NEXT XS=READBIT(P,15) IF XS THEN X=X*-1 IF XS AND !X THEN RETURN NAN() ELSE RETURN X ENDIF END COMMON DEF GETY(P) VAR Y,YS,S Y=0 FOR S=0 TO 14 Y=SETBIT(Y,S,READBIT(P,S+16)) NEXT YS=READBIT(P,31) IF YS THEN Y=Y*-1 IF YS AND !Y THEN RETURN NAN() ELSE RETURN Y ENDIF END Posted
  • #8 ✎ 34 KHypno
    DIM VEC[2] VEC[0] = x VEC[1] = y
    Ill use this
    Posted
  • #9 ✎ 34 KHypno
    If you're okay with only having 16 bits of information, you could probably use bit shifting VAR VEC2 = 0 ' To set values: X = 5 Y = 10 VEC = VEC AND ((X AND &HFFFF) << 16) AND (Y AND &HFFFF) ' To get values: VEC2X = VEC >> 16 AND &HFFFF VEC2Y = VEC AND &HFFFF (tihs might not work, I haven't used SB in a long time)
    what is bit shifting
    Posted
  • #10 ✎ 1284 rando Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Second Year My account is over 2 years old Website Forum Leader Hidden Achievements yeah I prefer data arrays DIM THISARR[377,582,562] (probably out of memory lol) Posted