Block (class)
Jump to navigation
Jump to search
This class provides fields/functions for managing Blocks in the current level.
Static functions
Static Block Functions (Level only) | ||
---|---|---|
Function | Return values | Description |
Block.count() | number | How many blocks are in the level. |
Block.get() | table of Block | Returns all blocks |
Block.get(number or table ids) | table of Block | Returns all blocks with the matching ids. Only the blocks with the same id given by ids will be returned. |
Block.getIntersecting(number x1, number y1, number x2, number y2) | table of Block | Returns all blocks which are intersecting with an area from x1/y1 to x2/y2. |
Block.iterateIntersecting(number x1, number y1, number x2, number y2) | function, table, number | Used to iterate through all blocks intersecting with an area from x1/y1 to x2/y2. Returns an iterator function, a table of args and the iterator index. Use it like shown: for k,b in Block.iterateIntersecting() do |
Block.spawn(number blockId, number x, number y) | Block | Spawns a new block. |
Block(number index) | Block | Returns the Block object at position index in the global Block table. Use this constructor with caution! Use Block.get or Block.getIntersecting instead!! (See above) |
Instance functions
These fields and functions are part of Block Objects and have to be called for that object. Trying to call them from the static Block class will result in an error. Example (feel free to copy it into your lua file to see how it works):
function onTick()
for index,myBlock in ipairs(Block.get()) do
myBlock.speedX = myBlock.speedX + 1
end
end
Block class | |||
---|---|---|---|
Type | Function/Field | Return values/Value type | Description |
function | Block:mem(int offset, int fieldtype, object value) | nil | Sets a value of the Block struct at a specific address-offset. |
function | Block:mem(int offset, int fieldtype) | object | Returns a value of the Block struct at a specific address-offset. |
function | Block:collidesWith(Player player) | int | Returns a number with the side of the collision. 0 = no collision, 1 = Player on top of block, 2 = Player touching right side, 3 = Player touching bottom, 4 = Player touching left side. |
function | Block:remove(boolean playEffectAndSound) | nil | Destroys/Removes a block. If playEffectAndSound is true, then the destroy sound and effect you normally only see in the level editor is played. (LunaLua ≥ v0.7.1) |
function | Block:remove() | nil | Same as Block:remove(false) (LunaLua ≥ v0.7.1) |
function | Block:hit(boolean fromUpperSide, Player player, number hittingCount) | nil | Simulates a hit on the block. If fromUpperSide is true, then the block will simulate a hit from the top side. The player argument is needed for blocks like the player-switch block. hittingCount is the number of repeating hits on the block (i.e. when toads hits the block). (LunaLua ≥ v0.7.2) |
function | Block:hit(boolean fromUpperSide, Player player) | nil | Simulates a hit on the block. If fromUpperSide is true, then the block will simulate a hit from the top side. The player argument is needed for blocks like the player-switch block. (LunaLua ≥ v0.7.1) |
function | Block:hit(boolean fromUpperSide) | nil | Same as Block:hit(fromUpperSide, Player(1)) (LunaLua ≥ v0.7.1) |
function | Block:hit() | nil | Same as Block:hit(false, Player(1)) (LunaLua ≥ v0.7.1) |
Field | Block.x | double | The x coordinate of the block. |
Field | Block.y | double | The y coordinate of the block. |
Field | Block.speedX | double | The x-speed of the block. |
Field | Block.speedY | double | The y-speed of the block. |
Field | Block.id | number | The block-id of the block. |
Field | Block.contentID | number | The contents of the block. 0-99 are coin values. 1XXX where XXX is the id of the npc. (i.e. 1099 is the npc with the id 99) (LunaLua ≥ v0.7.2) |
Field | Block.isHidden | boolean | Boolean flag if the block is invisible. |
Field | boolean | Boolean flag if the block is invisible. | |
Field | Block.slippery | boolean | Boolean flag if the block is slippery. |
Field (ro) | Block.layerName | VBStr | The layer name of the block. |
Field (ro) | Block.layerObj | Layer | The layer object of the block. |
Offsets
This is the memory map for the Block struct. This struct is not fully analysed. Any help is appreciated!
Please note that the data is probably not 100% accurate. We'd have to check if the structure SMBX Block+(memory) is actually represented that way in-game.
Block Memory | |||
---|---|---|---|
Name | Memory address | Memory type | Description |
SMBX Block+0x00 | 0x00 | FIELD_WORD | Makes block slippery |
SMBX Block+0x02 | 0x02 | FIELD_WORD | Unknown attribute in memory offset 02. |
SMBX Block+0x04 | 0x04 | FIELD_WORD | How many times the block gets hitted (i.e. when Toad hits the block) |
SMBX Block+0x06 | 0x06 | FIELD_WORD | Block type 2 |
SMBX Block+0x08 | 0x08 | FIELD_WORD | Content ID related |
SMBX Block+0x0A | 0x0A | FIELD_WORD | Unknown 0A |
SMBX Block+0x0C | 0x0C | VB6StrPtr | Event that triggers when block is hit. |
SMBX Block+0x10 | 0x10 | VB6StrPtr | Event that triggers when block is destroyed. |
SMBX Block+0x14 | 0x14 | VB6StrPtr | Event that triggers when there are no more objects in layer. |
SMBX Block+0x18 | 0x18 | VB6StrPtr | Name of the layer the block belongs to. |
SMBX Block+0x1C | 0x1C | FIELD_WORD | Block is hidden (Hidden layers or destroyed) |
SMBX Block+0x1E | 0x1E | FIELD_WORD | Registers block type. |
SMBX Block+0x20 | 0x20 | FIELD_DFLOAT | Current x-position |
SMBX Block+0x28 | 0x28 | FIELD_DFLOAT | Current y-position |
SMBX Block+0x30 | 0x30 | FIELD_DFLOAT | Height |
SMBX Block+0x38 | 0x38 | FIELD_DFLOAT | Width |
SMBX Block+0x40 | 0x40 | FIELD_DFLOAT | Current x-speed |
SMBX Block+0x48 | 0x48 | FIELD_DFLOAT | Current y-speed |
SMBX Block+0x50 | 0x50 | FIELD_WORD | Registers ID of block contents. |
SMBX Block+0x52 | 0x52 | FIELD_WORD | Counter for the first half of the bonk animation. Sum with 0x54 for the y offset of the bonk. |
SMBX Block+0x54 | 0x54 | FIELD_WORD | Counter for the second half of the bonk animation. Sum with 0x52 for the y offset of the bonk. |
SMBX Block+0x56 | 0x56 | FIELD_WORD | The y offset of the bonking animation. Should equal -(0x52 + 0x54). |
SMBX Block+0x58 | 0x58 | FIELD_WORD | -1 on the frame after a block has been bonked, but only when bonked by the player. |
SMBX Block+0x5A | 0x5A | FIELD_WORD | Block invisibility (Invisible flag from the editor - will reappear when hit from below) (0 when visible, -1 when not) |
SMBX Block+0x5C | 0x5C | FIELD_WORD | Unknown |
SMBX Block+0x5E | 0x5E | FIELD_WORD | Unknown |
SMBX Block+0x60 | 0x60 | FIELD_WORD | Unknown |
SMBX Block+0x62 | 0x62 | FIELD_WORD | Unknown |
SMBX Block+0x64 | 0x64 | FIELD_WORD | Unknown |
SMBX Block+0x64 | 0x66 | FIELD_WORD | Unknown |