Switch from GRAPHICS to Text Output

Matteo
Posts: 16
Joined: Thu Jan 19, 2017 1:14 pm
My devices: iPhone 5S
Flag: Italy

Switch from GRAPHICS to Text Output

Post 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

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Switch from GRAPHICS to Text Output

Post by Mr. Kibernetik »

You can do it with command TEXT

Matteo
Posts: 16
Joined: Thu Jan 19, 2017 1:14 pm
My devices: iPhone 5S
Flag: Italy

Re: Switch from GRAPHICS to Text Output

Post 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

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Switch from GRAPHICS to Text Output

Post 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
smart BASIC Rocks!

- Scott : San Diego, California

Matteo
Posts: 16
Joined: Thu Jan 19, 2017 1:14 pm
My devices: iPhone 5S
Flag: Italy

Re: Switch from GRAPHICS to Text Output

Post 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

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Switch from GRAPHICS to Text Output

Post 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
smart BASIC Rocks!

- Scott : San Diego, California

Matteo
Posts: 16
Joined: Thu Jan 19, 2017 1:14 pm
My devices: iPhone 5S
Flag: Italy

Re: Switch from GRAPHICS to Text Output

Post 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

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Switch from GRAPHICS to Text Output

Post 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.
smart BASIC Rocks!

- Scott : San Diego, California

Matteo
Posts: 16
Joined: Thu Jan 19, 2017 1:14 pm
My devices: iPhone 5S
Flag: Italy

Re: Switch from GRAPHICS to Text Output

Post 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

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Switch from GRAPHICS to Text Output

Post 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. :)
smart BASIC Rocks!

- Scott : San Diego, California

Post Reply