(shouting)

Lua help thread

If you lost something come look for it here
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Lua help thread

Post by Hoeloe »

acrowdofpeople wrote: EDIT: I broke multipoints somehow. When I use it to provide a second midpoint, the SMBX-provided one breaks, so I removed the first one and tried to use multipoints to add the first one back - only to break the midpoint I had added originally.

Code: Select all

multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(-139925, -140055, 3);
multipoints.addLuaCheckpoint(-99942, -100070, 5);
The last line was the one that originally worked, so I tried using the second line to replace the SMBX midpoint... which caused the third line to break somehow and now there are no midpoints. I'll just provide a shortcut through the midpoint room to the boss...
Using regular SMBX midpoints with multipoints isn't advised, but two multipoints checkpoints shouldn't break anything. Make sure you reset the level before testing again, otherwise things will get confused.

If it still doesn't work, then I could take a look at the level and see if I can work it out. You do want to make sure you have the most recent version of multipoints, though, because I think the one included in LunaLua is out of date.
Image
Image
Image
Image
Image
acrowdofpeople
Posts: 54
Joined: 8 years ago

Re: Lua help thread

Post by acrowdofpeople »

Here's a test version of the level with the two midpoints from multipoints.

By "reset the level," you mean close out after removing the smbx midpoint and load it up again, right?
S1eth
Posts: 291
Joined: 9 years ago

Re: Lua help thread

Post by S1eth »

acrowdofpeople wrote:Here's a test version of the level with the two midpoints from multipoints.

By "reset the level," you mean close out after removing the smbx midpoint and load it up again, right?
In the SMBX editor: Test Level --> Reset Level (F8)
Image
acrowdofpeople
Posts: 54
Joined: 8 years ago

Re: Lua help thread

Post by acrowdofpeople »

Okay, tried it... midpoints still aren't working.
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Lua help thread

Post by Hoeloe »

Yeah. It works fine for me. Make sure you have the latest version of LunaLua and multipoints.
Image
Image
Image
Image
Image
acrowdofpeople
Posts: 54
Joined: 8 years ago

Re: Lua help thread

Post by acrowdofpeople »

I thought I did. I downloaded the most recent version of multipoints from the multipoints page and installed it after downloading the most recent version of Lua from the Lua page and installing that over the one in the devkit...
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Lua help thread

Post by Hoeloe »

acrowdofpeople wrote:I thought I did. I downloaded the most recent version of multipoints from the multipoints page and installed it after downloading the most recent version of Lua from the Lua page and installing that over the one in the devkit...
If you open your multipoints.lua file, what's the version number at the top of the file?
Image
Image
Image
Image
Image
acrowdofpeople
Posts: 54
Joined: 8 years ago

Re: Lua help thread

Post by acrowdofpeople »

2.2.2
Edit: I somehow missed the actual lib file, which was just floating around... now it's 3.0. I'll retest.
Last edited by acrowdofpeople 8 years ago, edited 1 time in total.
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Lua help thread

Post by Hoeloe »

acrowdofpeople wrote:2.2.2
The current most recent version should be 3.0.0. Let me check the download.

EDIT: Looks like you've downloaded the version for LunaLua v0.6 and lower. Try the other one.
Image
Image
Image
Image
Image
acrowdofpeople
Posts: 54
Joined: 8 years ago

Re: Lua help thread

Post by acrowdofpeople »

Looks like it's working, I just need to fine-tune the coordinates now. Thanks!
User avatar
Dog In Da Grass
Woof!
Posts: 522
Joined: 10 years ago
First name: Dog
Pronouns: that dog
Location: Da Grass

Re: Lua help thread

Post by Dog In Da Grass »

Is there any witchcraft or science I can do to make the hud disappear?
:pal: Image :pal:

Image
Image
Image
acrowdofpeople
Posts: 54
Joined: 8 years ago

Re: Lua help thread

Post by acrowdofpeople »

So I'm trying to have lua trigger a SMBX event for me.

Code: Select all

multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(-139925, -140055, 2, -159696, -160241);
multipoints.addLuaCheckpoint(-99942, -100070, 2, -159696, -160241, "endboss");
function endboss
triggerEvent("finalbosswarp")
end
With this code, when I load up the level, I get an error: '(' expected near 'triggerEvent'
What did I break this time?
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Lua help thread

Post by Hoeloe »

acrowdofpeople wrote:So I'm trying to have lua trigger a SMBX event for me.

Code: Select all

multipoints = loadAPI("multipoints");
multipoints.addLuaCheckpoint(-139925, -140055, 2, -159696, -160241);
multipoints.addLuaCheckpoint(-99942, -100070, 2, -159696, -160241, "endboss");
function endboss
triggerEvent("finalbosswarp")
end
With this code, when I load up the level, I get an error: '(' expected near 'triggerEvent'
What did I break this time?
Functions can't just have names, they need a list of arguments when you define it. A list of arguments is denoted by a pair of brackets, with each argument inside separated by commas. For example, a function with two arguments might be defined:

Code: Select all

function myFunc(arg1, arg2)
Which reflects the way you would call the function:

Code: Select all

myFunc(a,b)
For a function with no arguments, just leave the argument list empty:

Code: Select all

function myFunc()
Which again reflects how you call it:

Code: Select all

myFunc()
I suggest reading the tutorials on the LunaLua wiki. They cover things like this.
Image
Image
Image
Image
Image
acrowdofpeople
Posts: 54
Joined: 8 years ago

Re: Lua help thread

Post by acrowdofpeople »

The tutorial was where I got the idea to trigger an event off of this.
EDIT: I'm apparently having a basic conceptual misunderstanding of what I'm trying to do here. I'll try this again once I've mastered the tutorial material. Thank you.
User avatar
Kevsoft
LunaLua Master Developer
Posts: 83
Joined: 9 years ago

Re: Lua help thread

Post by Kevsoft »

Dog In Da Grass wrote:Is there any witchcraft or science I can do to make the hud disappear?

Code: Select all

hud(false)
User avatar
HatKid
If this ain't a flair, then I don't know what is
Posts: 416
Joined: 9 years ago
Pronouns: she/her
https://hatkid.talkhaus.com/

Re: Lua help thread

Post by HatKid »

Is there any way I could make the background scroll really fast?
Thanks in advance.
Image
User avatar
Ivy
Posts: 2387
Joined: 10 years ago
Pronouns: any
Contact:
https://ivy.talkhaus.com/

Re: Lua help thread

Post by Ivy »

HatKid wrote:Is there any way I could make the background scroll really fast?
Thanks in advance.
That would be interesting; like that one level in SMW?
3DS FC: 2793-0650-7690 | Switch: SW-2766-9108-9399 | Steam: ivysaur1996 (ivy)
User avatar
HatKid
If this ain't a flair, then I don't know what is
Posts: 416
Joined: 9 years ago
Pronouns: she/her
https://hatkid.talkhaus.com/

Re: Lua help thread

Post by HatKid »

Ivy wrote:
HatKid wrote:Is there any way I could make the background scroll really fast?
Thanks in advance.
That would be interesting; like that one level in SMW?
Yes, like that one level .
Image
User avatar
7NameSam
hey
Posts: 248
Joined: 9 years ago
Pronouns: they/them

Re: Lua help thread

Post by 7NameSam »

How do I make a layer move back and forth using LUA?
S1eth
Posts: 291
Joined: 9 years ago

Re: Lua help thread

Post by S1eth »

7NameSam wrote:How do I make a layer move back and forth using LUA?

Code: Select all

local myLayer = findlayer("TheNameYouGaveYourLayerInSMBX");

myLayer.speedX = someNumber; 
myLayer.speedY = someNumber;
You may want to put this into some if block, that uses an incremental counter for each frame, and reset it when the event happens (or use modulo).

Set to speed to e.g. +2 to make it move to the right, and another function to set the speed to -2 to make it move back.
For example, set it to move right at i==0, to move left at i==200, set i=0 at 400.
Image
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Lua help thread

Post by Hoeloe »

S1eth wrote:
7NameSam wrote:How do I make a layer move back and forth using LUA?

Code: Select all

local myLayer = findlayer("TheNameYouGaveYourLayerInSMBX");

myLayer.speedX = someNumber; 
myLayer.speedY = someNumber;
You may want to put this into some if block, that uses an incremental counter for each frame, and reset it when the event happens (or use modulo).

Set to speed to e.g. +2 to make it move to the right, and another function to set the speed to -2 to make it move back.
For example, set it to move right at i==0, to move left at i==200, set i=0 at 400.
Alternatively, you can use the eventu library to do most of the scheduling stuff for you.
Image
Image
Image
Image
Image
S1eth
Posts: 291
Joined: 9 years ago

Re: Lua help thread

Post by S1eth »

Hoeloe wrote:
S1eth wrote:
7NameSam wrote:How do I make a layer move back and forth using LUA?

Code: Select all

local myLayer = findlayer("TheNameYouGaveYourLayerInSMBX");

myLayer.speedX = someNumber; 
myLayer.speedY = someNumber;
You may want to put this into some if block, that uses an incremental counter for each frame, and reset it when the event happens (or use modulo).

Set to speed to e.g. +2 to make it move to the right, and another function to set the speed to -2 to make it move back.
For example, set it to move right at i==0, to move left at i==200, set i=0 at 400.
Alternatively, you can use the eventu library to do most of the scheduling stuff for you.
Is eventu now able to handle multiple events happening on the same tick?

And in general, is there a well organized list of features added since v7? I feel like I have to look through all the forums to find those one at a time.
Image
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: Lua help thread

Post by Hoeloe »

S1eth wrote: Is eventu now able to handle multiple events happening on the same tick?
EventU isn't the same thing as "onEvent", which is a direct SMBX hook. onEvent had some issues in earlier versions not detecting more than one event on a single tick. EventU is a Lua library to create timers and coroutines.
Image
Image
Image
Image
Image
Zygl
Posts: 616
Joined: 11 years ago

Re: Lua help thread

Post by Zygl »

So I have some code to make Rinkas do assorted wAaAaAaAaAacky things at random, like flying at double-speed, flying away from the player, stopping and re-aiming after about a second, etc.
It's merely a proof of concept, of course, half of those are terrible ideas and reverse Rinkas serve like no purpose at all. But if it were to be used in an actual thing, how would one go about making each "flavour" use a different graphic? I looked at cinematX but it apparently doesn't work well with generators which would I imagine be rather important when dealing with Rinkas. And I did notice a few global functions to load graphics that could be used to draw over them but that seems like it'd be a pain given their having four frames of animation?
Rixithechao
https://www.youtube.com/watch?v=BODxOghVmko
Posts: 1812
Joined: 10 years ago
First name: Mack
https://rixithechao.talkhaus.com/

Re: Lua help thread

Post by Rixithechao »

Yeah, generators and cinematX don't mix well. One thing you could do, however, is make your own rinka generators by looping through all instances of a given block and having them call a function that uses NPC.spawn() to generate a rinka with custom behavior.

Here's the code I'm using for my own cinematX-enabled rinka shenanigans as an example:

Code: Select all

rinkaSpeed = 0
rinkaDelay = 0
rinkaStartX = 0
rinkaStartY = 0


function fireRinka (startX, startY, delay, speedMult)
	rinkaStartX = startX
	rinkaStartY = startY
	rinkaDelay = delay or -1
	rinkaSpeed = speedMult or 1
	cinematX.runCoroutine (cor_fireRinka)
end


function cor_fireRinka ()
	local startX = rinkaStartX
	local startY = rinkaStartY
	local spd = rinkaSpeed
	local delay = rinkaDelay
	
	
	-- Spawn the rinka
	local spawnedRinka = NPC.spawn (NPCID.RINKA, startX, startY, player.section)
	
	-- Delay the rinka
	local timePassed = 0
	
	while timePassed < delay  do
		spawnedRinka:mem (0xF8, FIELD_DFLOAT, 10)
		cinematX.waitSeconds(0.0)
		timePassed = timePassed + cinematX.deltaTime
	end
	
	-- Fire the rinka
	spawnedRinka:mem (0xF8, FIELD_DFLOAT, 100)
	
	cinematX.waitSeconds(0.0)
	spawnedRinka.speedX = spawnedRinka.speedX * spd
	spawnedRinka.speedY = spawnedRinka.speedY * spd
	
	return spawnedRinka
end
If you want to make different variants with different graphics, you'll need to get the cinematX actors of each rinka via its' UID and override the animation. Keep all the different animations in the sheet for the rinkas and set each variant to have a different animation state.

Code: Select all

-- Loop through all rinkas
for key,value in pairs (NPC.get(NPCID.RINKA, -1)) do
    -- Get the UID
	local uid = value:mem (cinematX.ID_MEM, FIELD_WORD);

	-- Get the actor reference and override the animation
	local thisActor = cinematX.indexedActors[uid]
	thisActor:overrideAnimation (animData_Rinka)
	
	-- Determine the animation state based on certain parameters
	if		()		then
		thisActor:setAnimState (variation A)
	elseif	()		then
		thisActor:setAnimState (variation B)
	elseif	()		then
		thisActor:setAnimState (variation C)
	else
		thisActor:setAnimState (variation D)
	end
end
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