Page 24 of 27
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 30, 2022 12:06 pm
by Marioman2007
LunarCatUSA wrote: ↑Mon May 30, 2022 10:05 am
Okay, and to clarify;
It should be under "OnTick()" and I use the function "player.frame = 48"?
Yes, under onTick() or onDraw().
And you should do
Code: Select all
player.frame = 48 * player.direction
Or
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 30, 2022 12:12 pm
by Enjl
onTick is a bad idea because onTick runs before the internal code sets the animation frame. onTickEnd is better because it runs after, onDraw ideal.
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 30, 2022 12:26 pm
by LunarCatUSA
Okay so good news!
I used:
Code: Select all
function onDraw()
-- Player Stunned --
if ouch == true then
player:setCurrentSpriteIndex(0,0,false)
end
Thing is, this is working for the character when they face the right. I just need to make it the sprite for when they face the left. At least the sprite is now loading, so that's good.
Added in 24 minutes 2 seconds:
Okay so I made it like...
Code: Select all
function onDraw()
-- Player Injured --
if ouch == true and player.direction == 1 then
player:setCurrentSpriteIndex(0,0,false)
end
if ouch == true and player.direction == -1 then
player:setCurrentSpriteIndex(0,1,false)
end
The problem is that the left sprite doesn't spawn and instead the player model disappears/blinks out of existence before going back to normal. The sprite can load no problem so am I calling the left direction incorrectly?
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 31, 2022 1:40 pm
by Hoeloe
Why are you not doing what you've been told to? Just set player.frame, no need to mess with setCurrentSpriteIndex.
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 31, 2022 5:02 pm
by krakin
Hoeloe wrote: ↑Tue May 31, 2022 1:40 pm
Why are you not doing what you've been told to? Just set player.frame, no need to mess with setCurrentSpriteIndex.
Maybe because not everyone is a LunaLua genius?
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 31, 2022 6:33 pm
by deice
krakin wrote: ↑Tue May 31, 2022 5:02 pm
Maybe because not everyone is a LunaLua genius?
they're not even being asked to intuit anything? they've clearly been told to use the frame field but instead opted for a different method without articulating why they chose not to use what they've already been explained. hoeloe's question seems fairly genuine, and i'm not sure how you could interpret it as condescending.
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 31, 2022 7:06 pm
by LunarCatUSA
Hoeloe wrote: ↑Tue May 31, 2022 1:40 pm
Why are you not doing what you've been told to? Just set player.frame, no need to mess with setCurrentSpriteIndex.
Because it hasn't been working for me. That's why I needed to use setCurrentSpriteIndex instead.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Jun 01, 2022 12:02 pm
by Hoeloe
LunarCatUSA wrote: ↑Tue May 31, 2022 7:06 pm
Hoeloe wrote: ↑Tue May 31, 2022 1:40 pm
Why are you not doing what you've been told to? Just set player.frame, no need to mess with setCurrentSpriteIndex.
Because it hasn't been working for me. That's why I needed to use setCurrentSpriteIndex instead.
That means you were doing something else wrong. Setting player.frame is effective.
Re: Need help with lua? - LunaLua General Help
Posted: Thu Jun 02, 2022 11:22 am
by LunarCatUSA
Great news everyone!
I figured out the player.frame thing. Turns out, the model was just in the incorrect direction on the spritesheet.
So now, it's all working. Thanks again.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jun 05, 2022 10:09 pm
by LunarCatUSA
If it's not too much trouble, how would I go about making an NPC fly around in a circle clockwise? Do I need to do something like:
Code: Select all
v.speedX = math.sin(2*math.pi)
v.speedY = math.sin(2*math.pi)
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 06, 2022 6:21 am
by Enjl
LunarCatUSA wrote: ↑Sun Jun 05, 2022 10:09 pm
If it's not too much trouble, how would I go about making an NPC fly around in a circle clockwise? Do I need to do something like:
Code: Select all
v.speedX = math.sin(2*math.pi)
v.speedY = math.sin(2*math.pi)
Remember that a sine is something that expresses a motion over time, so you need some form of time variable in the equation. You might also want to modulate the motion with a frequency (speed of going along the circle) and amplitude (radius of the circle).
Code: Select all
v.speedX = math.sin(lunatime.time() * frequency) * amplitude
v.speedY = math.cos(lunatime.time() * frequency) * amplitude
The above solution has the potential to drift, because of rounding issues. So what I tend to do is treat the sine/cosine as positions on the circle the NPC should move along, rather than the speed necessary follow it:
Code: Select all
local oldX = v.x - v.spawnX
local oldY = v.y - v.spawnY
local newX = math.sin(lunatime.time() * frequency) * amplitude
local newY = math.cos(lunatime.time() * frequency) * amplitude
v.speedX = newX - oldX
v.speedY = newY - oldY
v.spawnX and v.spawnY are the spawn coordinates of the NPC, but those are also just numbers and can be swapped out with an origin point of your own definition.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 06, 2022 12:43 pm
by LunarCatUSA
Okay, thanks.
Also, is there any way I can prevent my NPC from facing the other direction when going upwards?
Like, say I wanted to have it face only the left side of the screen while it's going in circles. (It has 8 frames, 4 frames for one side, 4 for the other with a framestyle = 1)
Added in 11 hours 53 minutes 1 second:
Say I wanted an NPC to remain in its first frame or a 'Dormant' frame until the player comes within a certain x-axis proximity to them. Then its full animation plays and at the end of the animation, it transforms into a hostile, moving enemy. I know how to use the v:transform(someNpc) function, I just want to know how I can keep it in the first frame until the player gets close enough to it.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Jun 07, 2022 3:07 pm
by LunarCatUSA
Instead of making a dormant npc frame, I wonder, is it possible to make an effect for an NPC? Make the npc a single framed one and then give it an effect gif before transforming it into another npc?
Re: Need help with lua? - LunaLua General Help
Posted: Tue Jun 07, 2022 3:50 pm
by deice
LunarCatUSA wrote: ↑Tue Jun 07, 2022 3:07 pm
Instead of making a dormant npc frame, I wonder, is it possible to make an effect for an NPC? Make the npc a single framed one and then give it an effect gif before transforming it into another npc?
you could render the npc invisible for a fixed period of time, spawn the effect at it's location, then transform it. your other idea could also work, you just have to set the npc's "animationFrame" field to whichever frame you want it to be stuck on (zero-based, so the frame at the very top of the sprite is animation frame 0, the one below is 1, etc.).
Re: Need help with lua? - LunaLua General Help
Posted: Tue Jun 07, 2022 7:25 pm
by LunarCatUSA
Alright well I made an effect.png and an effect.txt file with the latter having all correct gfxwidth, gfxheight, frames, and framespeed. Is there anything else I need for when I use the Effect.spawn(946,xpos,ypos)?
Added in 2 hours 25 minutes 41 seconds:
deice wrote: ↑Tue Jun 07, 2022 3:50 pm
LunarCatUSA wrote: ↑Tue Jun 07, 2022 3:07 pm
Instead of making a dormant npc frame, I wonder, is it possible to make an effect for an NPC? Make the npc a single framed one and then give it an effect gif before transforming it into another npc?
you could render the npc invisible for a fixed period of time, spawn the effect at it's location, then transform it. your other idea could also work, you just have to set the npc's "animationFrame" field to whichever frame you want it to be stuck on (zero-based, so the frame at the very top of the sprite is animation frame 0, the one below is 1, etc.).
Alright, so it would be like:
Code: Select all
proximity = math.abs(v.x - player.x)
if proximity >= 220 then
v.animationFrame = 0
end
if v.animationFrame == 3 then
v:transform(162,true,true)
end
All under onDraw()? But when I try it, the NPC doesn't advance past the 2nd frame. I wonder if it has anything to do with FrameSpeed or FrameDelay.
Added in 22 minutes 55 seconds:
Hmmm... It seems I somehow got the animation frames to go in reverse. Weird.
Added in 12 minutes 17 seconds:
Okay, it's working now. I just had to change the framestyle. Thanks again!
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 20, 2022 12:14 am
by LunarCatUSA
So, the Wohlsoft page has a deprecated page for the Multipoint function because its an earlier build. That being said, does anyone know how I would go about adding two checkpoints to my level without the player having to physically run into the CP flag npc?
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 20, 2022 11:01 am
by Hoeloe
LunarCatUSA wrote: ↑Mon Jun 20, 2022 12:14 am
So, the Wohlsoft page has a deprecated page for the Multipoint function because its an earlier build. That being said, does anyone know how I would go about adding two checkpoints to my level without the player having to physically run into the CP flag npc?
Multipoints are deprecated because that's the old library from back when SMBX only supported one checkpoint in a level.
These days, both checkpoint NPCs can be used multiple times with no issues, and checkpoints can be created from Lua directly using the Checkpoint class.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 20, 2022 1:00 pm
by LunarCatUSA
So something like...
Code: Select all
local checkpoints = API.load("checkpoints");
if event == true then
checkpoints.addLuaCheckpoint(ThisX, ThisY, ThatSection);
end
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 20, 2022 4:27 pm
by Hoeloe
No. Look at the documentation, it's just this:
Code: Select all
local myCheckpoint = Checkpoint{x=ThisX, y=ThisY, section=ThatSection}
Then, when you want to collect the checkpoint you can just do:
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 20, 2022 4:29 pm
by Enjl
Hoeloe wrote: ↑Mon Jun 20, 2022 4:27 pm
No. Look at the documentation, it's just this:
Code: Select all
local myCheckpoint = Checkpoint{x=ThisX, y=ThisY, section=ThatSection}
Then, when you want to collect the checkpoint you can just do:
To BE fair you made the docs today and didn't link them.