(shouting)

LunaLua Help

User avatar
Isrieri
Creatively Bankrupt
Posts: 95
Joined: 11 years ago
Pronouns: Male

Re: LunaLua Help

Post by Isrieri »

Okay lets get cracking!

I want to make a level based around the Starman, but I also want to try making some modifications to it's code (specifically, add a counter for after the music loops end and make use of the Colliders API), I think I understand what's going on for most of it, but some of the functions I have no clue what they do. For instance in starman.onTick there's something called NPC.getIntersecting. Is that for when mario picks up the star?

Another thing I tried to figure out last night is how to make Mario's fireballs shoot correctly (have only two on-screen at a time, with no timer in-between firing, and a change to their x-speed). But when I first tried it I didn't know what function or API I could use to count the fireballs in Mario's current section. I tried NPC.get but it returned some hex values, and NPC.count, which I couldn't figure out. I don't know what arguments .count takes, if any.


EDIT: Alright, I figured out the fireballs, but they persist while offscreen. I figure, I'll just find the screen coordinates and kill the npcs when they're about 4 blocks out, but I don't know how player.screen works. Its a RECT type and I went to look it up. Seems like its a function that returns the four boundary values? But whenever I try to use it I get "==> no such operator defined". Do I have to define a new RECT using player.screen? I'm clueless.
User avatar
Isrieri
Creatively Bankrupt
Posts: 95
Joined: 11 years ago
Pronouns: Male

Re: LunaLua Help

Post by Isrieri »

Okay! I finally figured all that fireball jazz out. It works in the level just fine. So I tried to put it into it's own API, but then I get this error:

Image

I went to mainV2.lua to check it out, but it looks as though its just defining the events for each API. I think it may be that I have to return some data from the API to the host level file but I don't know what needs to be returned.

Code:

Code: Select all

local properFireballs = {}

function properFireballs.onTick()
	local fireballs = NPC.get(13,player.section);
	local iceballs = NPC.get(265,player.section);
	local hammers = NPC.get(171,player.section);
	
	for _, v in pairs(fireballs) do	
		local offscreen = v:mem(0x128,FIELD_WORD)
		if offscreen == -1 then 
			v:mem(0x12A,FIELD_WORD,0)    --If shots are offscreen, set despawn to instant
		end
		if v.direction > 0 then
			v.speedX = 8
			else if v.direction < 0 then
				v.speedX = -8
			end
		end
		if fireballs[2] == nil then    --Checks if second index is filled for player section
		player:mem(0x160,FIELD_WORD,0)
		else
			player:mem(0x160,FIELD_WORD,1)
		end
	end
	
	for _, v in pairs(iceballs) do	
		local offscreen = v:mem(0x128,FIELD_WORD)
		if offscreen == -1 then
			v:mem(0x12A,FIELD_WORD,0)
		end
		if v.direction > 0 then
			v.speedX = 5.6
			else if v.direction < 0 then
				v.speedX = -5.6
			end
		end
		if iceballs[2] == nil then
			player:mem(0x160,FIELD_WORD,0)
		else
			player:mem(0x160,FIELD_WORD,1)
		end
	end
	
	for _, v in pairs(hammers) do	
		local offscreen = v:mem(0x128,FIELD_WORD)
		if offscreen == -1 then
			v:mem(0x12A,FIELD_WORD,0)
		end
		if hammers[2] == nil then
			player:mem(0x160,FIELD_WORD,0)
		else
			player:mem(0x160,FIELD_WORD,1)
		end
	end
end
	
function properFireballs.onInitAPI()
	registerEvent(properFirealls,"onTick","onTick")
end

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

Re: LunaLua Help

Post by Hoeloe »

Isrieri wrote:registerEvent(properFirealls,"onTick","onTick")
Isrieri wrote:properFirealls
Isrieri wrote:Firealls
Isrieri wrote:alls
Be sure to check your spelling
Image
Image
Image
Image
Image
User avatar
Isrieri
Creatively Bankrupt
Posts: 95
Joined: 11 years ago
Pronouns: Male

Re: LunaLua Help

Post by Isrieri »

Oh my god, that was actually it. I'm so pissed at myself.

Thank you, Hoeloe! Now I know what to do if that error shows up again.
KittyTristy
Posts: 4
Joined: 7 years ago
Location: USA

Re: LunaLua Help

Post by KittyTristy »

.
Last edited by KittyTristy 5 years ago, edited 1 time in total.
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaLua Help

Post by Hoeloe »

KittyTristy wrote:No matter what I do, I can't get cinematX to work. I've followed the wiki and examples I've seen, and it just doesn't work at all. :/

Does anyone have any levels using cinematX that are working with SMBX 2.0 that I could take a look at?
CinematX is very old and broken and never quite worked properly. It's really not recommended to even try using it.
Image
Image
Image
Image
Image
KittyTristy
Posts: 4
Joined: 7 years ago
Location: USA

Re: LunaLua Help

Post by KittyTristy »

