FAQ  •  Register  •  Login

Control codes

<<

rikokun

Posts: 13

Joined: Mon Apr 18, 2016 9:51 pm

Post Mon Apr 18, 2016 10:02 pm

Control codes

Hi
I'm new here, so excuse me if anyone asked this before. I tryed to search for it but didnt find anything.

So i'm playing with ZX basic for last week or so and i was doing some of my usual tests.
In one of them i was trying to print out a block of characters with random ink and color. And because making a loop that will print it character by character is rather slow, i tryed to be clever. It didn't work ^_^

So my problem:

i wanted to make a string variable with control codes that i would print out. And sure enough if i do

p$="\{i5}X"
print p$

it work just fine.


Problem is when i want to put some randomness to it and do something like

i$=str(int(rnd*7))
p$="\{i"+i$+"}X"
print p$

it outputs

\{i2}X

instead of colored X. In my mind, it should work...
Am i doing something wrong?

Also, implementing AT as \{ax,y} like it works in BASin would be nice ^_^

Thanks for your help
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Apr 20, 2016 3:45 pm

Re: Control codes

BASIN has its own codes. ZX BASIC is a compiler, so it tries to guess some (a few of them!) at compile time. NOT at runtime.
It's much faster if you use the ink code which is CHR(16) (Read here).
So instead of
  Code:
p$="{\i" + x$ + "}X"

use
  Code:
p$=CHR$(16) + i$ + "X";


Actually, CHR$ is optimized for several chars at once. So CHR$(x) + CHR$(y) + CHR$(z) + ... can be written as CHR$(x, y, z, ...). Example:
  Code:
p$ = CHR$(16, INT(RND * 7), CODE "X")

Give it a try. Also, in this case, you can ignore the INT( )... because CHR$ will take only INT args and do it for you.
Tell me is this work for you :roll:
<<

rikokun

Posts: 13

Joined: Mon Apr 18, 2016 9:51 pm

Post Wed Apr 20, 2016 4:48 pm

Re: Control codes

Thanks, that was really helpful. I guess i wasnt coding in speccy basic for quite some time, otherwise i woul'd realise.
Will give it a go.
<<

rikokun

Posts: 13

Joined: Mon Apr 18, 2016 9:51 pm

Post Wed Apr 20, 2016 6:29 pm

Re: Control codes

Ok it works.
Well what works i when i use
  Code:
x$ = chr(17) + str(p) + "O"
print x$

I also tryed to use chr(22) which is supposed to be at and it kinda works
there i actually use
  Code:
x$ = chr(22,5,5) + "O"
print x$

and yes, it prints on 6th row, but in the 1st column...

Probably doing something badly again...
Thanks for your help anyway, gotta figure out what to use this for now ^_^
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu Apr 21, 2016 1:51 pm

Re: Control codes

That might be a bug. I'll check it, but
CHR$(22, 5, 5) + "0" should be equivalent to PRINT AT 5, 5; "0"
<<

rikokun

Posts: 13

Joined: Mon Apr 18, 2016 9:51 pm

Post Fri Apr 22, 2016 5:43 pm

Re: Control codes

That would be awsome.
I downloaded the newest build (1.4.0s1967) and it still does that to me.
I often use thease to generate a block of "graphics" i can place on the screen fairly quickly ^_^
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Jun 15, 2016 9:32 pm

Re: Control codes

rikokun wrote:That would be awsome.
I downloaded the newest build (1.4.0s1967) and it still does that to me.
I often use thease to generate a block of "graphics" i can place on the screen fairly quickly ^_^

Okay, I think I fixed it. Download build (1.4.0s1968)
Note: I will discontinue support for .exe files, so try to download the .py version whenever possible.

Return to Help & Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO