Page 67 of 76
Re: Need help with lua? - LunaLua General Help
Posted: Tue May 29, 2018 7:31 pm
by Novarender
How can I stop the player while they are jumping, still holding the jump button?
Also, how can I force the player to be able to jump?
Re: Need help with lua? - LunaLua General Help
Posted: Wed May 30, 2018 7:59 pm
by Smibbix
I'm having trouble with the colliders library. I want it so that whenever a player fireball hits a brick, the brick is destroyed. Here's the code in my lunadll.lua file:
local colliders = API.load("colliders")
function onTick()
for _,brick in pairs(NPC.get(4)) do
if (colliders.collideNPCBlock(13, brick)) then
brick:remove(true)
end
end
end
(I couldn't get my tabs to show up on this

)
When any fireballs actually hit a brick, though, nothing happens.
Re: Need help with lua? - LunaLua General Help
Posted: Thu May 31, 2018 7:57 pm
by Quantumenace
You're collecting NPC-4's instead of block-4's. Use Block.get(4) instead.
Re: Need help with lua? - LunaLua General Help
Posted: Thu May 31, 2018 11:17 pm
by The0x539
Smibbix wrote: ↑Wed May 30, 2018 7:59 pm
I'm having trouble with the colliders library. I want it so that whenever a player fireball hits a brick, the brick is destroyed. Here's the code in my lunadll.lua file:
local colliders = API.load("colliders")
function onTick()
for _,brick in pairs(NPC.get(4)) do
if (colliders.collideNPCBlock(13, brick)) then
brick:remove(true)
end
end
end
(I couldn't get my tabs to show up on this

)
When any fireballs actually hit a brick, though, nothing happens.
that's not how collideNPCBlock works.
local didCollide, howMany, collisions = colliders.collideNPCBlock(13, 4)
for _,collision in ipairs(collisions) do
local fireball = collision[1]
local brick = collision[2]
brick:remove(true)
end
Re: Need help with lua? - LunaLua General Help
Posted: Fri Jun 01, 2018 5:25 pm
by Novarender
Notxarb wrote: ↑Tue May 29, 2018 7:31 pm
How can I stop the player while they are jumping, still holding the jump button?
Also, how can I force the player to be able to jump?
Can someone please answer my above question? Thanks.
Also, how can I create the stomping effect when yoshi eats a yellow shell and touches the ground?
Re: Need help with lua? - LunaLua General Help
Posted: Sat Jun 02, 2018 12:09 pm
by Taycamgame
Notxarb wrote: ↑Fri Jun 01, 2018 5:25 pm
Notxarb wrote: ↑Tue May 29, 2018 7:31 pm
How can I stop the player while they are jumping, still holding the jump button?
Also, how can I force the player to be able to jump?
Can someone please answer my above question? Thanks.
Also, how can I create the stomping effect when yoshi eats a yellow shell and touches the ground?
While i cannot answer your first question, i can help with the second.
There are different coloured yoshis as you are aware. Pretty sure it is the Yellow or maybe blue yoshi that stomps when holding an object, though i am unsure how to do the yellow shell part.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Jun 02, 2018 6:31 pm
by Quantumenace
Notxarb wrote: ↑Tue May 29, 2018 7:31 pm
How can I stop the player while they are jumping, still holding the jump button?
Also, how can I force the player to be able to jump?
I'm having a hard time understanding what you're asking. If you want to override the player's jump key input, use the event onInputUpdate() and set player.jumpKeyPressing to true or false.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jun 03, 2018 3:28 pm
by Novarender
Quantumenace wrote: ↑Sat Jun 02, 2018 6:31 pm
Notxarb wrote: ↑Tue May 29, 2018 7:31 pm
How can I stop the player while they are jumping, still holding the jump button?
Also, how can I force the player to be able to jump?
I'm having a hard time understanding what you're asking. If you want to override the player's jump key input, use the event onInputUpdate() and set player.jumpKeyPressing to true or false.
So I tried to set the player's Y-speed to 50 while in mid-air -- it works, but not while the player is jumping AND still holding the jump key. I think I'll have to set the Y-speed every tick, that might work.
As for my second question, I need to do a sort of double-jump. If I set 0x11E to 1 it makes it so they can't jump, and that works, but if I set it to -1, they're supposed to be able to jump, but it doesn't work. Both are being set every tick so that's not the issue. I also don't want to set their Y-speed to -20 to simulate a jump because you know how you can jump at different heights depending on how long you hold the jump button. This second question is for making a wall-jumping program.
Taycamgame wrote: ↑Sat Jun 02, 2018 12:09 pm
Notxarb wrote: ↑Fri Jun 01, 2018 5:25 pm
Notxarb wrote: ↑Tue May 29, 2018 7:31 pm
How can I stop the player while they are jumping, still holding the jump button?
Also, how can I force the player to be able to jump?
Can someone please answer my above question? Thanks.
Also, how can I create the stomping effect when yoshi eats a yellow shell and touches the ground?
While i cannot answer your first question, i can help with the second.
There are different coloured yoshis as you are aware. Pretty sure it is the Yellow or maybe blue yoshi that stomps when holding an object, though i am unsure how to do the yellow shell part.
Yes, I know all this. I need to know how to spawn in the effect or something. Both the yellow shell and the yellow Yoshi create this effect upon touching the ground.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jun 03, 2018 4:16 pm
by The0x539
Notxarb wrote: ↑Sun Jun 03, 2018 3:28 pm
Quantumenace wrote: ↑Sat Jun 02, 2018 6:31 pm
Notxarb wrote: ↑Tue May 29, 2018 7:31 pm
How can I stop the player while they are jumping, still holding the jump button?
Also, how can I force the player to be able to jump?
I'm having a hard time understanding what you're asking. If you want to override the player's jump key input, use the event onInputUpdate() and set player.jumpKeyPressing to true or false.
So I tried to set the player's Y-speed to 50 while in mid-air -- it works, but not while the player is jumping AND still holding the jump key. I think I'll have to set the Y-speed every tick, that might work.
As for my second question, I need to do a sort of double-jump. If I set 0x11E to 1 it makes it so they can't jump, and that works, but if I set it to -1, they're supposed to be able to jump, but it doesn't work. Both are being set every tick so that's not the issue. I also don't want to set their Y-speed to -20 to simulate a jump because you know how you can jump at different heights depending on how long you hold the jump button. This second question is for making a wall-jumping program.
Have a look at player offset 0x11C, also accessible as the UpwardJumpingForce field.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jun 03, 2018 9:42 pm
by Novarender
The0x539 wrote: ↑Sun Jun 03, 2018 4:16 pm
Notxarb wrote: ↑Sun Jun 03, 2018 3:28 pm
Quantumenace wrote: ↑Sat Jun 02, 2018 6:31 pm
I'm having a hard time understanding what you're asking. If you want to override the player's jump key input, use the event onInputUpdate() and set player.jumpKeyPressing to true or false.
So I tried to set the player's Y-speed to 50 while in mid-air -- it works, but not while the player is jumping AND still holding the jump key. I think I'll have to set the Y-speed every tick, that might work.
As for my second question, I need to do a sort of double-jump. If I set 0x11E to 1 it makes it so they can't jump, and that works, but if I set it to -1, they're supposed to be able to jump, but it doesn't work. Both are being set every tick so that's not the issue. I also don't want to set their Y-speed to -20 to simulate a jump because you know how you can jump at different heights depending on how long you hold the jump button. This second question is for making a wall-jumping program.
Have a look at player offset 0x11C, also accessible as the UpwardJumpingForce field.
Ok I'll try that, but right now I have a more immediate problem:
This is supposed to load Ground_Pound.lua from the library, but it gives me this error message:
==> mainV2.lua:509: attempt to concatenate global 'apiPath' (a nil value)
=============
stack traceback:
mainV2.lua:422: in function '__concat'
mainV2.lua:509: in function 'loadAPIByPath'
mainV2.lua:537: in function 'doAPI'
mainV2.lua:579: in function 'loadAPI'
... 2.0 Beta 3/data/worlds/A New Adventure/REAL\lunadll.lua:1: in function 'codeFile'
mainV2.lua:723: in function 'loadCodeFile'
mainV2.lua:937: in function <mainV2.lua:921>
[C]: in function '__xpcall'
mainV2.lua:921: in function <mainV2.lua:920>
This is the code of Ground_Pound.lua:
Code: Select all
isGroundPounding = 0
function onTick()
Text.print(isGroundPounding,0,0)
end
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jun 03, 2018 10:31 pm
by PixelPest
Notxarb wrote: ↑Sun Jun 03, 2018 9:42 pm
I'd highly recommend checking out this tutorial as it explains how APIs are structured:
https://wohlsoft.ru/pgewiki/How_To:_Mak ... custom_API.
The error could be due to it not being in the same directory as the Lua file it's being called from. Also use API.load instead of loadAPI which is deprecated
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 04, 2018 3:31 am
by Taycamgame
Also i'd do something like
local groundpound = API.load("groundpound")
Which would load the API correctly.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Jun 05, 2018 11:51 am
by Novarender
I want to detect if a key is being pressed every frame. I'm using it in onTick but it's not working correctly. Is there a different event I should use?
Re: Need help with lua? - LunaLua General Help
Posted: Tue Jun 05, 2018 2:55 pm
by The0x539
Notxarb wrote: ↑Tue Jun 05, 2018 11:51 am
I want to detect if a key is being pressed every frame. I'm using it in onTick but it's not working correctly. Is there a different event I should use?
Inputs should be accurate during onTick. Show code.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Jun 05, 2018 5:00 pm
by Novarender
Code: Select all
function onTick()
Text.print(isGroundPounding,0,0)
Text.print(isSitting,0,25)
Text.print(t,0,50)
Text.print(player:isGroundTouching(),0,75)
Text.print(player.speedX,0,100)
Text.print(forceStay,0,125)
Text.print(player.leftKeyPressing,0,150)
Text.print(player.rightKeyPressing,0,175)
Text.print(player.downKeyPressing,0,200)
if player:isGroundTouching() then
if t < 10 and isGroundPounding == 1 then
t = t + 1
forceStay = 1
else
if isSitting == 1 then --and player.leftKeyPressing == 0 and player.rightKeyPressing == 0
forceStay = 1
else
if isGroundPounding == 1 then
isGroundPounding = 0
--if player.downKeyPressing == 1 then
isSitting = 1
forceStay = 1
--end
else
isSitting = 0
forceStay = 0
end
end
end
else
if isGroundPounding == 1 then
if player.speedX < -1 then
player.speedX = -1
end
if player.speedX > 1 then
player.speedX = 1
end
end
end
end
I don't know if it's just my browser but all the newlines appear to be deleted in the preview.
The comments are the key checks I had. When I had them in, parts of the program stopped working, but when I took them out it worked just fine.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Jun 05, 2018 5:56 pm
by Daring Tombstone
I've been attempting to learn a little bit of lunalua. I've read the tutorials and dabbled some. I'm attempting to use a clock that counts down twice as fast as it normally would using this code.
Code: Select all
local i = 600
function onTick()
if i <= 0 then
player:kill()
end
if i > 0 then
i = i - 1
end
local placement = math.ceil(i / 32.5)
Text.print(placement, 215, 54)
end
The countdown does go down twice as fast but when it reaches zero the player dies a million times. Assuming it's killing the player every frame. Since I'm a supernoob I'm not sure the correct way to tell the code to check if the player is dead. It's a super simple code so it's almost embarrassing to ask for help.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Jun 05, 2018 7:14 pm
by PixelPest
Daring Tombstone wrote: ↑Tue Jun 05, 2018 5:56 pm
I've been attempting to learn a little bit of lunalua. I've read the tutorials and dabbled some. I'm attempting to use a clock that counts down twice as fast as it normally would using this code.
Code: Select all
local i = 600
function onTick()
if i <= 0 then
player:kill()
end
if i > 0 then
i = i - 1
end
local placement = math.ceil(i / 32.5)
Text.print(placement, 215, 54)
end
The countdown does go down twice as fast but when it reaches zero the player dies a million times. Assuming it's killing the player every frame. Since I'm a supernoob I'm not sure the correct way to tell the code to check if the player is dead. It's a super simple code so it's almost embarrassing to ask for help.
Part of LunaLua are these memory structs which store an extra bunch of properties for class objects, like players.
https://wohlsoft.ru/pgewiki/SMBX_Player_Offsets
Basically, to access these addition properties you use the player:mem function with two arguments, the offset (memory address) and address type, or add a third argument to set the property.
https://wohlsoft.ru/pgewiki/Player:mem
In this case you can check player:mem(0x13E, FIELD_WORD) > 0 which is the player death animation timer
Re: Need help with lua? - LunaLua General Help
Posted: Tue Jun 05, 2018 8:21 pm
by Daring Tombstone
Thank you for the pleasant explanation and useful links. I was able to figure it out with the information you provided. Appreciate it.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Jun 13, 2018 8:27 pm
by Daring Tombstone
Sorry for double posting (if my above post from over a week ago counts) but I have this problem using the "moarrinkas" npcs. I'm using the bomb rinkas which works for a few seconds into a fight I'm doing then I get this error.
I'm not a genius in lunalua so I'm not sure what this is trying to tell me. If it helps, the bomb rinka is spawning in midfight and isn't there when you first arrive in the area. Is the moarrinkas buggy like this or is something else happening I'm not noticing.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Jun 13, 2018 10:14 pm
by PixelPest
Daring Tombstone wrote: ↑Wed Jun 13, 2018 8:27 pm
Sorry for double posting (if my above post from over a week ago counts) but I have this problem using the "moarrinkas" npcs. I'm using the bomb rinkas which works for a few seconds into a fight I'm doing then I get this error.
I'm not a genius in lunalua so I'm not sure what this is trying to tell me. If it helps, the bomb rinka is spawning in midfight and isn't there when you first arrive in the area. Is the moarrinkas buggy like this or is something else happening I'm not noticing.
Are you spawning it via a generator?