Control codes - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16) +---- Thread: Control codes (/showthread.php?tid=731) |
Control codes - rikokun - 04-18-2016 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 Re: Control codes - boriel - 04-20-2016 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" 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") Tell me is this work for you :roll: Re: Control codes - rikokun - 04-20-2016 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. Re: Control codes - rikokun - 04-20-2016 Ok it works. Well what works i when i use Code: x$ = chr(17) + str(p) + "O" there i actually use Code: x$ = chr(22,5,5) + "O" Probably doing something badly again... Thanks for your help anyway, gotta figure out what to use this for now ^_^ Re: Control codes - boriel - 04-21-2016 That might be a bug. I'll check it, but CHR$(22, 5, 5) + "0" should be equivalent to PRINT AT 5, 5; "0" Re: Control codes - rikokun - 04-22-2016 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 ^_^ Re: Control codes - boriel - 06-15-2016 rikokun Wrote:That would be awsome.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. |