Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Aug 11, 2021 11:56 am

A lot to unpack here...
Wiimeiser wrote:
Wed Aug 11, 2021 9:00 am
The problem is that when I enter the rocket, it turns into a white square
White square is the default thing that's drawn if no texture is provided. Sounds like you're missing the image file it tries to draw.
Wiimeiser wrote:
Wed Aug 11, 2021 9:00 am
or change it to "false" the rocket instead turns invisible when activated.
sceneCoords, as the name implies, causes the coordinates of the draw function to be interpreted as scene-coords, rather than screen-coords. If you toggle it, now it's invisible because the square is drawn somewhere offscreen instead. More about sceneCoords on both the old documentation for glDraw, as well as the current documentation glDraw, drawBox, drawCircle, and drawScreen, which all use similar sets of arguments. You won't find this info on the handbook because it existed and was documented long before the handbook was made. The handbook is also largely deprecated at this point and replaced by docs.codehaus.moe.
Wiimeiser wrote:
Wed Aug 11, 2021 9:00 am
I have issues with grid snapping/anchoring
The editor's grid alignment for objects of sizes nondivisible by 16 outright sucks
Wiimeiser wrote:
Wed Aug 11, 2021 9:00 am
the * next to the filename
... indicates that there are unsaved changes, but in the most recent patch was a rather new addition and sometimes shows when no unsaved changes are there
Wiimeiser wrote:
Wed Aug 11, 2021 9:00 am
as well as with saving bookmarks on the world map
I never used the bookmark feature so I can't comment on this. I'm sure that sounds like a bug that's just not on Wohlstand's radar cause the feature is so underused.
Wiimeiser wrote:
Wed Aug 11, 2021 9:00 am
The filename "World.bY8hqLY5OLEq.wld.meta" seems abnormal to me
That's a world map bookmark file.

Wiimeiser
Snifit
Snifit
Posts: 215
Joined: Mon Jun 24, 2019 4:36 am
Flair: What?

Re: Need help with lua? - LunaLua General Help

Postby Wiimeiser » Wed Aug 11, 2021 8:21 pm

I found out what's going on with the bookmarks- Whenever I save the map file it creates a new one of those files, but it doesn't read from them or update the correct file.

With the * it appears when I save if there were previously unsaved changes before doing so, and disappears if the level hadn't been modified since the previous save.
Enjl wrote: White square is the default thing that's drawn if no texture is provided. Sounds like you're missing the image file it tries to draw.
That's exactly what I thought. It's still happening in a new episode even if I don't modify any of the rocket's data. Is it working for you when you try? What about the Boost Bubble? Based on some experimentation just now, it seems "Graphics.drawImageToSceneWP(bubbleImage" does not return a valid image file while "Graphics.drawImageToSceneWP(Graphics.loadImageResolved("bubble.png")" does. Changing "local sprite = Graphics.loadImage("npc-762.png")" to local sprite = "Graphics.loadImageResolved("npc-762.png")" did in fact appear to fix it, though, so not sure what's going on there. In fact, just adding "Resolved" to the Boost Bubble fixed that, too...

Also, I seem to be having a problem in my main episode where if I use a potion door to move to a section with a higher number, I appear above the section and fall down. This isn't happening in my test episode, so it's most likely some code I installed somewhere along the line. Could even be Rooms.lua even though it's not loaded in the level this is happening in. EDIT: It seems to be just the one level, so I have no idea what's going on here...

EDIT: I seem to be cursed. Brown Klaptraps were killing me from literally a screen to the right of them. I did kind of fix it by changing this:

Code: Select all

data.hitbox = colliders.Box(v.x, v.y, 448, v.height)
to this:

Code: Select all

data.hitbox = colliders.Box(v.x, v.y, 32, v.height)
But the fact lua on my end is messing up this badly means something in this room belongs in some SCP containment facility...

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Thu Aug 12, 2021 2:30 am

