Jump to content

Print variable contents


Recommended Posts



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.






I am pleased to report that it worked like a charm. Of course I have had to use <>#y and  <>#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"


MODE 0,2,0,0,0






   #BACKTAB(c)=$0007 + 3 * 8


   #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





Edited by Alkadian
Link to comment
Share on other sites

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



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. ;)




  • Like 1
Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...