Need help with lua? - LunaLua General Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
SMBX-Acc
Goomba
Goomba
Posts: 3
Joined: Mon Jan 14, 2019 11:13 am

Re: Need help with lua? - LunaLua General Help

Postby SMBX-Acc » Wed May 29, 2019 11:08 am

How do I use AI (ai.1-5) of an existing NPC for my custom NPC? I'm trying to make a custom koopa shell.

Thanks
Last edited by SMBX-Acc on Fri Jul 12, 2019 10:28 am, edited 1 time in total.

timocomsmbx2345
Nipper
Nipper
Posts: 850
Joined: Sat Feb 06, 2016 1:44 pm
Contact:

Re: Need help with lua? - LunaLua General Help

Postby timocomsmbx2345 » Thu May 30, 2019 6:50 pm

I'm thinking about using all the scripts for my episode.bhownwouldnongp about doing that?

Rixitic
Spike
Spike
Posts: 250
Joined: Sat Dec 12, 2015 1:00 am
Contact:

Re: Need help with lua? - LunaLua General Help

Postby Rixitic » Fri May 31, 2019 8:59 am

For starters, you don't. Cinematx, textblox, and really all the other ones I made before animatx2 are generally bloated buggy messes and at least one of them doesn't even work anymore. And there's a lot of other folks' older libraries that are outdated/deprecated for similar reasons.

Going with some more recent scripts that fit the design and direction of your project rather than trying to make everything work together will be much more manageable.

IttaBaby
Swooper
Swooper
Posts: 53
Joined: Sat Apr 08, 2017 8:19 pm

Re: Need help with lua? - LunaLua General Help

Postby IttaBaby » Sat Jun 01, 2019 10:16 pm

anybody willing to tell me how to switch some buttons? I want to make Wario dash when run is pressed, rather than alt-run. I tried but when I just replace them all it breaks his coding so he dashes forever.

Emerald Galaxy
Koopa
Koopa
Posts: 18
Joined: Sun Apr 21, 2019 6:27 am
Flair: =w=

Re: Need help with lua? - LunaLua General Help

Postby Emerald Galaxy » Mon Jun 03, 2019 12:55 am

Remember that LunaLua tutorial that involved making a Goomba follow Mario. How come it doesn't seem to work anymore?

Emerald Galaxy
Koopa
Koopa
Posts: 18
Joined: Sun Apr 21, 2019 6:27 am
Flair: =w=

Re: Need help with lua? - LunaLua General Help

Postby Emerald Galaxy » Wed Jun 12, 2019 10:12 pm

Hello. I'm trying to give Peach and Toad their own swimming animations, but I'm having trouble doing so. Can I get a little assistance?
Thanks in advance.

Skott
Goomba
Goomba
Posts: 2
Joined: Mon Jun 17, 2019 7:56 pm

Re: Need help with lua? - LunaLua General Help

Postby Skott » Mon Jun 17, 2019 9:08 pm

Hey all, I'm having some trouble setting up global variables. Here's what I have in lunaworld.lua:

https://hastebin.com/biwerozede.rb

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Wed Jun 19, 2019 6:52 am

That hastebin file is empty. For global variables you want to store them in either GameData or SaveData, depending on whether you want the value to be saved when you quit the game.

For example:
SaveData.myVariable = SaveData.myVariable or 0

A line like this will set up a global variable that is saved when you save the game, and initialised to 0.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9722
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Jun 19, 2019 10:37 am

Hoeloe wrote:
Wed Jun 19, 2019 6:52 am
That hastebin file is empty. For global variables you want to store them in either GameData or SaveData, depending on whether you want the value to be saved when you quit the game.

For example:
SaveData.myVariable = SaveData.myVariable or 0

A line like this will set up a global variable that is saved when you save the game, and initialised to 0.
It's not empty for me. Here's a repost.

Code: Select all

SaveData.Treasures = SaveData.Treasures
SaveData.Tokens = SaveData.Tokens
local str = "Treasures: "
local str2 = "Tokens: "

function onDraw()
	Text.print(str .. Treasures, 10, 46)

	Text.print(str2 .. Tokens, 10, 26)
end

function onEvent(eventName)
	if eventName == "SM" then
		SaveData.Tokens = SaveData.Tokens + 5
	end
	if eventName == "MM" then
		SaveData.Tokens = SaveData.Tokens + 10
	end
	if eventName == "LM" then
		SaveData.Tokens = SaveData.Tokens + 20
	end
end

function onNPCKill(eventObj, killedNPC, killReason)
	if killedNPC.id ~= 196 then return end

	if killReason ~= HARM_TYPE_OFFSCREEN then return end

	if Colliders.collide(player, killedNPC) then
		SaveData.Treasures = SaveData.Treasures + 1
	end
end


TheNightingale
Charged Spiny
Charged Spiny
Posts: 1976
Joined: Fri Apr 20, 2018 9:28 pm
Flair: I don't know anything
Pronouns: he/him
Contact:

Re: Need help with lua? - LunaLua General Help

Postby TheNightingale » Wed Jun 19, 2019 10:46 pm

Since some time I want to use this mechanic but I am not sure how to make it work. It's around switchable blocks:
- In the first jump, the blue blocks appear and the rest of the colors disappear
- In the second jump, the red blocks appear and the rest disappears
- In the third jump, the yellow blocks appear and the rest disappears
- In the fourth jump, the green blocks appear and the rest disappears
- And then that's what is supposed to happen over and over
I also have a video as a reference: https://www.youtube.com/watch?v=6sYTXcKBK5o

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Thu Jun 20, 2019 4:14 am

Enjl wrote:
Wed Jun 19, 2019 10:37 am

It's not empty for me. Here's a repost.
Weird.

Anyway, the issue is that you never initialise the variables:

SaveData.Treasures = SaveData.Treasures
SaveData.Tokens = SaveData.Tokens

These lines do literally nothing - they're assigning variables to themselves, and if they don't exist, well they still don't exist afterwards.

The reason we do things like:

SaveData.myVar = SaveData.myVar or 0

is to initialise the variable. That "or 0" is the important part. What this line means is "if SavaData.myVar exists, then leave its value the same. Otherwise, set it to 0". This is done because, since SaveData loads its values from the save file, it might already be set up at this point, and just assigning it to 0 would make it act just like a regular variable, removing the point of SaveData in the first place.

Skott
Goomba
Goomba
Posts: 2
Joined: Mon Jun 17, 2019 7:56 pm

Re: Need help with lua? - LunaLua General Help

Postby Skott » Sat Jun 22, 2019 9:12 pm

Thanks, the variables are working perfectly now!

Murphmario
Chargin' Chuck
Chargin' Chuck
Posts: 2382
Joined: Fri Dec 20, 2013 7:07 pm
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby Murphmario » Sat Jul 06, 2019 10:01 pm

Hey, does anyone know how to make an NPC that behaves identically to a Snake Block other than the block it's initially set to in the PGE editor? I can't figure it out myself, so help would be appriciated.

MisterZygarde64
Swooper
Swooper
Posts: 52
Joined: Wed Jun 08, 2016 9:43 pm

Re: Need help with lua? - LunaLua General Help

Postby MisterZygarde64 » Sun Jul 07, 2019 10:24 pm

How am I supposed to run the code for this?
http://www.smbxgame.com/forums/v ... 87&t=13566

I'm making an episode where Mario and Luigi are the only playable characters but I want to make the episode easier so it can be more acessable. So I decided to download this lua code. (Credit to PixelPest). I just have no experience with LunaLua. I just need to know how I can have the code run so when Fire Mario his hit, he becomes big Mario instead of small Mario

*Edit* Nevermind. I figured it out.
Last edited by MisterZygarde64 on Tue Jul 09, 2019 4:33 pm, edited 1 time in total.

ElectriKong
Posts: 4650
Joined: Mon Jun 06, 2016 4:32 pm
Flair: I have NO idea what to put here
Pronouns: he/him
Contact:

Re: Need help with lua? - LunaLua General Help

Postby ElectriKong » Mon Jul 08, 2019 1:43 am

Murphmario wrote:
Sat Jul 06, 2019 10:01 pm
Hey, does anyone know how to make an NPC that behaves identically to a Snake Block other than the block it's initially set to in the PGE editor? I can't figure it out myself, so help would be appriciated.
Changed the block ID for the snake block NPCs in the properties, then place that block between them.

Murphmario
Chargin' Chuck
Chargin' Chuck
Posts: 2382
Joined: Fri Dec 20, 2013 7:07 pm
Pronouns: he/him

Re: Need help with lua? - LunaLua General Help

Postby Murphmario » Mon Jul 08, 2019 10:09 am

I said a NEW NPC, as in, not the same ID as a regular Snake Block.

cato
Volcano Lotus
Volcano Lotus
Posts: 547
Joined: Thu Aug 24, 2017 3:06 am
Flair: Koishi enjoyer
Contact:

Re: Need help with lua? - LunaLua General Help

Postby cato » Fri Jul 12, 2019 5:29 am

How do I script an autoscroll in other sections in SMBX 2.0 Beta 3?
It is possible in MAGLX3 or PAL version. Is it possible in the previous sections?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9722
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Fri Jul 12, 2019 5:42 am

Murphmario wrote:
Mon Jul 08, 2019 10:09 am
I said a NEW NPC, as in, not the same ID as a regular Snake Block.
Why? What Electriking said makes the snake block look like it were of the block you entered.
A demo can be found in this blog post:
http://codehaus.wohlsoft.ru/blog/2017/0 ... loodgates/
cato wrote:
Fri Jul 12, 2019 5:29 am
How do I script an autoscroll in other sections in SMBX 2.0 Beta 3?
It is possible in MAGLX3 or PAL version. Is it possible in the previous sections?
Literally the same as in the MAGLX3 builds.

cato
Volcano Lotus
Volcano Lotus
Posts: 547
Joined: Thu Aug 24, 2017 3:06 am
Flair: Koishi enjoyer
Contact:

Re: Need help with lua? - LunaLua General Help

Postby cato » Fri Jul 12, 2019 10:38 am

Well nope, legitly copied it from your video. Doesn't even scroll at all in Beta3. When I tested it on the PAL version, works perfectly fine.
I think the problem would be the argument "autoscroll.scrollRight(1)".

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9722
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Fri Jul 12, 2019 10:59 am

cato wrote:
Fri Jul 12, 2019 10:38 am
Well nope, legitly copied it from your video. Doesn't even scroll at all in Beta3. When I tested it on the PAL version, works perfectly fine.
I think the problem would be the argument "autoscroll.scrollRight(1)".
The only thing that changed in autoscroll.lua between beta 3 and maglx3 is that a buffer was introduced to ensure the first scroll command is guaranteed to be executed after the first onCameraUpdate, to prevent the camera from scrolling before it has properly reset. In Beta 3 you have to take care of that manually if you want the scroll to start immediately. No difference when starting a scroll later though, which is the primary use case anyway.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 4 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari