(shouting)

LunaLua Offical Thread

The second SMBX collab!

Shall I stream some LunaLua live development?

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

User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Post by Hoeloe »

Kevsoft wrote:Layers in SMBX don't have positions. They only move their objects by the speed, nothing else.
I see... Theoretically it should be possible to create such a position variable then, by simply changing the positions of the objects in the layer. In any case, it would be nice to see an example of how to correctly use the layer speed. At the moment, I'm making the assumption that the code is called once per frame, which is the ideal. It does appear, however, that frameskip might cause these events to be skipped, which breaks the cycle.

At the moment, I'm having to create a bounding box, which stops the motion and prevents the movement events from continuing if the player is outside it. This seems to work okay, but a more concrete solution would be preferred.

EDIT: Okay, this doesn't work 100% of the time, and the events can still get out of sync, but it's now extremely rare, which is good.

EDIT EDIT: Okay, I think I've improved it a little, but it's still not perfect. It seems that, very occasionally, LunaLua either skips frames (even while frameskip is turned off) or runs a frame twice. This makes looping movements essentially impossible to deal with, because LunaLua's update cycle doesn't match with the update cycle of layer movements. This means that any layer movement can move too much, or too little, causing errors in the movement. I hope there is some way this can be fixed in future versions. My suggestion would be to handle "layer movement" manually, rather than going through SMBX's system, and update the position of objects in the layer as SMBX does, but within the DLL. The benefit of this would be to guarantee that if a frame is skipped in Lua, then it will also skip frames in the layer movement (meaning that events to change movement speed won't be skipped). It will also making logging and setting absolute layer positions a possibility, which is a much more intuitive system for certain kinds of operation.

EDIT EDIT EDIT: AHA! I've worked it out! While the player is taking damage (or collecting a powerup), LunaLua remains updating. However, layer movement does not apply while this is happening. Because of this, the layer position desyncs from the counter. This causes layers to be in the wrong place, moving in the wrong direction. Is there a way to prevent this?
Image
Image
Image
Image
Image
TiKi
Posts: 709
Joined: 11 years ago

Re: Presenting: Lunadll for Lua!

Post by TiKi »

Hey Hoeloe could you please make something like the RaoCoin counter but for red coins? That doesn't store anything (a la shop) except for displaying the level's amount you collected? A friend of mine wanted that.
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Post by Hoeloe »

TiKi wrote:Hey Hoeloe could you please make something like the RaoCoin counter but for red coins? That doesn't store anything (a la shop) except for displaying the level's amount you collected? A friend of mine wanted that.
Just one that counts the in-level coins? Actually fairly easy. The Raocoin counter uses a neat trick to determine when you collect one. It finds all the Raocoins in the level and counts them. If the count on one frame is less than the count on the previous frame, then it assumes you've collected one, and adds to the counter*. Replicating that for other NPCs is fairly trivial.

*This may be complicated by things such as hiding layers, though I think it still counts them. This can be repaired by disabling the counter when the layers are hidden, or otherwise accounting for these discrepancies. For most cases, just counting the objects will work fine.

The code that deals with this in the Raocoin counter is this:

Code: Select all

local raocoins = 0;
local lastRaocoins = -1;

function onLoop()
	local rcs = findnpcs(274, -1);  --find all raocoins
	local raocounter = 0;
	  
	  for key,value in pairs(rcs) do
		raocounter = raocounter + 1; --count the number of raocoins
	  end
	  
	  if(raocounter < lastRaocoins) then --if there are fewer raocoins this frame than the previous frame
			raocoins = raocoins+lastRaocoins-raocounter; --take the difference between the two and add that to the counter
		end
	  lastRaocoins = raocounter; --keep track of the raocoins on the previous frame
end
Changing this to work for red coins, or any NPC, is very simple - just change the NPC ID in the first line! The ID of raocoins is 274, but if you swap that with something else, it will count that NPC instead. The value that's called "raocoins" here stores the coins collected, so you can use that too.

I would warn you that for objects like coins, that might have hundreds of instances instead of 5, this might be extremely inefficient, and you may be better off using the Trigger library, along with a SMBX event triggered when collecting the coins, though that itself has caveats (i.e. may not work if multiple coins are collected in very quick succession).
Image
Image
Image
Image
Image
TiKi
Posts: 709
Joined: 11 years ago

Re: Presenting: Lunadll for Lua!

Post by TiKi »

Great! That's easy to do! Is it possible to make it not retain the count between levels?
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

The new Animation/Effect System in the upcoming LunaLua version:


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 »

Kevsoft wrote:The new Animation/Effect System in the upcoming LunaLua version:


That is a really nice looking effect. Can it make everything shiny/sparkly too?
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Every effect SMBX can play.
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 »

Kevsoft wrote:The new Animation/Effect System in the upcoming LunaLua version:


Image

Also, I just remembered that NPCs have an offset for checking whether they're interacting with the player.

Code: Select all

// 0x+44	w	= Activated / interacted with player flag
That'd probably be simpler to use than checking against the remaining count, but then again you've probably already tried it.
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 »

The code I posted won't retain the count between levels. That needs special handling and a user variable, so that should be fine.
Rockythechao wrote: Also, I just remembered that NPCs have an offset for checking whether they're interacting with the player.
Doesn't work, unfortunately. The NPCs are immediately removed from play, so this flag is never triggered. It was the first thing I tried for the Raocoin system.

Oh, also, Kevsoft, this has been bugging me a little for a while, but you keep using the word "documentary" when you mean "documentation". A documentary is a non-fiction TV or radio program, while documentation is a record of information about a programming language or API.
Image
Image
Image
Image
Image
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Hoeloe wrote:Oh, also, Kevsoft, this has been bugging me a little for a while, but you keep using the word "documentary" when you mean "documentation". A documentary is a non-fiction TV or radio program, while documentation is a record of information about a programming language or API.
Yea sorry, english is not my native language and I do sometimes silly mistakes.

Anyway:
LunaLua v0.3.4 is out!
Changes:
*Added the function exitLevel()
*Added getter and setter function winState()
*Added Animation class (I know it's called effect in SMBX but I got used to it)
*Added the function runAnimation(...) to run a SMBX Effect.
Example (from the video demonstration):

Code: Select all

function isCrabDead() return findnpcs(209, -1)[0] == nil end

function onLoop()
	if not isCrabDead() then return end
	local myBlocks = blocks()
	local plScreen = player.screen
	local k = 0
	for _,v in pairs(myBlocks) do
		k = k + 1
		local curX = v.x
		local curY = v.y
		if(k % math.random(1,2000) == 0)then
			if(player.y-plScreen.top < curY and player.y-plScreen.top+600 > curY and player.x-plScreen.left < curX and player.x-plScreen.left+800 > curX)then
				runAnimation(108, curX, curY+16, 1065353216)
			end
		end

	end
	earthquake(5)
end
Documentation will be updated soon! :P

PS: I feel LunaLua is already quite finished and I want do now more work on Wohlstand's Editor. I only did LunaLua that you guys can do awesome stuff with LunaDLL, but I still stick more to the Editor than to Lunadll.
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Post by Hoeloe »

Kevsoft wrote: PS: I feel LunaLua is already quite finished and I want do now more work on Wohlstand's Editor. I only did LunaLua that you guys can do awesome stuff with LunaDLL, but I still stick more to the Editor than to Lunadll.
There are still quite a few things missing. Custom cheats, for one, and there are a few things such as disabling player input which still need to be worked out.

So does the levelEnd function just end the level as though you've encountered an exit?
Image
Image
Image
Image
Image
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Hoeloe wrote:There are still quite a few things missing. Custom cheats, for one, and there are a few things such as disabling player input which still need to be worked out.
I didn't say I am completly finished, I just said that I am going to slowly "close" this project.
Hoeloe wrote:So does the levelEnd function just end the level as though you've encountered an exit?
"exitLevel()" does simply end the level immediately.
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Post by Hoeloe »

Kevsoft wrote: I didn't say I am completly finished, I just said that I am going to slowly "close" this project.
Okay. Have you released the source anywhere so others can continue it when you do?
Kevsoft wrote: "exitLevel()" does simply end the level immediately.
Okay. I can see that being quite useful for a joke I have planned.
Image
Image
Image
Image
Image
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

Hoeloe wrote:Okay. Have you released the source anywhere so others can continue it when you do?
Yes: Github link! Kil has access to this repo so he will upload any changes he does too. So everyone can help.
Hoeloe wrote:Okay. I can see that being quite useful for a joke I have planned.
Glad to see that it will be useful :P
Kil
Posts: 13
Joined: 15 years ago

Re: Presenting: Lunadll for Lua!

Post by Kil »

I told you guys to get on github so you could help update Lua faster :P I wasn't planning to myself so I wouldn't get in the way of kevsoft's plans, but if he's finished I guess I could try and figure it out...
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 »

The link to the source code has been at the bottom of the original post for quite a while, I've been reading through it to try and figure out stuff myself. It's pretty easy to miss down there, so you might want to move it up to the where the links for the download & documentation are.

It's understandable if you want to move on, Kev. We really appreciate all of the effort you've put into this module :D
I've been set up to work with the source for over a month now, kept meaning to mention that but I don't think I ever did... And now my trial for Visual Studio's probably expired so I'll have to get a full license.

In the meantime, I can still offer snippets of code that can be copied and pasted into the solution. And on that note, are the NPC constants I put together going be implemented? I don't mean to be pushy about it or anything, it's just that I haven't gotten any feedback on those things so I don't know if anyone's even interested :|
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 »

Rockythechao wrote:The link to the source code has been at the bottom of the original post for quite a while, I've been reading through it to try and figure out stuff myself. It's pretty easy to miss down there, so you might want to move it up to the where the links for the download & documentation are.
Updated the main post.
Rockythechao wrote:It's understandable if you want to move on, Kev. We really appreciate all of the effort you've put into this module :D
I've been set up to work with the source for over a month now, kept meaning to mention that but I don't think I ever did... And now my trial for Visual Studio's probably expired so I'll have to get a full license.
I appreciate all of you with your feedback about LunaLua. :)
Rockythechao wrote:And on that note, are the NPC constants I put together going be implemented? I don't mean to be pushy about it or anything, it's just that I haven't gotten any feedback on those things so I don't know if anyone's even interested :|
Sorry about that I missed that. I did see it but I thought you implement it as a softcoded API part. I can surely do that for the hardcoded part in the dll itself.
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 »

Kevsoft wrote:Sorry about that I missed that. I did see it but I thought you implement it as a softcoded API part. I can surely do that for the hardcoded part in the dll itself.
Ah, my bad. I did start working on it as part of cinematX but then I figured it'd be best if they weren't tied to a separate module like that. I guess I didn't communicate that well :oops:

But, er, *ahem*, I finally got around to checking the source to see what offset you used for the NPC messages, aaaaaaaand...

~SUCCESS~!!!

Image

Changing the NPC's message pointer does indeed disable the speaking interaction in-game!

Now that that's taken care of, I can start working on the following functionality:

  • Custom context-sensitive NPC icons that can be displayed from further away than the SMBX default; you'll know whether the NPC is friendly or an enemy the moment the appear onscreen, and you'll know whether that NPC has anything new to say or to differentiate between flavor/advice NPCs and quest-givers
  • Call cinematX coroutines by talking to NPCs -- complex cutscenes, shop interfaces, etc.
  • Wrapping regular NPC dialogue in cinematX messages to keep it from interrupting LunaDLL/LunaLua stuff
[/size]

And don't worry, I'm making sure that the message pointers aren't permanently detached from the NPCs to prevent memory leaks.
Last edited by Rixithechao 9 years ago, edited 2 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
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Post by Hoeloe »

Kevsoft wrote: Sorry about that I missed that. I did see it but I thought you implement it as a softcoded API part. I can surely do that for the hardcoded part in the dll itself.
The constants would be best softcoded in my opinion, since Lua has a global namespace you can use, they can just be put into that. It might be best to have them as part of a subtable, though, so instead of writing something like:

Code: Select all

NPC_ID_GOOPA
You'd write something like:

Code: Select all

NPCID.GOOPA
Might be slightly better organised, and take up less of the global namespace (which is usually a good idea to keep reasonably free). Just a thought.
Image
Image
Image
Image
Image
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 »

