Alkadian Posted September 24 Share Posted September 24 (edited) Hi, I am starting a new thread following my previous post, hoping that it could be help somebody else in future: Below the advice given by @DZ-Jay: ----------------------------------------------------------------------------------------------------------- 8 hours ago, Alkadian said: I have a question, if I may. Would it be possible to use the PRINT function to print the contents of a variable? Something like: PRINT AT 7 COLOR 6, "Contents of variable y" Thanks so much! You guys are a treasure here! Of course! Just follow it with a comma and the variable: PRINT AT ScreenPos(7, 0) COLOR CS_YELLOW, "Contents of variable y:", y Just bear in mind that it will treat all variables as if they were characters and try to convert them to a GROM or GRAM card. If you want IntyBASIC to interpret the variable as a number -- essentially converting it to a decimal numeric string -- you need to use the "<>" directive, as described in the IntyBASIC manual: PRINT <>expr ' Simple number PRINT <const>expr ' Right-aligned with zeroes to 'const' size. PRINT <.const>expr ' Right-aligned with spaces to 'const' size. So, for your example above, if "y" is numeric, you can use: PRINT AT ScreenPos(7, 0) COLOR CS_YELLOW, "Contents of variable y:", <>y For scores and such which typically have a specific field size, prefixed with zeroes or spaces, you use one of the other two variations: ' Print score in a four-digit string, with leading zeros PRINT AT ScreenPos(12, 0) COLOR CS_RED, "P1:", <4>score What happens if you forget the "<>" modifier? The contents of the variable will be interpreted as a card number, multiplied by 8, and indexed into either GRAM or GROM, wherever it may appear to point. In other words, the arguments to PRINT AT after the position are used to compose a BACKTAB card data word, for instance: ' The following: ' PRINT AT ScreenPos(7) COLOR CS_YELLOW, "Contents of variable y:", y ' is the same as: #Backtab(7) = CS_YELLOW + (y * 8) So ... be careful with that. -dZ. ------------------------------------------------------------------------------------ I am pleased to report that it worked like a charm. Of course I have had to use <>#y and <>#x in my specific case, as pointed out by @artrag x and y are16-bit variables! Below the code which I have used for testing: INCLUDE "constants.bas" CLS MODE 0,2,0,0,0 WAIT c=0 loop: WAIT #BACKTAB(c)=$0007 + 3 * 8 #x=#BACKTAB(c) #y=(#x and $07F8) / 8 #BACKTAB(#y+1)=$0007 + 4 * 8 PRINT AT ScreenPos(20, 0) COLOR CS_YELLOW, "Contents of variable y:", <>#y PRINT AT ScreenPos(60, 0) COLOR CS_YELLOW, "Contents of variable x:", <>#x GOTO loop Thanks! Edited September 24 by Alkadian Quote Link to comment Share on other sites More sharing options...
+DZ-Jay Posted September 24 Share Posted September 24 Good job! As for the variable prefixes, just remember that in IntyBASIC, you can have an 8-bit variable and a 16-bit variable, both with the same name; and the compiler will tell them apart by the "#" symbol. This means that you can have something like the following: Dim SomeName Dim #SomeName SomeName = 1 #SomeName = 2 Print "SomeName: ", <>SomeName Print "#SomeName: ", <>#SomeName That code will produce the following output: SomeName: 1 #SomeName: 2 Also, to some extent, the same applies to labels, like those used for data tables, "Goto" targets, or procedure names -- their names must be unique among other labels, but they can coincide with variable names. In other words, a procedure named "SomeName" will not clash with an 8-bit variable of the same name, so your code can look like this: Dim SomeName Dim #SomeName Gosub SomeName SomeName: Procedure Print "8-Bit: ", <>SomeName Print "16-Bit: ", <>#SomeName End Now, the fact that the compiler allows this does not mean it is a good idea to do it. It is always recommended that you aim for clarity and avoid ambiguity. -dZ. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.