Wiimeiser wrote:
Wed Aug 11, 2021 8:21 pm
I found out what's going on with the bookmarks- Whenever I save the map file it creates a new one of those files, but it doesn't read from them or update the correct file.
Best to report that to Wohlstand, then.
Wiimeiser wrote:
Wed Aug 11, 2021 8:21 pm
What about the Boost Bubble? Based on some experimentation just now, it seems "Graphics.drawImageToSceneWP(bubbleImage" does not return a valid image file while "Graphics.drawImageToSceneWP(Graphics.loadImageResolved("bubble.png")" does.
Ergh... alright, so. What I gather from that sentence alone is that the affected packs expect you to deposit the files in a level folder, but you deposited them in an episode folder. Graphics.loadImage only looks in the level folder, while loadImageResolved looks in the episode folder as well.
That said, DON'T CALL LOADIMAGERESOLVED IN THE DRAW CALL. That'll load the image every frame, which is not fun for performance. Replacing all references to loadImage with loadImageResolved should do the trick.
Wiimeiser wrote:
Wed Aug 11, 2021 8:21 pm
EDIT: I seem to be cursed. Brown Klaptraps were killing me from literally a screen to the right of them. I did kind of fix it by changing this:

Code: Select all

data.hitbox = colliders.Box(v.x, v.y, 448, v.height)
This just looks like the creator accidentally typed 448 for the hitbox width rather than 48.
There are no curses going on here. Everything you've shared so far makes perfect sense.
Wiimeiser wrote:
Wed Aug 11, 2021 8:21 pm
Could even be Rooms.lua even though it's not loaded in the level this is happening in
No, it cannot. Because it's not loaded. Hard to debug this one without more information.

wyldstrykr
Buster Beetle
Buster Beetle
Posts: 84
Joined: Mon May 31, 2021 11:20 pm

Re: Need help with lua? - LunaLua General Help

Postby wyldstrykr » Fri Sep 10, 2021 10:13 pm

is there a way to check if the player choose to restart via menu?

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Sun Oct 31, 2021 2:24 am

How do I teleport the player? I keep getting an error message even though I type:

player.teleport(myX,myY,false)

Am I doing something wrong? Or is this the wrong code?

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 544
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Marioman2007 » Sun Oct 31, 2021 8:34 am

LunarCatUSA wrote:
Sun Oct 31, 2021 2:24 am
How do I teleport the player? I keep getting an error message even though I type:

player.teleport(myX,myY,false)

Am I doing something wrong? Or is this the wrong code?
player:teleport(myX, myY, false)

Methods (like this one) use colon rather than a dot.

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Sat Nov 06, 2021 12:56 am

How do I make the section music return to normal after using the “Audio.SeizeStream” function?

I go:
> Event
Audio.SeizeStream()
Audio.MusicOpen()
Audio.MusicPlay()
> Another Event
Audio.MusicStop
Audio.ReleaseStream

But for some reason, it stays silent after I release the stream. Anyone know what I can to make it return to the section music?

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sat Nov 06, 2021 8:32 am

Seems you're missing parentheses on those last two functions.

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Sat Nov 06, 2021 9:43 am

Well I do have the parenthesis in the code, I just forgot to put them there in the comment.

Code: Select all

if eventName == "Enemy Encounter" then
		Audio.SeizeStream(-1)
		Audio.MusicOpen("MyMusic.mp3")
		Audio.MusicPlay()
	end
And then it should go to

Code: Select all

if eventName == "Enemy Defeat" then
		Audio.MusicStopFadeOut(1000)
		Audio.ReleaseStream(-1)
	end
After this, it's stuck in complete silence, unable to return to the original section music.

ChunkyChimp
Spiny
Spiny
Posts: 26
Joined: Tue Sep 01, 2020 9:02 pm
Flair: I TAKE GFX FOR MY OWN LEVELS

Re: Need help with lua? - LunaLua General Help

Postby ChunkyChimp » Sun Nov 07, 2021 12:57 am

How do I embed an image in textplus? Is it <../file/> or <img=file> or something else?

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Tue Nov 09, 2021 12:27 pm

Is there anyway I can get or reference an NPC by it's array ID as opposed to its NPC ID? I'm asking because I want to reference an NPC that triggers an event/script when you talk to him.

deice
Rocky Wrench
Rocky Wrench
Posts: 625
Joined: Fri Jul 23, 2021 7:35 am

Re: Need help with lua? - LunaLua General Help

Postby deice » Tue Nov 09, 2021 1:02 pm

LunarCatUSA wrote:
Tue Nov 09, 2021 12:27 pm
Is there anyway I can get or reference an NPC by it's array ID as opposed to its NPC ID? I'm asking because I want to reference an NPC that triggers an event/script when you talk to him.
yes, you can grab an NPC's array index through the field "idx". raw access to the npc array can be performed either by doing NPC(index) or you can just iterate through all of the NPCs and stop at the one which has a matching index. (the latter might be preferable, as the new documentation doesn't list the former, indicating that it could be deprecated)

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Tue Nov 09, 2021 1:43 pm

LunarCatUSA wrote:
Tue Nov 09, 2021 12:27 pm
Is there anyway I can get or reference an NPC by it's array ID as opposed to its NPC ID? I'm asking because I want to reference an NPC that triggers an event/script when you talk to him.
I believe the onMessageBox event passes the NPC you talk to as its fourth parameter
function onMessageBox(eventToken, message, player, npcOrNil)

So you could, for instance, have the NPC say a keyword like "talkEvent1" and then you check if message == "talkEvent1" and you cancel the eventToken in that conditional and then do something with your npc reference.

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Tue Nov 09, 2021 3:38 pm

Enjl wrote:
Tue Nov 09, 2021 1:43 pm
LunarCatUSA wrote:
Tue Nov 09, 2021 12:27 pm
Is there anyway I can get or reference an NPC by it's array ID as opposed to its NPC ID? I'm asking because I want to reference an NPC that triggers an event/script when you talk to him.
I believe the onMessageBox event passes the NPC you talk to as its fourth parameter
function onMessageBox(eventToken, message, player, npcOrNil)

So you could, for instance, have the NPC say a keyword like "talkEvent1" and then you check if message == "talkEvent1" and you cancel the eventToken in that conditional and then do something with your npc reference.
Ah well, I might as well explain my intention:

Image

Image

I want to try and capture the message the NPC will say when you talk to them so that they player will know what they said and be ablet to respond with dialogue options. Obviously, the simple function is myNpc = npc.get() and myNpc.msg to retrieve what they say, but I wish to know if I can do it with just any NPC really instead of having to make separate event codes for each character who will have a full-on conversation with you.

Code: Select all

Speak = false
Availableoptions = {}
Availableresponses = {}
Converse = nil
Talkstage = 0
Achoice = nil
Goomba1ResponseA = {"Thanks!","Okay","Screw you","Goodbye"}
Goomba1ReactA = {"You're welcome, jerk!","No, not okay...","No, screw YOU good sir.","Bye"}

Code: Select all

-- Dialogue/Convos --
	if Speak == true then
		if Converse == Goomba1 and Talkstage == 0 then
			Text.print(MyLine,4,90,90)
			Availableresponses = Goomba1ResponseA
			for index,displayedresponses in ipairs(Availableresponses) do
				Text.print(displayedresponses,90,120+(index*30-30))
				Availableoptions[index] = DialogueOptions[index]
				Graphics.draw{
				type = RTYPE_IMAGE,
				image = Availableoptions[index],
				x = 60,
				y = 120+(index*30-30),
				priority = 5,
				}
			end
		end
		if Converse == Goomba1 and Talkstage == 1 then
			Text.showMessageBox(Goomba1ReactA[Achoice])
			triggerEvent("DialogueEnd")
		end
	end
end
function onKeyboardPress(KEY)
	if KEY == 49 and Speak == true then
		Achoice = 1
		Talkstage = Talkstage + 1
	end
	if KEY == 50 and Speak == true and Availableoptions[2] then
		Achoice = 2
		Talkstage = Talkstage + 1
	end
	if KEY == 51 and Speak == true and Availableoptions[3] then
		Achoice = 3
		Talkstage = Talkstage + 1
	end
	if KEY == 52 and Speak == true and Availableoptions[4] then
		Achoice = 4
		Talkstage = Talkstage + 1
	end
	if KEY == 53 and Speak == true and Availableoptions[5] then
		Achoice = 5
		Talkstage = Talkstage + 1
	end
end
I want to try to advance the dialogue through talkstages and what not, but I imagine there's a better function.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Tue Nov 09, 2021 3:57 pm

You could for instance use extra settings in a global_npc.json to give every npc a new boolean called v.data._settings._global._hasDialogue as well as a text field for a string of responses _responses and reactions _reactions
https://docs.codehaus.moe/#/concepts/extra-settings

Code: Select all


local reactions = {}
local shownText = ""
local inDialogue = false
local chosenReactionIndex = 0

local function dialogueRoutine(npc)
     inDialogue = true
     local responses = {}
     -- string split the response and reaction strings and sort them into the reactions and responses variables
     shownText = npc.msg
     -- Show the message and response prompts
     Routine.waitSignal("optionChosen")
     shownText = responses[chosenReactionIndex]
     Routine.waitSignal("advanceText")
     inDialogue = false
end

function onMessageBox(event, message, _, npc)
    if npc and npc.data._settings._global._hasDialogue then
        Routine.run(dialogueRoutine, npc)
        event.cancelled = true
    end
end
Then you just need to disable regular player input (setting player.keys variables to false in onTick and restoring in onTickEnd), draw the menu (onDraw) and handle your own input (I recommend making a navigatable menu instead of using onKeyboardPress, because the latter doesn't work for controller users).
Selecting a response would call Routine.signal("optionChosen") and set chosenReactionIndex, and advancing text would call Routine.signal("advanceText")

The way this works is by starting a routine when such a dialogue tree is initiated. It's pretty limited in this quickly-in-a-forum-post-made sample, but it's fairly compact and can be expanded if need be.

Hope this helps. Should you have any questions I can go into more detail. I realize it's somewhat difficult to wrap one's head around and I might have explained the idea dreadfully.

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Tue Nov 09, 2021 4:52 pm

Okay, and I take it I get one of these .JSON files from the data file?
And then I put it either in the episode folder or level folder depending on which NPCs I want it to affect on which scale?

(Sorry if I seem confused right now, I best learn from example)

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Tue Nov 09, 2021 5:08 pm

LunarCatUSA wrote:
Tue Nov 09, 2021 4:52 pm
Okay, and I take it I get one of these .JSON files from the data file?
And then I put it either in the episode folder or level folder depending on which NPCs I want it to affect on which scale?

(Sorry if I seem confused right now, I best learn from example)
A json file by the name of global_npc.json in the episode folder will act as extra settings for EVERY npc id in your episode.
For example, the a2xt2 devkit comes with this one, which integrates with the devkit's message system to change things like the message box style.
https://www.toptal.com/developers/haste ... uvoyi.json
... which then shows up like this:
Image

And exposes the following variables in the code, assuming v is any npc:
v.data._settings._global.talkName (string)
v.data._settings._global.talkIcon (enum)
v.data._settings._global.messageBoxStyle (enum)
v.data._settings._global.noTurn (bool)
v.data._settings._global.talkRoutine (string)
v.data._settings._global.towns.isBuried (bool)
v.data._settings._global.towns.saveDeathKey (string)
v.data._settings._global.towns.utilityType (enum)

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Tue Nov 09, 2021 6:05 pm

Image

Alright, made a global_npc.json file and a dialogue boolean. Now regarding the file of string options and responses, do I just make a separate Lua file in my episode folder? And then after that, I suppose I take the code you made and apply it to my global code?

Added in 46 minutes 49 seconds:
Also, if it's not too much trouble, I would like to know how to build a menu that one can use the arrow keys or mouse for.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Nov 10, 2021 12:14 pm

Eh... apologies but I may have misunderstood the scope at play here. If I get more specific we might be here for weeks, hah.

Littledialogue.lua has basically what you're looking for, so you might wanna check that out. It won't teach you how to do all of this on your own, of course, but it's a quick way to get a good result going. I don't have a tutoring session in me at the moment, sorry.

LunarCatUSA
Monty Mole
Monty Mole
Posts: 115
Joined: Sat Mar 06, 2021 9:56 am
Flair: Soda-Butler

Re: Need help with lua? - LunaLua General Help

Postby LunarCatUSA » Wed Nov 10, 2021 12:19 pm

I understand, I won't keep ya. I'll give that a look. Thanks for the help.

Added in 52 minutes 44 seconds:
YOOOOOO! I'm loving this so far! I can make character portrait animations and selectable dialogue options. This is amazing!


Return to “LunaLua Help”

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari