Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
User avatar
Bulby_VR
Koopa Troopa
Koopa Troopa
Posts: 21
Joined: Wed Aug 07, 2019 11:18 am
Current Project: Super Mario 3D World Crouch + Long Jump
Chat Username: Bulby

Re: Need help with lua? - LunaLua General Help

Postby Bulby_VR » Sat Aug 17, 2019 11:52 am

Enjl wrote:Player runspeed is capped. Walkspeed isn't.
If Walk speed isn't capped, then could I force the player to use walkspeed?
Also, isn't player.get() static? Wouldn't that mean an error would be brought up if I did this?

Code: Select all

playerTable = player.get;
playerTable[1].spinJumpKeyPressing = false;
Edit, i tested it and it did nothing, so either it ignores it or sets it properly
an ace at making garbo code
When I use mediafire, I use adblock, and you should too when using my links.

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7933
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sat Aug 17, 2019 12:34 pm

Bulby_VR wrote:
Sat Aug 17, 2019 11:52 am
If Walk speed isn't capped, then could I force the player to use walkspeed?
walkspeed is used when the run key is not held, while runspeed is used when the run key is held. For solutions, refer to my previous post.
Bulby_VR wrote:
Sat Aug 17, 2019 11:52 am
Also, isn't player.get() static? Wouldn't that mean an error would be brought up if I did this?
Have you used NPC.get() before in order to loop over NPCs? It's used like that.

Code: Select all

for k,p in ipairs(Player.get()) do
	p.altJumpKeyPressing = false
end
Few notes on that code:
- it's altJumpKeyPressing, like seen on this page https://wohlsoft.ru/pgewiki/Player_(class)
- Player.get() is a method static to the player class, yes. This means that while Player.get() exists, player.get() does not.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Bulby_VR
Koopa Troopa
Koopa Troopa
Posts: 21
Joined: Wed Aug 07, 2019 11:18 am
Current Project: Super Mario 3D World Crouch + Long Jump
Chat Username: Bulby

Re: Need help with lua? - LunaLua General Help

Postby Bulby_VR » Sat Aug 17, 2019 1:38 pm

Another question is, can we use different plugins like LuaSocket? I want to use a timer without a busy wait but you need something external to do that.
an ace at making garbo code
When I use mediafire, I use adblock, and you should too when using my links.

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7933
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sat Aug 17, 2019 1:49 pm

Bulby_VR wrote:
Sat Aug 17, 2019 1:38 pm
Another question is, can we use different plugins like LuaSocket? I want to use a timer without a busy wait but you need something external to do that.
... what is your goal?
A timer is just a variable you tick up in onTick.
A leveltimer can be implemented using timer.lua, for which there are instructions on the handbook.
What do you mean by "busy wait"?
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Bulby_VR
Koopa Troopa
Koopa Troopa
Posts: 21
Joined: Wed Aug 07, 2019 11:18 am
Current Project: Super Mario 3D World Crouch + Long Jump
Chat Username: Bulby

Re: Need help with lua? - LunaLua General Help

Postby Bulby_VR » Sun Aug 18, 2019 11:28 am

Enjl wrote:What do you mean by "busy wait"?
By busy wait I mean it stops everything, i.e. freeze the game, which I don't want.
Enjl wrote:A timer is just a variable you tick up in onTick.
How many ticks would be in a second? I don't want to have to use ticks because I'm not very familiar with that.

Added in 36 minutes 56 seconds:
It also looks like I can't use the command line to sleep because that raises an error when I use os.execute().

Added in 30 minutes 35 seconds:
Here is what I want to do:
https://pastebin.com/5AjP98XD
an ace at making garbo code
When I use mediafire, I use adblock, and you should too when using my links.

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7933
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sun Aug 18, 2019 2:04 pm

64.12 frames in a second. That's how often onTick runs. 39/2500 seconds per frame, to be precise.

First of all, I recommend using the "keys" fields. Your player here is x so it'd be x.keys:
The below line is true only on the frame on which the alt jump key is pressed:
if x.keys.altJump == KEYS_PRESSED then

You can also use x.mount < 1 instead of the mem offset.
I don't know what c is in this context because of this heavily cut down code fragment, so I can't comment on that bit.
Next, I don't know why you would want to wait a frame in that situation. It sounds rather volatile/unresponsive. It looks like you're trying to make a long jump script, but long jumps have never been locked to an arbitrary 20 frame limit, or with a 1-frame delay.
Then again, very little context in this script so I cannot give more precisely targeted advice regarding the intended goal. Dunno the intended goal after all.
The easiest way to delay by 1 frame is by using a coroutine https://wohlsoft.ru/pgewiki/EventU.lua
You never have to use io or os functions when working with SMBX2's lunalua module.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Bulby_VR
Koopa Troopa
Koopa Troopa
Posts: 21
Joined: Wed Aug 07, 2019 11:18 am
Current Project: Super Mario 3D World Crouch + Long Jump
Chat Username: Bulby

Re: Need help with lua? - LunaLua General Help

Postby Bulby_VR » Sun Aug 18, 2019 8:03 pm

I think my stuff is working with nothing really messed up, so I think I'm done with the help.
I'll probably post the file soon to the forum
an ace at making garbo code
When I use mediafire, I use adblock, and you should too when using my links.

User avatar
FlyingGym
Cheep-Cheep
Cheep-Cheep
Posts: 16
Joined: Sat Aug 17, 2019 3:28 pm
Flair: ok
Chat Username: Gym

Re: Need help with lua? - LunaLua General Help

Postby FlyingGym » Sun Aug 18, 2019 11:09 pm

So https://wohlsoft.ru/pgewiki/PowerUDFreeze.lua is deadlinked, any way to replicate it?

MarioLover64
Hoopster
Hoopster
Posts: 150
Joined: Fri Apr 26, 2019 6:09 pm

Re: Need help with lua? - LunaLua General Help

Postby MarioLover64 » Thu Aug 22, 2019 8:40 pm

is it possible to use my system's date to do stuff on specific days?

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7933
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Thu Aug 22, 2019 8:51 pm

MarioLover64 wrote:
Thu Aug 22, 2019 8:40 pm
is it possible to use my system's date to do stuff on specific days?
os.date is available, so yes.
ImageImageImageImage
ImageImageImageImageImageImage

MarioLover64
Hoopster
Hoopster
Posts: 150
Joined: Fri Apr 26, 2019 6:09 pm

Re: Need help with lua? - LunaLua General Help

Postby MarioLover64 » Thu Aug 22, 2019 9:10 pm

ok so camLock refuses to work at all. it does absolutely nothing. There aren't even any errors.

Added in 36 seconds:
Oh yeah, here's my code
--------------------------------------------------
-- World map code
-- Created 12:47 2019-5-3
--------------------------------------------------

-- Run code on first frame of the world map
function onStart()
local camLock = require("camLock")
camLock.addZone(-64,0,25,20)
end

-- Run code every frame (~1/65 second)
-- (code will be executed before game logic will be processed)
function onTick()
--Your code here
end

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7933
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Thu Aug 22, 2019 9:15 pm

You're creating a camera zone at coordinates -64, 0 with scale 25, 20. That's 25 pixels wide and 20 pixels tall. You expect the camera to fit in there? The camera is 800x600 pixels...
ImageImageImageImage
ImageImageImageImageImageImage

MarioLover64
Hoopster
Hoopster
Posts: 150
Joined: Fri Apr 26, 2019 6:09 pm

Re: Need help with lua? - LunaLua General Help

Postby MarioLover64 » Thu Aug 22, 2019 9:19 pm

i thought it was a per tile basis

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7933
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Thu Aug 22, 2019 9:23 pm

Struggling to think of a scenario where distance in lua libraries isn't measured in pixels.
ImageImageImageImage
ImageImageImageImageImageImage

MarioLover64
Hoopster
Hoopster
Posts: 150
Joined: Fri Apr 26, 2019 6:09 pm

Re: Need help with lua? - LunaLua General Help

Postby MarioLover64 » Thu Aug 22, 2019 9:29 pm

me adjusts so it's big enough



Still doesn't work

Code: Select all

--------------------------------------------------
-- World map code
-- Created 12:47 2019-5-3
--------------------------------------------------

-- Run code on first frame of the world map
function onStart()
    local camLock = require("camLock")
 	camLock.addZone(-64,0,864,800,1)
end

-- Run code every frame (~1/65 second)
-- (code will be executed before game logic will be processed)
function onTick()
    --Your code here
end

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7933
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Thu Aug 22, 2019 9:50 pm

Seems there is an issue with camlock on the PAL release, odd.
Try Beta 3. It should work there.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Daring Tombstone
Bit
Bit
Posts: 141
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?
Current Project: Something Maybe
Chat Username: Chaperone

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » Sat Aug 24, 2019 3:07 pm

Been looking to figure out how to use the darkness.lua and attach a light to an npc (npc-102 to be precise) but can't figure it out for the life of me. I only figured out how to do so editing the darkness.lua script directly. NPC.get keeps giving me arithmetic errors.
Happy Dance
Image
Check out my completed episode
Spoiler: show
Image
Check out my halloween level
Spoiler: show
Image

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7933
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Sat Aug 24, 2019 3:28 pm

Daring Tombstone wrote:
Sat Aug 24, 2019 3:07 pm
Been looking to figure out how to use the darkness.lua and attach a light to an npc (npc-102 to be precise) but can't figure it out for the life of me. I only figured out how to do so editing the darkness.lua script directly. NPC.get keeps giving me arithmetic errors.
Use the NPC config flags:
https://docs.google.com/spreadsheets/d/ ... edit#gid=0
ImageImageImageImage
ImageImageImageImageImageImage

MarioLover64
Hoopster
Hoopster
Posts: 150
Joined: Fri Apr 26, 2019 6:09 pm

Re: Need help with lua? - LunaLua General Help

Postby MarioLover64 » Sun Aug 25, 2019 3:23 pm

How can I make it so that enemies thrown at a boss only damages the boss if it hits the top 32 pixels of the boss and just kills the thrown npc otherwise.

MarioLover64
Hoopster
Hoopster
Posts: 150
Joined: Fri Apr 26, 2019 6:09 pm

Re: Need help with lua? - LunaLua General Help

Postby MarioLover64 » Mon Aug 26, 2019 8:28 pm

How do I make noteblocks bounce me higher (to a height of six blocks instead of five)


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest