Page 1 of 47

LunaLua Offical Thread - SMBX Usermod Framework

Posted: Mon Dec 01, 2014 7:57 am
by Kevsoft
LunaLua documentation: https://wohlsoft.ru/pgewiki/Category:LunaLua_API



I recently had the idea if I should stream some LunaLua live development. Just say if you would be interested or not.

Because I get often ask where you can download LunaLua, I make a own topic about it.

LunaLua is a addition to lunadll which adds the script language lua. The problem with Autocode (the lunadll-language) is the lack of flexibility that it has (such as the way it lacks custom functions, variables,... etc). With this we don't need any hardcoded code for complex ideas anymore.

So first of all: What is lua?
Lua is an actual script language, which supports custom functions, variables and much more. The script type is something like JavaScript + Visual Basic



Download
Most recent Documentation
Source Code
LunaDLL for lua reference & example page (outdated since v0.2.7, but the examples still working)
LunaLua Tutorial
You might want to google other lua tutorials too.

How to install:
1. Check "Full Installation", check all checkboxes and download the most recent package.
2. Extract the package and profit!

How to update:
1. Check "Only Update" and replace the LuaScriptLib and lunadll.dll in your existing installation.

Example to see if LunaLua is working:
Spoiler: show

Code: Select all

function onLoop()
  printText("PLAYER x="..tostring(player.x).." y="..tostring(player.y), 30, 60)
end
Video Showcase:
Spoiler: show




Which lua-libs can I access?

Code: Select all

string.*
math.*
table.*
debug.*
os.* --Limited (only time/date works), because of security reasons
Reference to the lua libs:
string.*
math.*
table.*
debug.* (probably not needed)
os.* Note: Only os.clock, os.time and os.date works. The rest is limited due security reasons.

Re: LunaLua - Lunadll with lua

Posted: Mon Dec 01, 2014 8:56 am
by h2643
Cool, I hope this awesomeness will be stickied! You could add into the post some example videos, which were posted at PGE forum too, that would be better in my opinion ;)

Re: LunaLua - Lunadll with lua

Posted: Mon Dec 01, 2014 9:08 am
by Kevsoft
Updated my main post with some videos, so people can see what you can do with it.

Re: LunaLua - Lunadll with lua

Posted: Sat Dec 06, 2014 1:18 pm
by Destiny
So, apparently, LunaLua isn't working for me. I saved this test code in a lunaworld file (obviously in .lua format) but nothing happens. I still need a new exe or something?

EDIT: Yeah, I still need a new exe.
Spoiler: show
Image

Re: LunaLua - Lunadll with lua

Posted: Sat Dec 06, 2014 2:51 pm
by francot514
This will be work without need of new code into the main program?? becuase as i know there is no lua support in sbmx...

Re: LunaLua - Lunadll with lua

Posted: Sat Dec 06, 2014 5:02 pm
by Kevsoft
Sorry if you guys missed that: Yes you need the modded exe file! The modded exe

Re: LunaLua - Lunadll with lua

Posted: Sun Dec 21, 2014 3:42 am
by Kevsoft
v0.4 BETA is out.

Please read if you are an api-developer:
Spoiler: show
registerEvent has changed: The first argument has to be the api-table itself and not the api-string anymore!!!!

Code: Select all

registerEvent(table thisTable, string internalEventName, string functionToCall, boolean callBeforeMain)
This change is necessary to make a unique instance of a API.
In Addition for both api-developers and normal users:
Spoiler: show
* loadAPI is no longer using 'require'. I've writte my own loading function.
It will search in following paths for an API:
"{SMBXPath}\LuaScriptsLib\{apiName}.lua"
"{SMBXEpisodePath}\{apiName.lua}"
"{SMBXEpisodePath}\{CustomLevelFolder}\{apiName}.lua"
* loadSharedAPI added: Loads or gets (if already loaded) a shared instance of an API. (lunaworld.lua and lunadll.lua will reference the same API memory)
* hud(boolean displayHud) add: Toggle hud display on/off
Because there are lot of code changes I mark this version as "BETA". If there are any problems then please let me know!

Re: LunaLua - Lunadll with lua

Posted: Tue Dec 23, 2014 6:37 pm
by Wohlstand
SnifitGuy wrote:Could you possibly make an updated reference page? I know it may sound stupid, but I just don't want to have to go searching everywhere for new kinds of codes. Also, I tried using this code to display text, but it won't work. Any help?
Code:
Spoiler: show
function onLoop()
printText("This is a test", 3, 30, 30)
end
You also can check the Wiki page with latest LunaLUA references:
http://engine.wohlnet.ru/pgewiki/Category:LunaLua_API

Re: LunaLua - Lunadll with lua

Posted: Tue Dec 23, 2014 7:54 pm
by Wohlstand
SnifitGuy, quick question:
1) did you saved as "lunadll.lua" file in your custom dir of level?
2) did you correctly installed LunaLUA?

Re: LunaLua - Lunadll with lua

Posted: Thu Dec 25, 2014 4:37 pm
by Wohlstand
SnifitGuy wrote:
Wohlstand wrote:SnifitGuy, quick question:
1) did you saved as "lunadll.lua" file in your custom dir of level?
2) did you correctly installed LunaLUA?
1) It's LunaDLL with Lua, yes? That's the zip I have.
2) I put all the contents of the zip (the folder and two Dll files) in C:\SMBX
Do you got hexed SMBX's exe file which linked with LunaDLL?

Re: LunaLua - Lunadll with lua

Posted: Fri Dec 26, 2014 2:17 am
by Kevsoft
Try to run Autocode (aka. lunadll.txt with some debug code) first. Because when it is executing then it is a issue on my side. Also please check if you have a folder in your main dir called "LuaScriptsLib".

Re: LunaLua - Lunadll with lua

Posted: Fri Dec 26, 2014 7:47 am
by Kevsoft
I have a idea: Provide me a screenshot of your custom folder with the lunadll.lua inside.

Re: LunaLua - Lunadll with lua

Posted: Sat Dec 27, 2014 5:01 am
by Kevsoft

Image

LunaLua is now v0.5 BETA. We can now run code in the overworld YAY!
To run your code for the overworld make a file called "lunaoverworld.lua" in your episode dir.

Following events can be used for the world:
Spoiler: show
* onLoad
* onLoop
Following functions can be used for the world:
Spoiler: show
* windowDebug
* printText
* loadImage
* placeSprite
* mem
Classes are not supported yet!

A small Q&A to that:
Spoiler: show
Q: Can we run Autocode (lunadll.txt).
A: No you can only run lua code.

Q: Could you implement Autocode for overworld?
A: I could, but it would take way too long time. If kil does it then I am fine.

Q: Can we deactivate the world HUD?
A: No (maybe later), but the render code is the last painting code which is called. So you can overdraw everything if you want to.

Q: Why BETA?
A: There might be some bugs floating. If you have any issues please report them to me!

Re: LunaLua - Lunadll with lua

Posted: Sat Dec 27, 2014 6:54 am
by DarkShadeX
i fu****g love you kevy!

Re: LunaLua - Lunadll with lua

Posted: Sat Dec 27, 2014 8:17 am
by Kevsoft
DarkShadeX wrote:i fu****g love you kevy!
Hehe, thanks :P

I also updated the package with a small hotfix towards loadImage.

Re: LunaLua - Lunadll with lua [Now with Overworld]

Posted: Sat Dec 27, 2014 11:24 am
by Kevsoft
I am currently trying to fix a bug where the overworld is crashing when lunaoverworld.lua is missing. I'll release a new version soon!

Okay: Just fixed the small bug. Just download the same ZIP and overwrite the LunaDll.dll file.

Re: LunaLua - Lunadll with lua [Now with Overworld]

Posted: Sun Dec 28, 2014 5:23 am
by UberAndrew
Man, this is really looking amazing.

If this was included with SMBX 1.3.2 and there were in depth tutorials, this could really revitalize SMBX.

Re: LunaLua - Lunadll with lua [Now with Overworld]

Posted: Tue Dec 30, 2014 8:29 am
by Kevsoft
And here is the first LunaLua update for the overworld adding now the world class!
Example Code:
Spoiler: show

Code: Select all

function onLoop()
	local output = ""
	if world.playerIsCurrentWalking then
		output = output .. "Running "
	else
		output = output .. "Looking "
	end
	
	if world.playerCurrentDirection == ODIR_UP then
		output = output .. "Up"
	elseif world.playerCurrentDirection == ODIR_LEFT then
		output = output .. "Left"
	elseif world.playerCurrentDirection == ODIR_DOWN then
		output = output .. "Down"
	elseif world.playerCurrentDirection == ODIR_RIGHT then
		output = output .. "Right"
	end
	
	printText(output, 10, 10)
	if world.levelTitle then
		printText("Current Level: "..world.levelTitle.str, 10, 30)
	end
end
Changes for LunaLua 0.5.2:
Spoiler: show
* Added world class with following functions and properties:
** field double world.playerX
** field double world.playerY
** field int world.playerWalkingDirection
** field int world.playerWalkingTimer
** field int world.playerWalkingFrame
** field int world.playerWalkingFrameTimer
** field boolean world.playerIsCurrentlyWalking
** field nil or VBStr world.levelTitle
** function mem
Documentation will be updated soon!

Re: LunaLua - Lunadll with lua [Now with Overworld]

Posted: Tue Dec 30, 2014 9:30 am
by DarkShadeX
The code above doesnt work.

Re: LunaLua - Lunadll with lua [Now with Overworld]

Posted: Tue Dec 30, 2014 11:29 am
by Kevsoft
What doesn't work?
Do you get any errors?