Hi there stranger and thank you for looking at this
I am trying to use memblocks. I use Tier 1. If I set an INT in mem with SetMemblockInt I don't get the same INT when reading it back with GetMemblockInt, however, if I use the same code but with SetMemblockByte and GetMemblockByte instead I do get the same value when reading back as when I set it. Strange :-P
Something similar, I have some editors made in DBPro. I write longs to file, which is 4 bytes integers, I can't read them as 4 bytes integers in AGK2, BUT I can however create a memblock, read each byte from a 4 byte integer/long into a memblock and THEN retrieve a 4 byte integer correctly in AGK2.
EDIT: I don't think it is a bug, there must be an error elsewhere in my code.
EDIT 2: Changing the last SetMemblockInt(14,b,pre_read_tile_10) and tile = GetMemblockInt(14,m) to SetMemblockByte(14,b,pre_read_tile_10) and tile = GetMemblockByte(14,m) WILL give me the right integer tile number
EDIT 3: I have been writing across boundaries, I think :-P With SetMemblockShort and GetMemblockShort it works, and it fits with 2 bytes for X and Y, 2 bytes for tile number, not trying to write across boundaries
Here is some code:
//some read map, storing tile numbers in a memblock
If GetMemblockExists(13) Then DeleteMemblock(13)
CreateMemblock(13,screen_update_memblock_size)
n = 0
for layer = 7 to 14
For x = 1 to work_map_info[1]
for y = 1 to work_map_info[2]
SetMemblockInt(13,n,work_map[x,y,layer])
inc n,4
next y
next x
next layer
//A memblock used for storing tiles that should be rendered after player. This is the memblock that does not read back proper.
If GetMemblockExists(14) Then DeleteMemblock(14)
CreateMemblock(14,4000)
//reading integer tile number back in screen update, so far the value is still correct
if layer = 10
pre_read_tile_10 = GetMemblockInt(13,n)
inc n,4
EndIf
//store the tile to be rendered after character
if player_y + 128 < update_map_grid_y * 128
if layer = 10 and pre_read_tile_10 > 99 and layer_10_render_after_character_already_handled = 0
//render_after_character[update_map_grid_x,update_map_grid_y,1,1] = update_map_grid_x
//render_after_character[update_map_grid_x,update_map_grid_y,1,2] = update_map_grid_y
//render_after_character[update_map_grid_x,update_map_grid_y,1,3] = pre_read_tile_10
SetMemblockByte(14,b,update_map_grid_x)
Inc b
SetMemblockByte(14,b,update_map_grid_y)
Inc b
SetMemblockInt(14,b,pre_read_tile_10)
inc b,4
endif
//Here, it does not read back correct values for tile :-(
if end_of_render_after_character_memblock > 0
m = 0
while m < end_of_render_after_character_memblock
x = GetMemblockByte(14,m)
inc m
y = GetMemblockByte(14,m)
inc m
tile = GetMemblockInt(14,m)
store_tile = tile
inc m,4
SetSpriteImage(2,tile)
SetSpriteSize(2,-1,-1)
SetSpritePosition(2,x * 128 - 128,y * 128 - 128)
DrawSprite(2)
endwhile
EndIf
13/0