LuaInvaders - Learning Lua with BlitzMax
BlitzMax Forums/BlitzMax Beginners Area/LuaInvaders - Learning Lua with BlitzMax
| ||
Hi All, After reading about Lua, I thought I would try to learn it with BlitzMax. I couldnt really find any real world examples to help me. So I thought I would put this here as sort of a community project and we can all learn together... LuaInvaders.bmx: alien_script.lua: As you can see, all my Lua script does is create 10 aliens... Could someone please show me how would I use Lua to move the 10 aliens around? I've uploaded the source/exe/images to here: http://therevills.syntaxbomb.com/LuaInvaders/ |
| ||
Heres an updated version... LuaInvaders.bmx: alien_script.lua: So now the aliens will follow the player coded via the Lua... Also if you alter the Lua file while the program is running, just hit F5 to refresh the script... |
| ||
Hi therevills, Don't think nobody's interested or listening. I'm very interested in adding lua scripting to my games, right now I haven't got the time to learn lua properly but I'll be following the progress here so please keep it up! Cheers Matt [ps - completely O.T. - I've been hunting for animation software and bumped into Munchies on the front page of the Pro Motion website - small world :) ] |
| ||
I'm interested, although i haven't really had time to experiment yet. enjoying reading this though :) Cheers Charlie |
| ||
Hi thervills this looks cool would you like to contribute this as an article in BlitzMaxCoder 0.2?![]() |
| ||
therevills: You probably don't want to use MaxLua, as you seem to be doing. You're not going to learn much about how to actually use Lua that way, and it's not exactly the best way to use Lua in the first place. You'd probably be better starting off with something simple that just exposes a handful of functions to the script that then do something or other in the game. |
| ||
@matibee & jkrankie: Thanks for the comments guys... @Merx: would you like to contribute this as an article in BlitzMaxCoder 0.2 It'll be a pretty small article, maybe for 0.3 or 0.4.... Im still learning about this stuff... BTW great first issue! @Nilium: don't want to use MaxLua Why? There seems to be a lot of Lua Modules for BlitzMax... it's not exactly the best way to use Lua in the first place What is? Could you take what Ive done and so me how you would do it? As I stated in the first post, I cant find any real world examples... You'd probably be better starting off with something simple that just exposes a handful of functions to the script that then do something or other in the game. Examples please? |
| ||
I'll see if I can refit it to how I'd do it (without any extra modules), since I haven't been able to find any tutorials that are still up illustrating it. (My own is gone, I don't remember why - probably a hissyfit I had years ago.) |
| ||
Righto, example. This does not use anything other than straight Lua functions. No dependency on MaxLua (it'd have proven to be much more restricting with it). I removed the TPlayer and TAlien types because they're not needed, the player and aliens are constructs of the script and not the host application. LuaInvaders.bmx: alien_script.lua: (edit: for some reason I wrote the wrong name for this earlier...) ![]() I also decided not to use your images, because I was too lazy to download them. |
| ||
And, for my own personal amusement, the LuGI version. There's really not a whole lot to wrap in this, so it feels small. But, there are less functions to wrap and you have direct access to fields, so it works out. LuaInvaders.bmx: alien_script.lua: |
| ||
Pretty darn cool! |
| ||
Now thats an example! Thanks a lot Nilium! Ill have to have a deeper look at the weekend... seems pretty full on just to get Lua to work with BlitzMax doing it your way... |
| ||
Edit: Rewritten now that I have internet access from my Mac again. The way I'd normally do this is I'll have all the rendering, sound, etc. - basically, the stuff that isn't really game logic - in the host application and the remaining game logic (e.g., UI, player movement, etc. - physics simulations would probably be part of the host application unless the physics stuff was really, really simple) will all be in Lua. You could shift the line in either direction with more being in Lua or BlitzMax, it's a personal choice in this case. My way, I feel I get a much more reusable body of code, since I don't have to tear out any of the game logic from the host application and can just start from scratch with a new set of scripts. That way the back-end is already there and I just have to decide what the game does. Essentially, the end result should be like an engine, and your game is just built on top of that. Like I said though, this is just how I'd do it. You're free to put as much code in the host/script as you want, since you're the only person who will probably know what you want in the first place. |
| ||
Bumping this one in light of Zekes recent Lua module release Looks like there is a some great learning material here |