QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: zigzag on June 18, 2018, 10:33:40 am

Title: What is the point of DRAW "x" and PLAY "x" ?
Post by: zigzag on June 18, 2018, 10:33:40 am
Both QBasic, and QB64, accept any string with the DRAW or PLAY command. So, what is the point of:

Code: QB64: [Select]
  1. DRAW "x"+VARPTR$(A$)

when one can just use

Code: QB64: [Select]
  1. DRAW A$

that is much clearer?
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: FellippeHeitor on June 18, 2018, 10:55:52 am
Retrocompatibility with GWBASIC.
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: zigzag on June 18, 2018, 11:35:37 am
Gwbasic, too, allowed the simpler syntax. And the use of x was different,  since it was followed by the variable's name
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: FellippeHeitor on June 18, 2018, 11:47:08 am
I don't know then.
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: bplus on June 18, 2018, 11:53:36 am
Hi zigzag, welcome to forum!

Now you got me curious: http://qb64.org/wiki/VARPTR$ ' <<< the $ is not picked up in link sorry...

"X" + VARPTR$(value) can draw another substring.

Here is sample from Wiki:
Code: QB64: [Select]
  1.  
  2. WIND$ = "r10 d7 l10 u7 br20"   'create draw string to be read by function
  3. ROW$ = "x"+VARPTR$(WIND$)+"x"+VARPTR$(WIND$)+"x"+VARPTR$(WIND$)+" x"+VARPTR$(WIND$)+"bl80 bd11"
  4. LINE (100, 50)-(200, 160), , B
  5. DRAW "bm 115,52"
  6. FOR I = 1 TO 10
  7.     DRAW "x" + VARPTR$(ROW$)
  8.  

It looks to be a way to repeat drawing.
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: FellippeHeitor on June 18, 2018, 12:02:37 pm
Truth is I always used STR$() for numeric variables and the variable itself for strings, even back in QBasic days. VARPTR has always been a mystery to me.
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: bplus on June 18, 2018, 12:10:42 pm
Yep! This does same:
Code: QB64: [Select]
  1. WIND$ = "r10 d7 l10 u7 br20" 'create draw string to be read by function
  2. ROW$ = WIND$ + WIND$ + WIND$ + WIND$ + "bl80 bd11"
  3. LINE (100, 50)-(200, 160), , B
  4. DRAW "bm 115,52"
  5. FOR I = 1 TO 10
  6.     DRAW ROW$
  7.  
Thus,
Draw "X" + varptr$(var) 
is waste of time, don't use it. ;D

Ha! neither use screen 2! come join the brave new world with _NewImage
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: bplus on June 18, 2018, 12:19:06 pm
But then again wiki has another example:
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: bplus on June 18, 2018, 12:23:06 pm
But then again, that sample doesn't even work without throwing an error!

So it looks like you have to be careful moving with negative values.
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: zigzag on June 18, 2018, 03:09:09 pm
Interesting. I see no one knows what was the purpose of the x command. Unfortunately, QBASIC guide is not clear, and many people believed it was necessary to use that weird syntax. But actually, on older versions of Microsoft Basic, there is a clue: on MSX Basic (that is pretty similar to GWBasic), the x command was supposed to be used like:

Quote
DRAW "xa$;"

https://www.msx.org/wiki/DRAW (https://www.msx.org/wiki/DRAW)

It made no sense at all neither in GWBasic, nor in QBASIC... but after more than 30 years it's still here, because too many people don't know there is no need for it
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: FellippeHeitor on June 18, 2018, 04:50:10 pm
So at some point BASIC did allow a variable name to be embedded inside a string, so it does make sense that VARPTR would have to be used later, when doing the same was no longer allowed, so that you could still point to an existing variable (though, even back then, it would still probably have been easier to just concatenate the strings, but who knows?).
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: bplus on June 18, 2018, 05:55:05 pm
So zigzag,

Are you presently engaged in any projects using Draw string$. I ask because I have a version in JB I've been meaning to translate to QB64. Last I looked, it had some interesting features like 3 digit RGB for 1000 colors, a Repeat function so you don't have to say string$ + string$ +... 10 times just R10String$, circle and circle fill, box and box fill that could do boxes at angles and a built in variable you could reset and increment. Everything letter and then digits, syntaxically, I think even decimals worked.
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: zigzag on June 18, 2018, 06:01:41 pm
Currently, no, I have a project that might involve PLAY, instead. Can I see that version of Draw you are talking about?
Title: Re: What is the point of DRAW "x" and PLAY "x" ?
Post by: bplus on June 18, 2018, 06:08:32 pm
Walter's forum called The QB64 Edition:
http://qb64.thejoyfulprogrammer.com/showthread.php?tid=1334&pid=7079&rndtime=15293594621619392457#pid7079