Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
User avatar
cato
Hoopster
Hoopster
Posts: 162
Joined: Thu Aug 24, 2017 3:06 am
Current Project: My episode
Chat Username: Cato
Contact:

Re: Need help with lua? - LunaLua General Help

Postby cato » Fri Jul 12, 2019 11:35 am

Can't do much in Camera.Class.
Is camera pos/camera setting/camera movement required?
Should I just start with this and work around it?

Code: Select all

local player1Camera = Camera.get()[1]
function onCameraUpdate()
    player1Camera.x = player1Camera.x + 200
end
Or should copy the one in PAL version and work around it?

User avatar
Murphmario
Mouser
Mouser
Posts: 1932
Joined: Fri Dec 20, 2013 7:07 pm

Re: Need help with lua? - LunaLua General Help

Postby Murphmario » Fri Jul 12, 2019 12:37 pm

You two don't get what I want to do. As in, replace one of the free NPC slots with an identically-behaving Snake Block, with a few attributes changed.
Now taking graphics requests:
https://docs.google.com/forms/d/1urWpFq ... #responses

My graphics pack:
http://www.supermariobrosx.org/forums/v ... t=1960/url

Nothing is coming on Christmas. Why? Because I missed my past promises and should stop putting release dates on my stuff.

User avatar
MisterZygarde64
Spiny
Spiny
Posts: 43
Joined: Wed Jun 08, 2016 9:43 pm

Re: Need help with lua? - LunaLua General Help

Postby MisterZygarde64 » Sat Jul 13, 2019 11:38 pm

So I'm trying to have custom blooper graphic I'm using have it's death effect actually work
This is what happens when I didn't code in the effect

Image

So I decided to edit a luna.lua file so it wouldn't seem messed up

Image

Unfortunately I got this warning




Image

What did I do wrong and how can I correct it so I can make it so I can resize multiple effects at once?

User avatar
Hoeloe
Grinder
Grinder
Posts: 1040
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sun Jul 14, 2019 9:48 am

You can't have multiple copies of the same function - in this case, onDraw.

What you can do is just put the code inside both versions of that function one after the other.

I also strongly suggest using Notepad++, rather than just Notepad. It'll make this a whole lot easier.

User avatar
MisterZygarde64
Spiny
Spiny
Posts: 43
Joined: Wed Jun 08, 2016 9:43 pm

Re: Need help with lua? - LunaLua General Help

Postby MisterZygarde64 » Sun Jul 14, 2019 3:24 pm

Hoeloe wrote:
Sun Jul 14, 2019 9:48 am
You can't have multiple copies of the same function - in this case, onDraw.

What you can do is just put the code inside both versions of that function one after the other.

I also strongly suggest using Notepad++, rather than just Notepad. It'll make this a whole lot easier.
So is something like this good enough?

Code: Select all

function onDraw() for _, doanim in ipairs(Animation.get(3)) do doanim.width = 32; do doanim.height = 46; end end
(Animation.get(117))  doanim.width = 32; doanim.height = 48; end end

User avatar
Hoeloe
Grinder
Grinder
Posts: 1040
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Tue Jul 16, 2019 9:09 am

Too many "end"s. The "end" keyword is used to close off a block. You need to close off every time you use the keywords "function", "then", or "do". In this case, you're opening a block using "function", then opening another block using the for loop. You don't want to close off the onDraw definition until the end, and here you're opening 3 blocks, but closing 4 of them.

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

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Tue Jul 16, 2019 10:32 am

Hoeloe wrote:
Tue Jul 16, 2019 9:09 am
Too many "end"s. The "end" keyword is used to close off a block. You need to close off every time you use the keywords "function", "then", or "do". In this case, you're opening a block using "function", then opening another block using the for loop. You don't want to close off the onDraw definition until the end, and here you're opening 3 blocks, but closing 4 of them.
Also.... not how for loops work, heh. Let me fix the formatting so you can see it better:

Code: Select all

function onDraw()
	for _, doanim in ipairs(Animation.get(3)) do
		doanim.width = 32 do doanim.height = 46 // the "do" here makes no sense
	end
(end) //this one is too much
	(Animation.get(117)) do // this line is nonsense
		doanim.width = 32; doanim.height = 48
	end
end
I recommend reading a few of the basic lua tutorials to get a better understanding of things like for loops.
"Numeric" for loop. Arrow to the right brings you to the "generic" for loop, which is the ipairs loop.

Fixed version for comparison:

Code: Select all

function onDraw()
	for _, doanim in ipairs(Animation.get(3)) do
		doanim.width = 32
		doanim.height = 46
	end
	for _, doanim in ipairs(Animation.get(117)) do
		doanim.width = 32
		doanim.height = 48
	end
end
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
DrMekar
Ripper II
Ripper II
Posts: 348
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Fri Jul 19, 2019 6:02 pm

Is it possible to change the color of already lighting things like Lava, when using Darkness?

Image
This is how the 'Lava' looks in normal

Image
And with Darkness it stays Orange.

P.S: The Lava will also move during the Fight with Von Sacheverell
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 GM

Image

User avatar
Hoeloe
Grinder
Grinder
Posts: 1040
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sat Jul 20, 2019 9:35 am

DrMekar wrote:
Fri Jul 19, 2019 6:02 pm
Is it possible to change the color of already lighting things like Lava, when using Darkness?
Should be possible using Block.config.

Block.config[id].lightcolor = Color.white

for example.

User avatar
DrMekar
Ripper II
Ripper II
Posts: 348
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Sat Jul 20, 2019 9:43 am

Hoeloe wrote:
Sat Jul 20, 2019 9:35 am
DrMekar wrote:
Fri Jul 19, 2019 6:02 pm
Is it possible to change the color of already lighting things like Lava, when using Darkness?
Should be possible using Block.config.

Block.config[id].lightcolor = Color.white

for example.
Okay, Thanks
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 GM

Image

User avatar
Ness-Wednesday
Purple Yoshi Egg
Purple Yoshi Egg
Posts: 1372
Joined: Sun Jun 28, 2015 3:50 pm
Flair: Diverse Scouts
Current Project: TBA ;)
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Ness-Wednesday » Sat Jul 20, 2019 7:52 pm

I'm trying to make the npc move the opposite direction of its original id (like if it's getting deflected), but it would always become stationary while it continuously shakes.
Image
Spoiler: show

Code: Select all

	for k,v in pairs(NPC.get(174,player.section)) do
		if v:mem(0x0C,FIELD_WORD) == 2 or v:mem(0x10,FIELD_WORD) == 2 then
		v:kill()
		end
		if v:mem(0x0A, FIELD_WORD) == 2 then
			VivaJump = 0
		end
		v:mem(0x24, FIELD_WORD, 0)
		if v:mem(0x120, FIELD_BOOL) and (v:mem(0x0C, FIELD_WORD) ~= 2 and v:mem(0x10, FIELD_WORD) ~= 2) then
			v:mem(0x120, FIELD_BOOL, false)
		end
			if v:mem(0xEC,FIELD_FLOAT) == -1 then
				v.speedX = 4
			elseif v:mem(0xEC,FIELD_FLOAT) == 1 then
				v.speedX = -4
			end
		if VivaJump <= 12 then
			v.speedY = -8
		end
	end
#Therealmofloveandhate

Join my Discord server!
Spoiler: show
Image
Do you love Villagers? I know I do!
(Image is not by me)
Will Toad truly get an actual project, will something happen who knows?
OR

User avatar
DrMekar
Ripper II
Ripper II
Posts: 348
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Sun Jul 21, 2019 1:57 pm

Hoeloe wrote:
Sat Jul 20, 2019 9:35 am
DrMekar wrote:
Fri Jul 19, 2019 6:02 pm
Is it possible to change the color of already lighting things like Lava, when using Darkness?
Should be possible using Block.config.

Block.config[id].lightcolor = Color.white

for example.
It didn't work. I tried out lightcolor= yellow, lightcolor = color.yellow, color = yellow, blockcolor = yellow. I also couldn't find anythink in the Darkness Lua General File which leds to block color, only the NPCs
Defaults.
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 GM

Image

User avatar
Hoeloe
Grinder
Grinder
Posts: 1040
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sun Jul 21, 2019 3:43 pm

DrMekar wrote:
Sun Jul 21, 2019 1:57 pm


It didn't work. I tried out lightcolor= yellow, lightcolor = color.yellow, color = yellow, blockcolor = yellow. I also couldn't find anythink in the Darkness Lua General File which leds to block color, only the NPCs
Defaults.
Seems like you didn't try anything that actually fits the format I posted then.

Take a look closely.

Code: Select all

Color.white
Note the capital C in "color" here. You can't just change things around at random and expect it to work. Color.yellow does exist, you just didn't actually ask it for that.

The reason you can't find it in darkness.lua is that it's not set there, it's defined alongside the block data itself.

What could be helpful for you is a list of all the colour constants that exist, and their corresponding hex codes:
Color.white - 0xFFFFFFFF
Color.black - 0x000000FF
Color.red - 0xFF0000FF
Color.green - 0x00FF00FF
Color.blue - 0x0000FFFF
Color.alphawhite - 0xFFFFFF00
Color.alphablack - 0x00000000
Color.transparent - 0x00000000
Color.grey - 0x808080FF
Color.gray - 0x808080FF
Color.cyan - 0x00FFFFFF
Color.magenta - 0xFF00FFFF
Color.yellow - 0xFFFF00FF
Color.pink - 0xFF73ABFF
Color.canary - 0xFFF266FF
Color.purple - 0xAB66ABFF
Color.orange - 0xFF8C54FF
Color.teal - 0x00AB99FF
Color.maroon - 0x730000FF
Color.brown - 0x804D00FF
Color.lightgrey - 0xBFBFBFFF
Color.lightgray - 0xBFBFBFFF
Color.lightblue - 0x33CCFFFF
Color.lightgreen - 0x80CC99FF
Color.lightbrown - 0xBF9966FF
Color.lightred - 0xFF8080FF
Color.darkgrey - 0x404040FF
Color.darkgray - 0x404040FF
Color.darkblue - 0x003373FF
Color.darkgreen - 0x005926FF
Color.darkbrown - 0x4D4040FF
Color.darkred - 0x800000FF

User avatar
DrMekar
Ripper II
Ripper II
Posts: 348
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Sun Jul 21, 2019 4:07 pm

Hoeloe wrote:
Sun Jul 21, 2019 3:43 pm
DrMekar wrote:
Sun Jul 21, 2019 1:57 pm


It didn't work. I tried out lightcolor= yellow, lightcolor = color.yellow, color = yellow, blockcolor = yellow. I also couldn't find anythink in the Darkness Lua General File which leds to block color, only the NPCs
Defaults.
Seems like you didn't try anything that actually fits the format I posted then.

Take a look closely.

Code: Select all

Color.white
Note the capital C in "color" here. You can't just change things around at random and expect it to work. Color.yellow does exist, you just didn't actually ask it for that.

The reason you can't find it in darkness.lua is that it's not set there, it's defined alongside the block data itself.

What could be helpful for you is a list of all the colour constants that exist, and their corresponding hex codes:
Color.white - 0xFFFFFFFF
Color.black - 0x000000FF
Color.red - 0xFF0000FF
Color.green - 0x00FF00FF
Color.blue - 0x0000FFFF
Color.alphawhite - 0xFFFFFF00
Color.alphablack - 0x00000000
Color.transparent - 0x00000000
Color.grey - 0x808080FF
Color.gray - 0x808080FF
Color.cyan - 0x00FFFFFF
Color.magenta - 0xFF00FFFF
Color.yellow - 0xFFFF00FF
Color.pink - 0xFF73ABFF
Color.canary - 0xFFF266FF
Color.purple - 0xAB66ABFF
Color.orange - 0xFF8C54FF
Color.teal - 0x00AB99FF
Color.maroon - 0x730000FF
Color.brown - 0x804D00FF
Color.lightgrey - 0xBFBFBFFF
Color.lightgray - 0xBFBFBFFF
Color.lightblue - 0x33CCFFFF
Color.lightgreen - 0x80CC99FF
Color.lightbrown - 0xBF9966FF
Color.lightred - 0xFF8080FF
Color.darkgrey - 0x404040FF
Color.darkgray - 0x404040FF
Color.darkblue - 0x003373FF
Color.darkgreen - 0x005926FF
Color.darkbrown - 0x4D4040FF
Color.darkred - 0x800000FF
Oh, okay. Yeah that's my oversight 😅. Thanks for the list thougth. I'd never thougth that there are so many colors and it explains why purple was so bright when I tried it.
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 GM

Image

User avatar
Hoeloe
Grinder
Grinder
Posts: 1040
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Current Project: A2XT Episode 2

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sun Jul 21, 2019 4:14 pm

DrMekar wrote:
Sun Jul 21, 2019 4:07 pm
Oh, okay. Yeah that's my oversight 😅. Thanks for the list thougth. I'd never thougth that there are so many colors and it explains why purple was so bright when I tried it.
These are just the built in colours. You can make your own using:

