Lua scripting in Verge
Displaying 1-5 of 5 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Overkill

Okay, so about a year ago Verge got released with a relatively undocumented option to use Lua scripting instead of VC code.

This means that Verge suddenly got a big boost, and can do a bunch of very powerful stuff that couldn't be done with regular Verge so easily. Lua is much more expressive and flexible, to the point that old style Verge code is kind of awkward to write in Lua.

So I wrote a library that handles a lot of the raw Verge tasks in a nice friendly manner. I called it "vx", which is a "Verge eXtension"

If interested, you can read about how to setup vx here: http://www.bananattack.com/vx/

I highly recommend giving it a shot if you're starting a new project with Verge, or want to make something a little more maintainable!

Me and ustor both find vx very handy. Once you get over the initial hurdle of adjusting, it's actually much much faster to pump out code. Just thought I'd let everyone know!

Posted on 2008-12-06 03:41:20 (last edited on 2008-12-06 03:41:58)

Kildorf

Thanks for releasing and posting about this Overkill.

Seriously, anyone who has found themselves frustrated with limitations in VergeC should really try out Lua. I haven't used vx yet because I'm pigheaded and stupid, but the lesson here is to not be like Kildorf! Go try it out. I've been using Lua for Geas and it's much nicer to write in.

To whet your appetite, since Overkill was kind of vague about what benefits Lua offers over VC, here's a quick list of a few things that Lua gives you:


  • Numbers of any precision (i.e. floats)

  • Object oriented programming

  • Real dictionaries (they're called tables)

  • A faster scripting engine

  • Lots of other cool stuff



I'm not sure if Overkill mentions this on his site anywhere, but if you want to go learn Lua they have quite a lot of documentation over at the official site: http://www.lua.org.

Posted on 2008-12-07 11:38:01

Overkill

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.

Posted on 2008-12-07 13:00:04 (last edited on 2008-12-07 13:20:28)

Overkill

I've now updated the vx website to use better wiki software, and now as a result, anybody can edit this!

http://www.bananattack.com/vx/

And here's a tutorial on some basic coding concepts in Lua: http://www.bananattack.com/vx/Learn_Lua

Posted on 2008-12-17 19:57:54 (last edited on 2008-12-17 21:17:47)

Overkill

Whoooooops. I just realized. After I updated the wiki, I moved vx to the wrong folder, so nobody could download it. That was bad. :D

...It should work now! http://www.bananattack.com/vx/vx.zip

EDIT: Actually now, this time.

Posted on 2008-12-22 16:27:16 (last edited on 2008-12-23 00:02:38)


Displaying 1-5 of 5 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.