One of the coolest and weirdest things about Lua, is that almost everything uses tables, with a ton of variety.
Let's say you make a table representing player info:
player = { hp = 5; name = "Bob"; }
You can also write this in a different manner:
player = { hp = 5; name = "Bob"};
When you wanna get something out of the player, you can go like this:
print(player["hp"]) -- prints "5"
But this is exactly the same, and looks like you're poking at a struct:
print(player.hp) -- prints "5"
You can also create array-like things:
stuff = { 1, 2, 3 }
And use them like this:
print(stuff[1]) -- prints "1" Unlike VC index 1 actually means the first thing.
There's also some funky stuff with functions in tables being able to be treated as if it's object-oriented code. vx uses this to great effect, and quite frankly it's very useful in keeping code tidy and organized.
For instance, here's a silly example of drawing images with vx.
local image = vx.Image("hero.png")
local image2 = vx.Image(image) -- Copies the image
local image3 = vx.Image(50, 50) -- Creates a 50x50 image
-- All image primitives like rectangles and circles
-- affect whatever image the method is being invoked in.
image3:RectFill(0, 0, image3.width, image3.height, vx.RGB(255, 0, 0))
while true do
-- Draws an image at (5, 5) on the screen
image:Blit(5, 5)
-- Draws but this time with dest provided
image2:Blit(30, 30, vx.screen)
-- Blits an image to screen with rotation and scaling!
image3:RotateScaleBlit(100, 30, vx.clock.systemtime, math.sin(math.rad(vx.clock.systemtime)) * 0.5 + 1)
vx.ShowPage()
end
(Notice that the method calls on an image have a colon in front of it, this is how Lua does object-oriented stuff with tables.)
Oh yeah, and a fun fact you'll find very handy! vx is garbage collected! If any image/font/sound/song/socket handle is no longer used it'll be auto-freed without any issues.
So gone are the days of accidentally forgetting to free a resource you don't need anymore, or accidentally freeing it one times too many and causing your game to whine at you.