Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
cato
Rex
Rex
Posts: 86
Joined: Thu Aug 24, 2017 3:06 am
Chat Username: cato

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: 1904
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: 41
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
Eerie
Eerie
Posts: 993
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: 41
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
Eerie
Eerie
Posts: 993
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: 7226
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
Pokey
Pokey
Posts: 239
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

Current Project: Mario Heroes 2: The Seal of Darkness
Image

Code: Select all

https://www.supermariobrosx.org/forums/posting.php?mode=edit&f=90&t=23148&p=339823#preview
Last Project: Mario Heroes: The First Chapter

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

Suecra
jaf
Suckerman7 HM

User avatar
Hoeloe
Eerie
Eerie
Posts: 993
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
Pokey
Pokey
Posts: 239
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

Current Project: Mario Heroes 2: The Seal of Darkness
Image

Code: Select all

https://www.supermariobrosx.org/forums/posting.php?mode=edit&f=90&t=23148&p=339823#preview
Last Project: Mario Heroes: The First Chapter

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

Suecra
jaf
Suckerman7 HM

User avatar
Ness-Wednesday
Purple Yoshi Egg
Purple Yoshi Egg
Posts: 1353
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
Pokey
Pokey
Posts: 239
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

Current Project: Mario Heroes 2: The Seal of Darkness
Image

Code: Select all

https://www.supermariobrosx.org/forums/posting.php?mode=edit&f=90&t=23148&p=339823#preview
Last Project: Mario Heroes: The First Chapter

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

Suecra
jaf
Suckerman7 HM

User avatar
Hoeloe
Eerie
Eerie
Posts: 993
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
Pokey
Pokey
Posts: 239
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

Current Project: Mario Heroes 2: The Seal of Darkness
Image

Code: Select all

https://www.supermariobrosx.org/forums/posting.php?mode=edit&f=90&t=23148&p=339823#preview
Last Project: Mario Heroes: The First Chapter

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

Suecra
jaf
Suckerman7 HM

User avatar
Hoeloe
Eerie
Eerie
Posts: 993
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
Pokey
Pokey
Posts: 239
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

Current Project: Mario Heroes 2: The Seal of Darkness
Image

Code: Select all

https://www.supermariobrosx.org/forums/posting.php?mode=edit&f=90&t=23148&p=339823#preview
Last Project: Mario Heroes: The First Chapter

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

Suecra
jaf
Suckerman7 HM


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 0 guests