Type Conversions (What!?)

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 852
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Type Conversions (What!?)

Post by Simon Knight » Sat Aug 01, 2020 8:47 am

I am confusing myself while reading the bytes of a raw image file. As part of my debug process it is useful to view what is being read from the file at any given position. At the moment I am just looking at data written in Little Endian byte order so have only shown that portion of my read routine. The handler is passed the byte positions of the target data in pLowByte and pHighByte which are the start and end bytes. The Boolean pIsLittle Endian identifies the byte order and pImageFile is a pointer to the datafile being read

Code: Select all

Function ReadDataWord pLowByte, pHighByte, pIsLittleEndian, @pImageFile
   put empty into tDataWord
   put 0 into tPwr
   If pIsLittleEndian  then
      put "Little Endian : " into tdebug
      Repeat with N = pLowByte to pHighByte
         put byteToNum(byte N of pImageFile) into tInt
         
         put baseConvert(tInt, 10, 16) into tTemp
         put tTemp and comma after tDebug
         
         add tInt*(16^tPwr) to tValue
         add 1 to tPwr
      end Repeat
   Else
The line
put byteToNum(byte N of pImageFile) into tInt
correctly populates the variable tInt and its value may be viewed by stopping the code in the debugger. The code converts the integer tInt to base 16 and the hex value is stored in tTemp. However, if I try to place either tInt or tTemp into the variable tDebug the word "false" is added. Again this is visible in the debugger.
Screenshot 2020-08-01 at 08.41.05.png
Screen Shot of debugger
Does Livecode have type conversions ? Any thoughts on what is happening ?
best wishes
Skids

Post Reply

Return to “Talking LiveCode”