Author Topic: Help  (Read 4230 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline qbkiller101

  • Newbie
  • Posts: 73
    • View Profile
Help
« on: April 01, 2020, 09:21:11 am »
Anybody, please help
when I run the following etch a sketch code it keeps on saying as in attachments
Code: QB64: [Select]
  1. REM Developed in QBasic by Omer B. Hijazi
  2. REM Date: 1/4/2020
  3. REM Etch a Sketch
  4.  
  5. DIM X, Y
  6.  
  7.  
  8.  
  9. LOCATE 6, 28: PRINT "Use arrow keys to draw"
  10. LOCATE 7, 28: PRINT "Home to move drawing point"
  11. LOCATE 8, 21: PRINT "Del(ete) button to clear the screen"
  12. LOCATE 9, 34: PRINT "End to end"
  13.  
  14. X = 319
  15. Y = 239
  16.  
  17. 1 CLS
  18.     Y = Y + 1
  19.     X = X - 1
  20.     Y = Y - 1
  21.     X = X + 1
  22.     CLS
  23.     GOTO 2
  24. PSET (X, Y)
  25.  
  26. 2 CLS
  27.     Y = Y + 1
  28.     X = X - 1
  29.     Y = Y - 1
  30.     X = X + 1
  31.     CLS
  32.     GOTO 1
  33. PRESET (X, Y)
  34.  
  35.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Help
« Reply #1 on: April 01, 2020, 09:30:52 am »
You need to set your screenmode for graphics.  Screen 0 (the default one) is text only.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline qbkiller101

  • Newbie
  • Posts: 73
    • View Profile
Re: Help
« Reply #2 on: April 01, 2020, 09:40:54 am »
ok I corrected it
Code: QB64: [Select]
  1. REM Developed in QBasic by Omer B. Hijazi
  2. REM Date: 1/4/2020
  3. REM Etch a Sketch
  4.  
  5. DIM X, Y
  6.  
  7.  
  8.  
  9.     COLOR 15
  10.     LOCATE 6, 28: PRINT "Use arrow keys to draw"
  11.     LOCATE 7, 28: PRINT "Home to move drawing point"
  12.     LOCATE 8, 21: PRINT "Del(ete) button to clear the screen"
  13.     LOCATE 9, 34: PRINT "End to end"
  14.     SLEEP
  15.     GOTO 1
  16.  
  17.     X = 319
  18.     Y = 239
  19.  
  20.     1 COLOR 1
  21.     IF _KEYDOWN(18432) = -1 THEN
  22.         Y = Y + 1
  23.     ELSEIF _KEYDOWN(19200) = -1 THEN
  24.         X = X - 1
  25.     ELSEIF _KEYDOWN(20480) = -1 THEN
  26.         Y = Y - 1
  27.     ELSEIF _KEYDOWN(19712) = -1 THEN
  28.         X = X + 1
  29.     ELSEIF _KEYDOWN(21248) = -1 THEN
  30.         CLS
  31.     ELSEIF _KEYDOWN(18176) = -1 THEN
  32.         GOTO 2
  33.     END IF
  34.     PSET (X, Y)
  35.     GOTO 1
  36.  
  37.     2 CLS
  38.     IF _KEYDOWN(18432) = -1 THEN
  39.         Y = Y + 1
  40.     ELSEIF _KEYDOWN(19200) = -1 THEN
  41.         X = X - 1
  42.     ELSEIF _KEYDOWN(20480) = -1 THEN
  43.         Y = Y - 1
  44.     ELSEIF _KEYDOWN(19712) = -1 THEN
  45.         X = X + 1
  46.     ELSEIF _KEYDOWN(21248) = -1 THEN
  47.         CLS
  48.     ELSEIF _KEYDOWN(18176) = -1 THEN
  49.         GOTO 1
  50.     END IF
  51.     PRESET (X, Y)
  52.     GOTO 2
  53. LOOP UNTIL _KEYDOWN(20224) = -1
still not drawing
just correct the code using simple programming as I'm no pro

Marked as best answer by qbkiller101 on April 02, 2020, 08:30:56 am

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Help
« Reply #3 on: April 01, 2020, 11:25:26 am »
Try do this easiest way.


Code: [Select]
REM Developed in QBasic by Omer B. Hijazi
REM Date: 1/4/2020
REM Etch a Sketch

SCREEN 12
COLOR 15
X = _WIDTH / 2
Y = _HEIGHT / 2

DO

    LOCATE 6, 28: PRINT "Use arrow keys to draw"
    LOCATE 7, 28: PRINT "Home to move drawing point"
    LOCATE 8, 21: PRINT "Del(ete) button to clear the screen"
    LOCATE 9, 34: PRINT "End to end"


    k& = _KEYHIT
    SELECT CASE k&
        CASE 18432: Y = Y - 1
        CASE 19200: X = X - 1
        CASE 20480: Y = Y + 1
        CASE 19712: X = X + 1
        CASE 21248: CLS
        CASE 18176: SYSTEM
    END SELECT
    PSET (X, Y)
    SELECT CASE X
        CASE IS <= 0: X = 1
        CASE IS >= _WIDTH: X = _WIDTH
    END SELECT
    SELECT CASE Y
        CASE IS <= 0: Y = 1
        CASE IS >= _HEIGHT: Y = _HEIGHT
    END SELECT
LOOP UNTIL _KEYDOWN(20224) = -1
SYSTEM

or this, using _KEYDOWN + support pressing direction arrows simultaneously for oblique drawing (up and left arrow can be used simultaneously and so on):

Code: [Select]
REM Developed in QBasic by Omer B. Hijazi
REM Date: 1/4/2020
REM Etch a Sketch

SCREEN 12
COLOR 15
X = _WIDTH / 2
Y = _HEIGHT / 2

DO

    LOCATE 6, 28: PRINT "Use arrow keys to draw"
    LOCATE 7, 28: PRINT "Home to move drawing point"
    LOCATE 8, 21: PRINT "Del(ete) button to clear the screen"
    LOCATE 9, 34: PRINT "End to end"

    _LIMIT 20
    IF _KEYDOWN(18432) AND NOT _KEYDOWN(19200) THEN Y = Y - 1
    IF _KEYDOWN(19200) AND NOT _KEYDOWN(18432) THEN X = X - 1
    IF _KEYDOWN(19200) AND _KEYDOWN(18432) THEN Y = Y - 1: X = X - 1

    IF _KEYDOWN(20480) AND NOT _KEYDOWN(19712) THEN Y = Y + 1
    IF _KEYDOWN(19712) AND NOT _KEYDOWN(20480) THEN X = X + 1
    IF _KEYDOWN(19712) AND _KEYDOWN(20480) THEN Y = Y + 1: X = X + 1


    SELECT CASE _KEYHIT
        CASE 21248: CLS
        CASE 18176: SYSTEM
    END SELECT
    PSET (X, Y)
    SELECT CASE X
        CASE IS <= 0: X = 1
        CASE IS >= _WIDTH: X = _WIDTH
    END SELECT
    SELECT CASE Y
        CASE IS <= 0: Y = 1
        CASE IS >= _HEIGHT: Y = _HEIGHT
    END SELECT
LOOP UNTIL _KEYDOWN(20224) = -1
SYSTEM

« Last Edit: April 01, 2020, 11:45:25 am by Petr »

Offline qbkiller101

  • Newbie
  • Posts: 73
    • View Profile
Re: Help
« Reply #4 on: April 02, 2020, 04:41:54 am »
thanks but what about my code what was wrong with it
and btw plz add the home button for moving the drawing point
example:
Code: QB64: [Select]
  1. 2 IF _KEYDOWN(18432) = -1 THEN
  2.     Y = Y + 1
  3. ELSEIF _KEYDOWN(19200) = -1 THEN
  4.     X = X - 1
  5. ELSEIF _KEYDOWN(20480) = -1 THEN
  6.     Y = Y - 1
  7. ELSEIF _KEYDOWN(19712) = -1 THEN
  8.     X = X + 1
  9. ELSEIF _KEYDOWN(21248) = -1 THEN
  10.     CLS
  11. ELSEIF _KEYDOWN(18176) = -1 THEN
  12.     GOTO 1
  13. ELSEIF _KEYDOWN(20224) = -1 THEN
  14.     SYSTEM
  15. PRESET (X, Y)
by using preset for drawing in no color

Offline qbkiller101

  • Newbie
  • Posts: 73
    • View Profile
Re: Help
« Reply #5 on: April 02, 2020, 06:03:22 am »
ok no need I've done it
here take a look
(you've gotta press slightly and quickly the home key)
Code: QB64: [Select]
  1. REM Developed in QBasic by Omer B. Hijazi (aka qbkiller101) : https://www.qb64.org/forum/index.php?action=profile;u=525
  2. REM Mostly because of help from Petr : https://www.qb64.org/forum/index.php?action=profile;u=7
  3. REM Date: 1/4/2020
  4. REM Etch a Sketch
  5.  
  6. DIM X, Y
  7.  
  8. X = _WIDTH / 2
  9. Y = _HEIGHT / 2
  10.  
  11. LOCATE 6, 28: PRINT "Use arrow keys to draw"
  12. LOCATE 7, 28: PRINT "Home to move drawing point or erase"
  13. LOCATE 8, 21: PRINT "Del(ete) button to clear the screen"
  14. LOCATE 9, 34: PRINT "End to end"
  15.     _LIMIT 20
  16.    1 DO
  17.  
  18.         _LIMIT 20
  19.         IF _KEYDOWN(18432) AND NOT _KEYDOWN(19200) THEN Y = Y - 1
  20.         IF _KEYDOWN(19200) AND NOT _KEYDOWN(18432) THEN X = X - 1
  21.         IF _KEYDOWN(19200) AND _KEYDOWN(18432) THEN Y = Y - 1: X = X - 1
  22.  
  23.         IF _KEYDOWN(20480) AND NOT _KEYDOWN(19712) THEN Y = Y + 1
  24.         IF _KEYDOWN(19712) AND NOT _KEYDOWN(20480) THEN X = X + 1
  25.         IF _KEYDOWN(19712) AND _KEYDOWN(20480) THEN Y = Y + 1: X = X + 1
  26.  
  27.         SELECT CASE _KEYHIT
  28.             CASE 21248: CLS
  29.         END SELECT
  30.         PSET (X, Y)
  31.         SELECT CASE X
  32.             CASE IS <= 0: X = 1
  33.             CASE IS >= _WIDTH: X = _WIDTH
  34.         END SELECT
  35.         SELECT CASE Y
  36.             CASE IS <= 0: Y = 1
  37.             CASE IS >= _HEIGHT: Y = _HEIGHT
  38.         END SELECT
  39.  
  40.     LOOP UNTIL _KEYDOWN(18176) = -1
  41.     IF _KEYDOWN(20224) = -1 THEN SYSTEM ELSE GOTO 2
  42.    2 DO
  43.         _LIMIT 20
  44.         IF _KEYDOWN(18432) AND NOT _KEYDOWN(19200) THEN Y = Y - 1
  45.         IF _KEYDOWN(19200) AND NOT _KEYDOWN(18432) THEN X = X - 1
  46.         IF _KEYDOWN(19200) AND _KEYDOWN(18432) THEN Y = Y - 1: X = X - 1
  47.  
  48.         IF _KEYDOWN(20480) AND NOT _KEYDOWN(19712) THEN Y = Y + 1
  49.         IF _KEYDOWN(19712) AND NOT _KEYDOWN(20480) THEN X = X + 1
  50.         IF _KEYDOWN(19712) AND _KEYDOWN(20480) THEN Y = Y + 1: X = X + 1
  51.  
  52.         SELECT CASE _KEYHIT
  53.             CASE 21248: CLS
  54.         END SELECT
  55.         PRESET (X, Y)
  56.         SELECT CASE X
  57.             CASE IS <= 0: X = 1
  58.             CASE IS >= _WIDTH: X = _WIDTH
  59.         END SELECT
  60.         SELECT CASE Y
  61.             CASE IS <= 0: Y = 1
  62.             CASE IS >= _HEIGHT: Y = _HEIGHT
  63.         END SELECT
  64.  
  65.     LOOP UNTIL _KEYDOWN(18176) = -1 OR _KEYDOWN(20224) = -1
  66.     IF _KEYDOWN(20224) = -1 THEN SYSTEM ELSE GOTO 1
  67. LOOP UNTIL _KEYDOWN(20224) = -1
plus I've added credits to you:-)

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Help
« Reply #6 on: April 02, 2020, 07:21:01 am »
This is pretty cool. I like the home key no draw function, except that I can't really tell where my insertion point is. Never had that on the original etch-a-sketch.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Help
« Reply #7 on: April 02, 2020, 07:42:43 am »
An Etch-A-Sketch watch has been around for decades.

Might be the perfect tool to write/display "Will you marry me?" for a geek.
It works better if you plug it in.

Offline qbkiller101

  • Newbie
  • Posts: 73
    • View Profile
Re: Help
« Reply #8 on: April 02, 2020, 12:31:26 pm »
Spoiler Alert:
I've never actually used an etch a sketch

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Help
« Reply #9 on: April 02, 2020, 12:41:39 pm »
Hi killer,

Are you aware of the DRAW command? you might find it interesting. It's like a very fancy Etch-A-Sketch with code.
« Last Edit: April 02, 2020, 12:42:48 pm by bplus »