.
Last edited by KittyTristy 5 years ago, edited 1 time in total.
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaLua Help

Post by Hoeloe »

KittyTristy wrote: Ah. Well it was included with SMBX 2.0 and it's on the wiki so it didn't really seem like that way when I was looking around about it. Oh well. Thanks anyways. :3

It's been kept in for compatibility, but really you shouldn't be using it. There are some tools to do what it does in separate forms. The event scheduling is now part of eventu.lua, there's a simple "follower" script used by Bowser to replicate follower behaviour, pnpc.lua deals with keeping track of and modifying NPCs, and textblox.lua can deal with extra text printing (though that one is undergoing renovation at the moment). There's also imagic.lua, which can be used for drawing things like text boxes and speech bubbles should you want to.
Image
Image
Image
Image
Image
KittyTristy
Posts: 4
Joined: 7 years ago
Location: USA

Re: LunaLua Help

Post by KittyTristy »

.
Last edited by KittyTristy 5 years ago, edited 1 time in total.
KittyTristy
Posts: 4
Joined: 7 years ago
Location: USA

Re: LunaLua Help

Post by KittyTristy »

.
Last edited by KittyTristy 5 years ago, edited 1 time in total.
User avatar
Camwood777
oh man what
Posts: 14
Joined: 7 years ago
First name: Cam
Pronouns: he/him/his
Location: the land of tong-nou

Re: LunaLua Help

Post by Camwood777 »

For whatever reason, I can't get midpoints to work at all. I tried looking it up on the wiki, and it tells me to use multipoints.lua, so I guess it's a Lunalua thing.

At the same time, though, that raises more issues; Lunalua won't even open for me! It tells me to select a program... Can someone help me out here?
also goes by "camwoodstock", "camwood", "cws", or some variant thereof
plays video games i think
User avatar
ztarwuff
What the heck is a flair and why am I being asked to write one for my profile?
Posts: 550
Joined: 10 years ago
Location: Within 2 miles of the Imperial Crypt of Napoleon III

Re: LunaLua Help

Post by ztarwuff »

Camwood777 wrote:For whatever reason, I can't get midpoints to work at all. I tried looking it up on the wiki, and it tells me to use multipoints.lua, so I guess it's a Lunalua thing.

At the same time, though, that raises more issues; Lunalua won't even open for me! It tells me to select a program... Can someone help me out here?
Oh midpoints! Yes, midpoints are very easy.

The .lua files are basically just text documents. The notepad program that comes bundled with Windows can open them, but it's probably a better idea to get a free version of Notepad++. Notepad++ colour codes your lua code as you go along.

You'll need to create a .lua file called lunadll.lua in your level folder. Notepad doesn't give you the option, so you have to select all files, then type in lunadll.lua. NotePad++ however, does give you the option of saving as a .lua.

Here's a sample from one of my levels submitted to A2XT Episode 2:

Code: Select all

local multipoints = loadAPI("multipoints");

multipoints.addLuaCheckpoint(-19809, -20064, 9);
multipoints.addLuaCheckpoint(-199296, -200063, 0);
You need the first line to load the Multipoints API. The third and fourth lines are the midpoints. The numbers in the brackets are your coordinates: X, Y and Section Number. You get the X and Y coordinates from the debugger. Just switch the debugger on, and hover your mouse over where you want the midpoint goes. Write down the coordinates the debugger gives you. The section number is always one less than the actual one.

So in the above example, I have a midpoint in Section 10 and Section 1.
User avatar
Tyty
Posts: 50
Joined: 13 years ago

Re: LunaLua Help

Post by Tyty »

But of an odd question. Is there a way to draw something behind the player without putting it on their sprite sheet? Basically I'd like to imitate how the cape animates in SMW on a custom character, so it can animate independently and be drawn regardless of powerup state.
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaLua Help

Post by Hoeloe »

Tyty wrote: 7 years ago But of an odd question. Is there a way to draw something behind the player without putting it on their sprite sheet? Basically I'd like to imitate how the cape animates in SMW on a custom character, so it can animate independently and be drawn regardless of powerup state.
Absolutely! Take a look at the render priority system: http://wohlsoft.ru/pgewiki/LunaLua_Render_Priority