Hoeloe wrote:
Kevsoft wrote: Sorry about that I missed that. I did see it but I thought you implement it as a softcoded API part. I can surely do that for the hardcoded part in the dll itself.
The constants would be best softcoded in my opinion, since Lua has a global namespace you can use, they can just be put into that. It might be best to have them as part of a subtable, though...
Oh, right! Tables as enums!
I'll go ahead and convert that list into an API, then.

EDIT:
https://drive.google.com/file/d/0B-w323 ... sp=sharing
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 »

Rockythechao wrote:Changing the NPC's message pointer does indeed disable the speaking interaction in-game!
Do you mean changing the text or changing the pointer value itself?
Because if you mean the text then it would be strange... I used the API part (for example NPC.msg.str = "A text") and it works perfect.

Edit:
Your name API is not working out that well.

Code: Select all

NPCID.1UP_SMB = 186
is not working because the key-variable is starting with a number instead of a letter.
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 »

Kevsoft wrote:
Rockythechao wrote:Changing the NPC's message pointer does indeed disable the speaking interaction in-game!
Do you mean changing the text or changing the pointer value itself?
Because if you mean the text then it would be strange... I used the API part (for example NPC.msg.str = "A text") and it works perfect.
The pointer value. On the first update call, cinematX indexes all the important info to three tables:

Code: Select all

cinematX.npcMessageNPCs = {}
cinematX.npcMessagePointers = {}
cinematX.npcMessageStrings = {}
If any NPC is found to have a blank msg.str, it sets cinematX.nilNPCPointer to that NPC's pointer. Then during subsequent updates it loops through each NPC in npcMessageNPCs, sets their pointer back to the corresponding index in cinematX.npcMessagePointers and then sets it to cinematX.nilNPCPointer if that NPC is in the player's current section.

That last part can definitely be optimized, and I should probably add some additional safeguards to ensure that the pointer is back with the NPC whenever it needs to be cleared from memory.

Edit:
Your name API is not working out that well.

Code: Select all

NPCID.1UP_SMB = 186
is not working because the key-variable is starting with a number instead of a letter.
Whoops! I'll go ahead and change any initial numbers to their corresponding words. Sorry about that!

EDIT: Okay, changed the "1UP"s to "LIFE" and "3UP" to "MOON". Let me know if there's any other issues.
https://drive.google.com/file/d/0B-w323 ... sp=sharing
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 »

I added your npcid.lua as a standard library. I would like to add cinematiX also as standard library but I want to ensure first that it is finished and that there is a small documentation or at least a small example bundled with this library.
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Presenting: Lunadll for Lua!

Post by Kevsoft »

LunaLua v0.3.4.1 is out!

First of all I hardcoded a function which automatically resets several memory addresses. Currently in are gravity and jumpheight. If you have any more memory addresses that need to be reseted then let Kil or me know.

Now to the changes:
Added the function getInput() which returns a VBStr to cheat buffer.
Added field .length to VBStr. (Note it is always 2 bytes per character because of UNICODE)

Softcoded part:
Added library npcid.lua by Rockythechao.
Added library asmmod.lua by Kevsoft.
Example:

Code: Select all

asm = loadAPI("asmmod")

function onLoad()
	asm.setEndingAnimation(108) --Explosion Effect
	asm.setEndingCoinSound(56) --Sound id
	asm.setEndingCoinValue(13) --Coins per npc removal
end

function onLoop()
	printText(tostring(getInput().length).." "..getInput().str, 30, 190)
end
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Presenting: Lunadll for Lua!

Post by Hoeloe »

I have a few questions:

1. If, for example, I typed "abcd", would "getInput" return the values "a", "ab", "abc" and "abcd", or "a","b","c","d"? The latter may be more useful.
2. If "getInput" does return the complete string, what is the cooldown time? That is, if I typed "hello world", how long would I have to wait before pressing the "a" key such that it returns "a" instead of "hello worlda"? (Ignore this is the answer to question 1 returns individual characters)
3. Does the .length field return the length in characters or the length in bytes? It's arguably more convenient to return the length in characters, rather than raw bytes, as it doesn't require the user to know about the internal representation of strings and characters unless they need to do something involving raw data manipulation, in which case they can calculate the byte length from the character count.
4. What does the "asm" library actually DO? You've given an example of its use, but not actually said what it does.
Image
Image
Image
Image
Image
Post Reply