Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » 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?
Last edited by Novarender on Fri Jun 01, 2018 6:22 pm, edited 1 time in total.

Smibbix
Swooper
Swooper
Posts: 60
Joined: Fri Apr 06, 2018 10:47 pm

Re: Need help with lua? - LunaLua General Help

Postby Smibbix » 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.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Thu May 31, 2018 7:57 pm

You're collecting NPC-4's instead of block-4's. Use Block.get(4) instead.

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: Need help with lua? - LunaLua General Help

Postby The0x539 » Thu May 31, 2018 11:17 pm

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

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » 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?

Taycamgame
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 1483
Joined: Mon Jun 19, 2017 11:35 am
Flair: Stargard
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Taycamgame » 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.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » 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.

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » 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.

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.

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: Need help with lua? - LunaLua General Help

Postby The0x539 » 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
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.

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » Sun Jun 03, 2018 9:42 pm

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:

Code: Select all

loadAPI("Ground_Pound")

This is supposed to load Ground_Pound.lua from the library, but it gives me this error message:

Spoiler: show
==> 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

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Sun Jun 03, 2018 10:31 pm

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

Taycamgame
Gold Yoshi Egg
Gold Yoshi Egg
Posts: 1483
Joined: Mon Jun 19, 2017 11:35 am
Flair: Stargard
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Taycamgame » Mon Jun 04, 2018 3:31 am

Also i'd do something like
local groundpound = API.load("groundpound")
Which would load the API correctly.

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » 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?

The0x539
Eerie
Eerie
Posts: 751
Joined: Fri Jan 22, 2016 8:02 pm

Re: Need help with lua? - LunaLua General Help

Postby The0x539 » Tue Jun 05, 2018 2:55 pm

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.

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

Re: Need help with lua? - LunaLua General Help

Postby Novarender » Tue Jun 05, 2018 5:00 pm

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.

Daring Tombstone
Blooper
Blooper
Posts: 160
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » 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.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue Jun 05, 2018 7:14 pm

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

Daring Tombstone
Blooper
Blooper
Posts: 160
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » Tue Jun 05, 2018 8:21 pm

Thank you for the pleasant explanation and useful links. I was able to figure it out with the information you provided. Appreciate it.

Daring Tombstone
Blooper
Blooper
Posts: 160
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » 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.

Image

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.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Wed Jun 13, 2018 10:14 pm

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.

Image

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?


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari