Reading Binaries int8, int32 etc.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Bill
Posts: 45
Joined: Sat Apr 08, 2006 8:22 pm
Location: Colorado
Contact:

Reading Binaries int8, int32 etc.

Post by Bill » Sun May 20, 2018 5:13 am

Er..int16 not int8

Trying to extract data from Tim Phillip's Realmz.

How should I go about doing this?
This is the sequence of data in Data BD file, other files have other ranges.
The Mac OS Classic resources are a whole other beast to tackle.
169 is the number of entries.
I assume I read then as pos,dist,mystery,beforeBattle, afterBattleStringID, battleStringOD
but how? read from file for 16 int1 or 4 int 4?
  • int16[169] Position of monster in 13x13 grid.
    byte Distance from party
    byte ???
    int16 Before battle string id
    int16 After battle string id (Displayed when collecting treasure)
    int16 ???
Is the files are actually in Scenario folder of the game

This git has some details about the data

Thanks in advance.

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Reading Binaries int8, int32 etc.

Post by MaxV » Wed Dec 12, 2018 1:01 pm

  • Int8: 1 byte
  • Int16: 2 bytes
  • Int32 : 4 bytes
  • Int64 : 8 bytes
So just use bytetonum this way:

Code: Select all

put bytetonum(byte myByteposition of myData) #int8
put  256 * bytetonum(byte myByteposition of myData) +  bytetonum(byte (myByteposition - 1) of myData) # int16
put  256* 256* 256 * bytetonum(byte myByteposition of myData)  + 256* 256 * bytetonum(byte (myByteposition - 1) of myData) +  256 * bytetonum(byte (myByteposition - 2 ) of myData) +  ( byte (myByteposition - 3 ) of myData) # int32
# and so on..
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6242
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Reading Binaries int8, int32 etc.

Post by FourthWorld » Wed Dec 12, 2018 7:13 pm

FWIW "uint1", uint2", and "uint4" are valid chunk types that can be used with reading and writing files and parsing data. See those Dictionary entries for examples.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

MaxV
Posts: 1547
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Reading Binaries int8, int32 etc.

Post by MaxV » Fri Dec 14, 2018 5:24 pm

Uint in dictionary is not explained well. Please can yo write here what is it?
Is it int32 or 16 or else?
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6242
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Reading Binaries int8, int32 etc.

Post by FourthWorld » Fri Dec 14, 2018 10:59 pm

These are standard terms:
uint1 = 1 byte
uint2 = 2 bytes
unit4 - 4 bytes

To read 4 bytes from a file you could ask it for that:

Code: Select all

read from file tFile for 4 bytes
Or read as uint4:

Code: Select all

read from file tFile for 1 unit4
You may also find LiveCode's binaryDecode function useful.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”