Page 1 of 1

Reading Binaries int8, int32 etc.

Posted: Sun May 20, 2018 5:13 am
by Bill
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.

Re: Reading Binaries int8, int32 etc.

Posted: Wed Dec 12, 2018 1:01 pm
by MaxV
  • 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..

Re: Reading Binaries int8, int32 etc.

Posted: Wed Dec 12, 2018 7:13 pm
by FourthWorld
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.

Re: Reading Binaries int8, int32 etc.

Posted: Fri Dec 14, 2018 5:24 pm
by MaxV
Uint in dictionary is not explained well. Please can yo write here what is it?
Is it int32 or 16 or else?

Re: Reading Binaries int8, int32 etc.

Posted: Fri Dec 14, 2018 10:59 pm
by FourthWorld
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.