Code: Select all

Color(R, G, B)
With R,G, and B being values between 0 and 1. Alternatively:

Code: Select all

Color.fromHex(0x########)

User avatar
DrMekar
Ripper II
Ripper II
Posts: 348
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Current Project: Mario Hereos 2: The Seal of Darkness, SMBXDM The Lost Levels 2, Path of Silence
Chat Username: DrMekar
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DrMekar » Sun Jul 21, 2019 5:38 pm

Hoeloe wrote:
Sun Jul 21, 2019 4:14 pm
DrMekar wrote:
Sun Jul 21, 2019 4:07 pm
Oh, okay. Yeah that's my oversight 😅. Thanks for the list thougth. I'd never thougth that there are so many colors and it explains why purple was so bright when I tried it.
These are just the built in colours. You can make your own using:

Code: Select all

Color(R, G, B)
With R,G, and B being values between 0 and 1. Alternatively:

Code: Select all

Color.fromHex(0x########)
Intresting, but I think I'll be fine at first. Thanks
My Youtube Channel: https://www.youtube.com/channel/UC-8fzX ... subscriber

Great Folks who support/ed my projects/in the past:

Suecra
jaf
Suckerman7 GM

Image

User avatar
Chilly14
Spiny
Spiny
Posts: 53
Joined: Thu Jul 18, 2019 10:28 pm

Re: Need help with lua? - LunaLua General Help

Postby Chilly14 » Tue Jul 23, 2019 10:36 pm

How do I have Venus Firetraps shoot multiple fireballs at once?
For the love of god, please use an adblocker when using MediaFire to download my stuff.

cursed mario
Image

User avatar
1AmPlayer
Lakitu
Lakitu
Posts: 489
Joined: Sun May 21, 2017 3:36 am
Flair: I'm a hellspawn.
Current Project: Moonlight Forest (3rd Weather Trio Series)
Chat Username: IAmPx
Contact:

Re: Need help with lua? - LunaLua General Help

Postby 1AmPlayer » Fri Aug 09, 2019 9:26 am

Chilly14 wrote:
Tue Jul 23, 2019 10:36 pm
How do I have Venus Firetraps shoot multiple fireballs at once?
You can make a check if the Venus Firetraps' AI 2 field (npc.ai2) is on "Watch for a player and shoot" state (value of 2) and if the AI 1 (npc.ai1) field is set to 50 (the time when the Venus Firetrap shoots fire) and with pnpc library you can have a new data stored the amount of the fireballs shot by the Venus Firetrap in the same check and you can add it in the condition if the fireball amount is less than the value you wanted, which sould increment the fireballs amount by 1 and revert the AI 2 timer so that the NPC can shoot again until the maximum amount of the fireballs you wanted the Venus Firetrap to shoot is reached.

To revert the fireball amount, so that it can shoot again when it does it the next time the AI 2 field is the id 2 again by making a check if the AI 2 field is not 2, then make the pnpc data that has the fireball amount be set to 0.

This might be very hard to understand, so maybe someone else can explained it better. Sorry if it was hard though.
Have a lenny. ( ͡° ͜ʖ ͡°)

I have come back in SMBX Forums. Finally! :D
Image

User avatar
Bulby_VR
Shy Guy
Shy Guy
Posts: 9
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 » Wed Aug 14, 2019 10:19 am

When I set the player X speed, it goes down really quickly. Please help!

https://pastebin.com/Mi5cAB2W
(Yes, everything else works)
Also, how do I make this spagetti garbo 2 player?
https://pastebin.com/p0qkpj53
an ace at making garbo code

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

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Wed Aug 14, 2019 4:38 pm

Bulby_VR wrote:
Wed Aug 14, 2019 10:19 am
When I set the player X speed, it goes down really quickly. Please help!

https://pastebin.com/Mi5cAB2W
(Yes, everything else works)
Also, how do I make this spagetti garbo 2 player?
https://pastebin.com/p0qkpj53
Player runspeed is capped. Walkspeed isn't. There is no clean solution to breaching the speed, especially in regards to multiplayer compatibility. You can change the Defines.player_runspeed value dynamically, but that changes the cap for all players. http://wohlsoft.ru/pgewiki/SMBX_Fields
2-player compatibility is done by using a for loop over Player.get() rather than the player constant.
ImageImageImageImage
ImageImageImageImageImageImage


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 0 guests