Certain functions in LunaLua allow you to supply a priority. Most priority levels are negative, and if you use a priority below the player (that's more negative than -25) when drawing with Lua, you can draw things behind the player.
Image
Image
Image
Image
Image
Noodle
AKA Stingy
Posts: 56
Joined: 6 years ago
Pronouns: I/me/mine
Location: In LazyTown

Re: LunaLua Help

Post by Noodle »

I want to make a level where things generate at random. There will be a total of 10 random screens generated horizontally before the flagpole and all pipes generated lead to a normal underground bonus section. When they come back up, the flagpole is there immediately.
User avatar
Ittababy
Posts: 13
Joined: 10 years ago

Re: LunaLua Help

Post by Ittababy »

I've re-skinned Ludwig and would like to have him throw hammers instead of fireballs. I feel like a total dope, not knowing this when it seems basic.
A very shy ghost.
User avatar
Nimono
Posts: 745
Joined: 11 years ago

Re: LunaLua Help

Post by Nimono »

Is it possible to check if the player/game is in a frozen state from powering down? I'm manipulating layers with LunaLua using an in-code timer, but if the player takes damage, the layers stop but the timer keeps running, massively desynching things. I need to make the timer stop if the player's unable to take action, but I'm struggling to find out how to do this through the wiki
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaLua Help

Post by Hoeloe »

Layer.isPaused() will do what you need.
Image
Image
Image
Image
Image
User avatar
Nimono
Posts: 745
Joined: 11 years ago

Re: LunaLua Help

Post by Nimono »

Hoeloe wrote: 4 years ago Layer.isPaused() will do what you need.
Ah! I managed to miss that. Thank you, Hoeloe!
User avatar
LunarNeedle
The Golden Spork
Posts: 51
Joined: 11 years ago
First name: Matthew
Location: Canada, Canada

Re: LunaLua Help

Post by LunarNeedle »

This might be really dumb, but what are some ways a player can cause a change in a Lua variable (preferably boolean) through the players own actions like killing an NPC, hitting a block, standing on a certain block, a SMBX event, or anything. The best I have is to count the plunger NPC every frame and when the count goes down, trigger the change in the variable; which is less than ideal considering the wiki suggests making variables off of NPC.count() local only or there will be problems.

Never thought this would be the problem, but it might be coming from my inexperience with PGE and the engine overall. :oops:
"All these flavors and you choose to be salty"
- Grandma
User avatar
Emral
Posts: 940
Joined: 10 years ago
https://enjl.talkhaus.com/

Re: LunaLua Help

Post by Emral »

https://wohlsoft.ru/pgewiki/LunaLua_events
Check out some of these. They get triggered on certain conditions. onNPCKill and onEvent are particularly interesting. "eventObj" (the first argument) in onNPCKill refers to the event of the NPC dying, not the SMBX event it might invoke.
There's also onMessageBox and onBlockHit(eventObj, hitBlock, fromUpper?, playerOrNil), and onNPCHarm(eventObj, killedNPC, killReason, culpritOrNil) which trigger when their name suggests.

For standing on a particular block it's best to do a player:isGroundTouching() check and, if that passes, check if there's the desired block below the player using a for loop over Block.getIntersecting(left, top, right, bottom)
I do things. You can find them on my talkhaus site. https://enjl.talkhaus.com/
Here is another link. This one lets you draw.
https://enjl.talkhaus.com/draw.html
User avatar
Nimono
Posts: 745
Joined: 11 years ago

Re: LunaLua Help

Post by Nimono »

I'm assuming this is possible, but I can't figure out how... How do I get the angle between two points? As far as I can tell, Lua doesn't have atan2. Is it through the VectR library? Will the dot product of two vector2 vectors produce the direction I seek, or am I barking up the wrong tree? For full context: I'm wanting to make a function that will check if a player is within a specific range of an NPC, but the checks get blocked by solid tiles. ...come to think of it, just finding the angle alone wouldn't be enough- I'd still need sine and cosine functions, too, to get X and Y positions out of the degree/radian... Hrm. Maybe right now this sort of thing isn't possible in SMBX2?
User avatar
Draexzhan
Flair text
Posts: 208
Joined: 8 years ago
First name: Nathan
Pronouns: he/him/his
Location: Undertale

Re: LunaLua Help

Post by Draexzhan »

Lua does have atan2. It's math.atan2
Signature text.
User avatar
Nimono
Posts: 745
Joined: 11 years ago

Re: LunaLua Help

Post by Nimono »

Draexzhan wrote: 4 years ago Lua does have atan2. It's math.atan2
Ah, thanks. I thought that the math API wasn't built-in, but I guess I was wrong! Now I'm trying to debug this code and figure out why it's not giving me the right angle :/

Code: Select all

local ang = math.atan2(player.x-ax, player.y-ay);
NPC.spawn(137, player.x + (96 * math.cos(ang)), player.y + (96 * math.sin(ang)), 7);
This should be spawning a stunned bob-omb between ax,ay (the location of another NPC), and player.x, player.y, but whether I tell it to spawn using ax,ay as an origin or player.x,player.y as an origin, have the Y first in atan2, or flip it around so it's ax-player.x, ay-player.y, the result's the same: it spawns at an incorrect location.
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaLua Help

Post by Hoeloe »

You might find this easier to do with vectors.

From what it looks like, you're trying to spawn an NPC part way between the player and some other object, right?

Doing this with vectors is pretty simple:

Code: Select all

local direction = vector(player.x-ax, player.y-ay):normalize()

NPC.spawn(id, player.x + dist*direction.x, player.y + dist*direction.y, player.section)
Is the basic gist.
Image
Image
Image
Image
Image
Post Reply