Page 1 of 5

Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 1:34 pm
by Matteo
Hi! I'm new in SmartBASIC, I'd like to know if I can programmatically switch from GRAPHICS output to Text output. Example: in the source file "color pixels.txt" (default Examples folder inside the App) we find the GRAPHICS output call at the beginning; when I stop the execution of the program touching the square key in top left of the screen the program stops, all right, but if I add the code PRINT "hello" at last row:

Code: Select all

REM 'color pixels.txt' source file:

GRAPHICS
maxx = SCREEN_W....
...
GOTO LOOP

' added:
PRINT "hello"
after the stop of the execution I can't see the text output in the screen.
Can you help me about this?
Thanks!
Matteo

Re: Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 1:41 pm
by Mr. Kibernetik
You can do it with command TEXT

Re: Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 3:25 pm
by Matteo
Hi, sorry I can't understand your solution, that is if I write the code:

Code: Select all

REM 'color pixels.txt' source file:

GRAPHICS
maxx = SCREEN_W....
...
LOOP:
...
GOTO LOOP

' added:
TEXT
PRINT "hello"
run it and then stop it (due to infinite loop), I can't see the text output.
What I wrong?
Thanks
Regards
Matteo

Re: Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 3:34 pm
by sarossell
smart BASIC runs commands sequentially. You'll have to exit your loop for the interpreter to move on to your print command.

Code: Select all

Loop:
IF {condition} THEN BREAK
GOTO Loop

Re: Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 5:54 pm
by Matteo
hi, thanks for reply but again I can't run my training code:

Code: Select all


GRAPHICS
maxx = SCREEN_WIDTH() * SCREEN_SCALE()
maxy = SCREEN_HEIGHT() * SCREEN_SCALE()

a=1
b=0


LOOP:

IF a>1000 THEN
TEXT
PRINT b
BREAK

ENDIF

var1=RND(maxx)
var2=RND(maxy)

DRAW PIXEL var1, var2 COLOR RND(1), RND(1), RND(1)
IF var1<10 AND var2<10 THEN 
b=b+1

ENDIF 


a=a+1
GOTO LOOP

I have BREAK without cycle error. Some help?
Thanks
Matteo

Re: Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 6:04 pm
by sarossell
Ooh, sorry. BREAK is for DO/UNTIL, FOR/NEXT, or WHILE/WEND loops, not imposed GOTO loops. Try this:

Code: Select all

GRAPHICS
maxx = SCREEN_WIDTH() * SCREEN_SCALE()
maxy = SCREEN_HEIGHT() * SCREEN_SCALE()
a=1
b=0
DO
  var1=RND(maxx)
  var2=RND(maxy)
  DRAW PIXEL var1, var2 COLOR RND(1), RND(1), RND(1)
  IF var1<10 AND var2<10 THEN 
    b=b+1
  ENDIF 
a=a+1
UNTIL a>1000
PAUSE 3
TEXT
PRINT b

Re: Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 7:44 pm
by Matteo
Excellent, it works now, so I could try to program a button on the screen that switches from text to graph and viceversa to see results of a general computation (graphical and text values) in real time. Do you know if with Smart Basic user can program a button that exists in both graphic and text output and that can be touched to see graphics or text, until touching the square STOP key in top left of SmartBasic screen app?
Thanks!
Matteo

Re: Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 7:52 pm
by sarossell
I'm probably one of the least qualified people on this forum to help you with programming, but your questions make me think and look things up and I think I might have the answer. Besides, I'm a firm believer of Cunningham's Law "The best way to get the right answer on the Internet is not to ask a question, it's to post the wrong answer."

I believe you might best be served by staying in graphics mode and using the DRAW TEXT command to print on the same screen. That way, you can have switches and other graphical elements along with textual information. If you feel strongly about being able to switch between screens, you could then switch between pages using the PAGE commands.

Re: Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 8:57 pm
by Matteo
Thanks very much for your reply! I will try to write , with your hints, a default source code for my calculations and simulations projects able to show both graphical and textual (numbers and texts) results during execution, without stopping the code execution when I want to see a numeric value while seeing the graph of the calculation.
Thanks again for help.
Regards
Matteo

Re: Switch from GRAPHICS to Text Output

Posted: Thu Jan 19, 2017 11:40 pm
by sarossell
Happy to help any time I can Matteo. I'm sure we'd all love to see your results once you get it worked out. :)