(shouting)

LunaLua Offical Thread

The second SMBX collab!
Post Reply

Shall I stream some LunaLua live development?

Yes
23
92%
No
2
8%
 
Total votes: 25

User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

LunaLua Offical Thread

Post by Kevsoft »

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

Heya all, I'm here to present Lunadll with Lua (Alpha-Version)!
I used most of the last week to work on this, and I think it's turning out pretty well. 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). Kil is currently developing his own language, when he provides me the source code I would merge it together with this lua part. 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 and Tutorials
Source Code
LunaDLL for lua reference & example page (outdated since v0.2.7)
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.

Examples are provided in the reference page.

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.
Last edited by Kevsoft 8 years ago, edited 64 times in total.
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Update 0.2.1:

* Added section class
* Added direct memory editing
User avatar
Darkonius64
Dreams of a forgotten reality
Posts: 134
Joined: 10 years ago
Pronouns: he/him/his

Re: Presenting: Lunadll for Lua!

Post by Darkonius64 »

A friend of mine, the same that made the Luna.txt help program, has been experimenting with this, he made a fully working dino rhino torch thingy, and added a double jump to yoshi!
:bi_pride:
Image
My latest SMBX episode
https://talkhaus.raocow.com/viewtopic.p ... 70#p473070

My media links:
Twitter: https://twitter.com/Darkonius64

Support my indie game Dormiveglia!
https://dormivegliagame.com/
User avatar
Willhart
Stalker, Doxxer, and Sexual Harasser
Banned
Posts: 2434
Joined: 13 years ago
Location: Finland

Re: Presenting: Lunadll for Lua!

Post by Willhart »

Darkonius64 wrote:A friend of mine, the same that made the Luna.txt help program, has been experimenting with this, he made a fully working dino rhino torch thingy, and added a double jump to yoshi!
This sounds pretty awesome. Would it be possible to change the player jumping/running physics to SMW ones with the help of this thing?
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Technical yes, but I am not sure how SMBX handels modified physics. Anyway, I added a "onJump" event and a "onJumpEnd" event in the next version (will release soon)
Rixithechao
https://www.youtube.com/watch?v=BODxOghVmko
Posts: 1812
Joined: 10 years ago
First name: Mack
https://rixithechao.talkhaus.com/

Re: Presenting: Lunadll for Lua!

Post by Rixithechao »

Man, I'm not really that familiar with Lua but I just had to try something with this thing! So I drafted up a basic cutscene framework. Currently it just has timed subtitles and NPC talking animations, but based on that reference document I have a few ideas for other potentially useful features...

Code: Select all

dialogSpeaker = 0

dialogTextTime = 0
dialogSpeakerTime = 0

dialogName = ""
dialogText = ""

-- Can the player press the key to skip the current line?
dialogSkippable = true

-- Does the dialogue halt the cutscene timing?
dialogPause = true

-- Does the player have to press a key to continue?
dialogEndWithInput = true

-- Can the entire cutscene be skipped?
cutsceneSkippable = true

-- Current cutscene time in frames
cutsceneFrame = 0


-- Constants
NPCID_DEMO = 101
NPCID_IRIS = 102
NPCID_KOOD = 103




function onLoad()
  dialogSpeaker = 0
  
  dialogTextTime = 0
  dialogSpeakerTime = 0
  
  dialogName = ""
  dialogText = ""
  
  dialogSkippable = true
  dialogPause = true
  dialogEndWithInput = true
  
  cutsceneFrame = 0

  setDialogRules(true, true, true)
end




function onLoop()
  -- Trigger sequenced cutscene events
  processCutscene()

  -- Control specific NPC talking/idle animations
  processNPCTalkAnim(NPCID_DEMO, 0, 3, 4, 7)
  processNPCTalkAnim(NPCID_IRIS, 0, 0, 1, 4)
  processNPCTalkAnim(NPCID_KOOD, 0, 15, 16, 19)

  -- Control dialogue display
  processDialogue()
end


function processCutscene()
  if(dialogPause == false  or  dialogTextTime <= 0)then
    cutsceneFrame = cutsceneFrame + 1
  end

  -- Add subtitle commands here
  timedDialog(30, NPCID_DEMO, "Demo", "Testing, testing, 1, 2, 3...", 120, 180)
  timedDialog(60, NPCID_IRIS, "Iris", "Hey there, everyone!", 60, 120)
  timedDialog(90, NPCID_KOOD, "Kood", "This is a test of a LunaLUA cutscene system.", 150, 180)  
end



function setDialogRules(pause, skippable, needInput)
  dialogPause = pause
  dialogSkippable = skippable
  dialogEndWithInput = needInput
end


function timedDialog(frame, speakerid, name, text, textTime, speakTime, sound)
  if(cutsceneFrame == frame)then
    -- Insert play sound command here
    timedDialog(frame, speakerid, name, text, textTime, speakTime)
  end
end

function timedDialog(frame, speakerid, name, text, textTime, speakTime)
  if(cutsceneFrame == frame)then
    triggerSpeaker(speakerid, speakTime)
    triggerDialog(name, text, textTime)
  end
end


function triggerSpeaker(npcid, time)
  dialogSpeaker = npcid
  dialogSpeakerTime = time
end

function triggerDialog(name,text,time)
  dialogName = name
  dialogText = text
  dialogTextTime = textTime
end


function processDialog() 

  -- Decrement the dialogue timer.
  if(dialogTextTime > 0)then
    if(dialogEndWithInput == true  and  player:mem(0x134, FIELD_WORD) == 1)then
      dialogTextTime = 0
      dialogSpeakerTime = 0
    else
      dialogTextTime = dialogTextTime - 1
    end

    -- While the dialogue timer counts down, display the dialogue.  
    printText(dialogName..":\n"..dialogText, 30, 500)
  end


  -- When the speaker timer reaches zero, reset the speaker.
  speakerTime = speakerTime - 1

  if(speakerTime == 0)then
    dialogSpeaker = 0
  end
end


function processNPCTalkAnim(npcid, idleMin, idleMax, talkMin, talkMax)
  -- Control the specified NPC's animation based on whether or not it's currentSpeaker
  if(currentSpeaker == npcid)then
    clampNPCAnim(npcid, talkMin, talkMax)
  else
    clampNPCAnim(npcid, idleMin, idleMax)
  end
end


function clampNPCAnim(npcid, min, max)
  local myNPC = findnpcs(npcid, -1)[0]
  animFrame = getNPCAnimFrame(myNPC)
  if(animFrame < min  or  animFrame > max)then
    setNPCAnimFrame(myNPC, min)
end


function getNPCAnimFrame(myNPC)
  return myNPC:mem(0xE4, FIELD_WORD)
end


function setNPCAnimFrame(myNPC, frame)
  myNPC:mem(0xE4, FIELD_WORD, frame)
end
To use it, include a processNPCTalkAnim() command in onLoop for each NPC ID you want to animate, then add timedDialog() commands to processCutscene to create a sequence of subtitles and character animations. You can use setDialogRules() to control how dialogue flows/progresses. The NPC sprites can have any number of animation frames, but you'll want at least two so you can specify separate frames/ranges for idle and talking animations.

Again, I'm not super Lua-savvy, so apologies if there are any syntax errors or other major issues here. Hopefully this thing'll aid folks in making more cinematic cutscenes; at the very least it should help clear up issues people have with identifying which character is speaking, as has been the case with Youtubers being introduced to the siblings for the first time.
Last edited by Rixithechao 9 years ago, edited 6 times in total.
Delightful Adventure Enhanced is out now!

Image

There's an official ASMT Discord server! Check it out to discuss Demo games and follow their development! thread, invite link

(Entry requires verification, either with a connected Youtube/Twitter/Twitch/etc account or manually by the server staff.)


Itch.io (albums and eventually games), Youtube (dofur pass and I guess other videos)
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

There are some syntax errors. Lua is case sensitiv with functions and variables.

Also:

Code: Select all

local myNPC = findnpcs(npcid, -1)[0]
add '[0]' to get the first npc match, because findnpcs returns an array :P
Rixithechao
https://www.youtube.com/watch?v=BODxOghVmko
Posts: 1812
Joined: 10 years ago
First name: Mack
https://rixithechao.talkhaus.com/

Re: Presenting: Lunadll for Lua!

Post by Rixithechao »

Arright, fixed some misnamed variables and incorrectly-formatted hex addresses, added the [0] (not really sure what I was thinking trying to do that to the whole array), changed some of the spacing to be closer to the examples. Did I miss anything?
Delightful Adventure Enhanced is out now!

Image

There's an official ASMT Discord server! Check it out to discuss Demo games and follow their development! thread, invite link

(Entry requires verification, either with a connected Youtube/Twitter/Twitch/etc account or manually by the server staff.)


Itch.io (albums and eventually games), Youtube (dofur pass and I guess other videos)
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Lua unfortunaly doesn't support one-line if, for, function and while-loops. You always have to close them with the 'end' keyword.

processDialogue() to processDialog()

EDIT: Here the fixed code:

Code: Select all

dialogSpeaker = 0

dialogTextTime = 0
dialogSpeakerTime = 0

dialogName = ""
dialogText = ""

-- Can the player press the key to skip the current line?
dialogSkippable = true

-- Does the dialogue halt the cutscene timing?
dialogPause = true

-- Does the player have to press a key to continue?
dialogEndWithInput = true

-- Can the entire cutscene be skipped?
cutsceneSkippable = true

-- Current cutscene time in frames
cutsceneFrame = 0


-- Constants
NPCID_DEMO = 101
NPCID_IRIS = 102
NPCID_KOOD = 103




function onLoad()
  dialogSpeaker = 0
 
  dialogTextTime = 0
  dialogSpeakerTime = 0
 
  dialogName = ""
  dialogText = ""
 
  dialogSkippable = true
  dialogPause = true
  dialogEndWithInput = true
 
  cutsceneFrame = 0

  setDialogRules(true, true, true)
end




function onLoop()
  -- Trigger sequenced cutscene events
  processCutscene()

  -- Control specific NPC talking/idle animations
  processNPCTalkAnim(NPCID_DEMO, 0, 3, 4, 7)
  processNPCTalkAnim(NPCID_IRIS, 0, 0, 1, 4)
  processNPCTalkAnim(NPCID_KOOD, 0, 15, 16, 19)

  -- Control dialogue display
  processDialog()
end


function processCutscene()
  if(dialogPause == false  or  dialogTextTime <= 0)then
    cutsceneFrame = cutsceneFrame + 1
  end

  -- Add subtitle commands here
  timedDialog(30, NPCID_DEMO, "Demo", "Testing, testing, 1, 2, 3...", 120, 180)
  timedDialog(60, NPCID_IRIS, "Iris", "Hey there, everyone!", 60, 120)
  timedDialog(90, NPCID_KOOD, "Kood", "This is a test of a LunaLUA cutscene system.", 150, 180) 
end



function setDialogRules(pause, skippable, needInput)
  dialogPause = pause
  dialogSkippable = skippable
  dialogEndWithInput = needInput
end


function timedDialog(frame, speakerid, name, text, textTime, speakTime, sound)
  if(cutsceneFrame == frame)then
    -- Insert play sound command here
    timedDialog(frame, speakerid, name, text, textTime, speakTime)
  end
end

function timedDialog(frame, speakerid, name, text, textTime, speakTime)
  if(cutsceneFrame == frame)then
    triggerSpeaker(speakerid, speakTime)
    triggerDialog(name, text, textTime)
  end
end


function triggerSpeaker(npcid, time)
  dialogSpeaker = npcid
  dialogSpeakerTime = time
end

function triggerDialog(name,text,textTime)
  dialogName = name
  dialogText = text
  dialogTextTime = textTime
end


function processDialog()

  -- Decrement the dialogue timer.
  if(dialogTextTime > 0)then
    if(dialogEndWithInput == true  and  player:mem(0x134, FIELD_WORD) == 1)then
      dialogTextTime = 0
      dialogSpeakerTime = 0
    else
      dialogTextTime = dialogTextTime - 1
    end

    -- While the dialogue timer counts down, display the dialogue. 
    printText(dialogName..":\n"..dialogText, 30, 500)
  end


  -- When the speaker timer reaches zero, reset the speaker.
  dialogSpeakerTime = dialogSpeakerTime - 1

  if(dialogSpeakerTime == 0)then
    dialogSpeaker = 0
  end
end


function processNPCTalkAnim(npcid, idleMin, idleMax, talkMin, talkMax)
  -- Control the specified NPC's animation based on whether or not it's currentSpeaker
  if(currentSpeaker == npcid)then
    clampNPCAnim(npcid, talkMin, talkMax)
  else
    clampNPCAnim(npcid, idleMin, idleMax)
  end
end


function clampNPCAnim(npcid, min, max)
  local myNPC = findnpcs(npcid, -1)[0]
  animFrame = getNPCAnimFrame(myNPC)
  if(animFrame < min  or  animFrame > max)then
    setNPCAnimFrame(myNPC, min)
  end
end


function getNPCAnimFrame(myNPC)
  return myNPC:mem(0xE4, FIELD_WORD)
end


function setNPCAnimFrame(myNPC, frame)
  myNPC:mem(0xE4, FIELD_WORD, frame)
end

function processNPCTalkAnim(npcid, idleMin, idleMax, talkMin, talkMax)
  -- Control the specified NPC's animation based on whether or not it's currentSpeaker
  if (currentSpeaker == npcid)then
    clampNPCAnim(npcid, talkMin, talkMax)
  else
    clampNPCAnim(npcid, idleMin, idleMax)
  end
end


function clampNPCAnim(npcid, min, max)
  local myNPC = findnpcs(npcid, -1)[0]
  animFrame = getNPCAnimFrame(myNPC)
  if (animFrame < min  or  animFrame > max)then
    setNPCAnimFrame(myNPC, min)
  end
end


function getNPCAnimFrame(tarNPC)
  return tarNPC:mem(0xE4, FIELD_WORD)
end

function setNPCAnimFrame(tarNPC, val)
  tarNPC:mem(0xE4, FIELD_WORD, val)
end
Althought it doesn't work really as expect. May you need to test it...

btw, when you run the code, lua should give you the errors anyway.... (You can even use it in the editor)
Kil
Posts: 13
Joined: 15 years ago

Re: Presenting: Lunadll for Lua!

Post by Kil »

There is a decent text editor named SciTE that comes with Lua, which has highlighting and things. Very helpful 8-)
DON'T PM me. Ask your question in the help thread so everyone can be answered.
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Or Notepad++ :D
Kil
Posts: 13
Joined: 15 years ago

Re: Presenting: Lunadll for Lua!

Post by Kil »

oh, thanks for telling me about that. That's the one I was looking for 8-)
DON'T PM me. Ask your question in the help thread so everyone can be answered.
Rixithechao
https://www.youtube.com/watch?v=BODxOghVmko
Posts: 1812
Joined: 10 years ago
First name: Mack
https://rixithechao.talkhaus.com/

Re: Presenting: Lunadll for Lua!

Post by Rixithechao »

Ah, thought I capped off all of those, guess I missed a few ends.

Yeah, had I been using a proper IDE I would've caught those, but admittedly I haven't set everything up yet for incredibly dumb reasons -- I had trouble getting LunaDLL to work in the past so I was kinda worried that I'd end up spending all my free time on the installation process the DLLs and never get around to actually working with it.

That said, I've probably spent more time on this back-and-forth thingamajig than it probably would take me install it, and now I'm out of time. I'll get back to this thing this weekend. Thanks for the help and apologies for the trouble!
Delightful Adventure Enhanced is out now!

Image

There's an official ASMT Discord server! Check it out to discuss Demo games and follow their development! thread, invite link

(Entry requires verification, either with a connected Youtube/Twitter/Twitch/etc account or manually by the server staff.)


Itch.io (albums and eventually games), Youtube (dofur pass and I guess other videos)
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Version 0.2.2 is out!

Changes:
*Added playSFX
*Added triggerEvent
*Added access to player 2
*Added new events onJump, onJumpEnd, onKeyDown, onKeyUp
Rixithechao
https://www.youtube.com/watch?v=BODxOghVmko
Posts: 1812
Joined: 10 years ago
First name: Mack
https://rixithechao.talkhaus.com/

Re: Presenting: Lunadll for Lua!

Post by Rixithechao »

Test video time.
More details in the video description.
Delightful Adventure Enhanced is out now!

Image

There's an official ASMT Discord server! Check it out to discuss Demo games and follow their development! thread, invite link

(Entry requires verification, either with a connected Youtube/Twitter/Twitch/etc account or manually by the server staff.)


Itch.io (albums and eventually games), Youtube (dofur pass and I guess other videos)
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Just on the notice about the third line, it is because only Uppercase is allowed, I will implement a auto-uppercase soon. Keep up with the videos ;)
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Version 0.2.3 is out!

Changes:
* Added event support for player 2.
* printText now auto-uppercase the text.
Rixithechao
https://www.youtube.com/watch?v=BODxOghVmko
Posts: 1812
Joined: 10 years ago
First name: Mack
https://rixithechao.talkhaus.com/

Re: Presenting: Lunadll for Lua!

Post by Rixithechao »

Dangit, I took too long to reply!

When you say only uppercase is allowed, do you mean that this extension (I'm just gonna call it LuaLuna from now on) can't do lowercase or SMBX? According to the LunaDLL documentation there is a font that features lowercase letters:
FONT 1 only displays black letters (overworld level name font)
FONT 2 only displays numbers (score font)
FONT 3 only displays uppercase (normal game font)
...but I haven't been able to get Font 1 to work for whatever reason. I don't know if it's just an issue on my part or if Font 1 simply doesn't work in LunaLua, but unless it's the latter I don't recommend auto-capitalizing displayed text. At least not for fonts besides #3, anyway.

On another note, can this extension (I'm just gonna call it LuaLuna from now on) reference the level directory like LunaDLL autocode can? It would be great if we had the option to use file names for playSFX in addition to indexes, and there's so much that could be done with LoadImage and PlaceSprite. In general, it'd be helpful to have a list of planned features as well as which LunaDLL functionality, if any, can't be implemented in LuaLuna for whatever reason.
Delightful Adventure Enhanced is out now!

Image

There's an official ASMT Discord server! Check it out to discuss Demo games and follow their development! thread, invite link

(Entry requires verification, either with a connected Youtube/Twitter/Twitch/etc account or manually by the server staff.)


Itch.io (albums and eventually games), Youtube (dofur pass and I guess other videos)
Kil
Posts: 13
Joined: 15 years ago

Re: Presenting: Lunadll for Lua!

Post by Kil »

Font 1 should be able to display small letters. It's the smbx font used for level names. Only problem is that that font is black, so it's ugly. ALso that's a cool cutscene thing.
DON'T PM me. Ask your question in the help thread so everyone can be answered.
Rixithechao
https://www.youtube.com/watch?v=BODxOghVmko
Posts: 1812
Joined: 10 years ago
First name: Mack
https://rixithechao.talkhaus.com/

Re: Presenting: Lunadll for Lua!

Post by Rixithechao »

...So I tried something. I set up a simple loop and iterated through fonts 0 to 6.

Image

I'mma do it 30 times or more and see if there are any others tucked away in there.

EDIT:
Image

Also past me, that's not how you spell "LuaLuna".
Delightful Adventure Enhanced is out now!

Image

There's an official ASMT Discord server! Check it out to discuss Demo games and follow their development! thread, invite link

(Entry requires verification, either with a connected Youtube/Twitter/Twitch/etc account or manually by the server staff.)


Itch.io (albums and eventually games), Youtube (dofur pass and I guess other videos)
Kil
Posts: 13
Joined: 15 years ago

Re: Presenting: Lunadll for Lua!

Post by Kil »

Wait, there's a 4th font I never knew about? ... God damnit.
DON'T PM me. Ask your question in the help thread so everyone can be answered.
Rixithechao
https://www.youtube.com/watch?v=BODxOghVmko
Posts: 1812
Joined: 10 years ago
First name: Mack
https://rixithechao.talkhaus.com/

Re: Presenting: Lunadll for Lua!

Post by Rixithechao »

Yep, I thought the message box font was just the overworld font inverted but I guess it's a different thing altogether.

EDIT: The animation stuff is mostly working now. I can't get characters to stop jittering when I specify a single-frame loop, but as long as the max is greater than the min it works perfectly. I'll record another video once I get text wrapping to work.
Last edited by Rixithechao 9 years ago, edited 1 time in total.
Delightful Adventure Enhanced is out now!

Image

There's an official ASMT Discord server! Check it out to discuss Demo games and follow their development! thread, invite link

(Entry requires verification, either with a connected Youtube/Twitter/Twitch/etc account or manually by the server staff.)


Itch.io (albums and eventually games), Youtube (dofur pass and I guess other videos)
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Post by Hoeloe »

Rockythechao wrote:Yep, I thought the message box font was just the overworld font inverted but I guess it's a different thing altogether.
Looks to be a monospaced version, probably to make fitting the font to the text box easier.
Image
Image
Image
Image
Image
Kil
Posts: 13
Joined: 15 years ago

Re: Presenting: Lunadll for Lua!

Post by Kil »

I guess font 1 is the score and only displays integers
DON'T PM me. Ask your question in the help thread so everyone can be answered.
Rixithechao
https://www.youtube.com/watch?v=BODxOghVmko
Posts: 1812
Joined: 10 years ago
First name: Mack
https://rixithechao.talkhaus.com/

Re: Presenting: Lunadll for Lua!

Post by Rixithechao »

Oh, one more thing! Does version 0.2.2 (not gonna update just yet due to autocaps) process both Lua and autocode or just one or the other? I remember seeing something in the LunaDLL help thread about it disabling one if the other is detected, but if it allows both I'mma try out some HUD stuff.
Delightful Adventure Enhanced is out now!

Image

There's an official ASMT Discord server! Check it out to discuss Demo games and follow their development! thread, invite link

(Entry requires verification, either with a connected Youtube/Twitter/Twitch/etc account or manually by the server staff.)


Itch.io (albums and eventually games), Youtube (dofur pass and I guess other videos)
Post Reply