#1✎ 34KHypnoI want a way for ONE variable to have 2 values. (x and y)
How do I do that?
Posted
#2✎ 1130snail_Power UserQSP Contest 1 Contest ParticipantI participated in the first SmileBASIC Source QSP Contest!HelperReceived for being very helpful around SmileBASIC SourceAchievementsAmazing ContributorSomeone thinks I'm an awesome person who has done so much for the community!AchievementsDIM VEC[2]
VEC[0] = x
VEC[1] = y
Posted
#3✎ 1546randoIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthSecond YearMy account is over 2 years oldWebsiteAvatar TabooI didn't change my avatar for 180 daysWebsite
DIM VEC[2]
VEC[0] = x
VEC[1] = y
lol yes
Is there another way?
Posted
#4✎ 188412Me21Syntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express YourselfIt's usually better to just use 2 variables though
Posted
Edited
by 12Me21
#5✎ 481MasterR3C0RDPower UserAmazing ContributorSomeone thinks I'm an awesome person who has done so much for the community!AchievementsThird YearMy account is over 3 years oldWebsiteosu! Is Awesome!I love osu!Express YourselfIf 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✎ 246AveryFirst WeekJoined in the very first week of SmileBASIC SourceWebsiteThird YearMy account is over 3 years oldWebsiteDisguisedHiddenWebsitepsst, 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✎ 246AveryFirst WeekJoined in the very first week of SmileBASIC SourceWebsiteThird YearMy account is over 3 years oldWebsiteDisguisedHiddenWebsiteHere 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
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✎ 1546randoIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthSecond YearMy account is over 2 years oldWebsiteAvatar TabooI didn't change my avatar for 180 daysWebsiteyeah I prefer data arrays
DIM THISARR[377,582,562]
(probably out of memory lol)
Posted