Page 11 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Fri Apr 08, 2016 6:58 am
by Circle Guy
PixelPest wrote:
Circle Guy wrote:
HenryRichard wrote:Did you set the .wld file's name in the editor?
Yeah, but I mean NO world names are showing up. Even the Invasion 2!
Oh. You mean on the main screen. I don't think you could really fix that easily. Have you actually checked to see if the .wld files have names inside the file?
Yeah, they do. Maybe I'll just look through and see what happened later.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Apr 08, 2016 5:06 pm
by HenryRichard
Sounds like you need to reinstall smbx.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Apr 08, 2016 5:49 pm
by pal4
Quantumenace wrote:The legacy editor should use lunalua scripts. I've never gotten the new editor to test correctly. Is the folder you posted the folder for the level? If so, why are there .lvl files in there?
It's the folder the level is in. I've been grouping levels by world.

Re: Need help with lua? - LunaLua General Help

Posted: Fri Apr 08, 2016 7:18 pm
by Hoeloe
pal4 wrote:
Quantumenace wrote:The legacy editor should use lunalua scripts. I've never gotten the new editor to test correctly. Is the folder you posted the folder for the level? If so, why are there .lvl files in there?
It's the folder the level is in. I've been grouping levels by world.
Then your lunalua file won't work. It has to be inside the level folder, with the level itself outside that folder.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Apr 09, 2016 10:30 am
by pal4
Hoeloe wrote:
pal4 wrote:
Quantumenace wrote:The legacy editor should use lunalua scripts. I've never gotten the new editor to test correctly. Is the folder you posted the folder for the level? If so, why are there .lvl files in there?
It's the folder the level is in. I've been grouping levels by world.
Then your lunalua file won't work. It has to be inside the level folder, with the level itself outside that folder.
How do I make a level folder? My computer won't let me name the folder like my level is named.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Apr 09, 2016 12:08 pm
by Hoeloe
pal4 wrote: How do I make a level folder? My computer won't let me name the folder like my level is named.
You don't add ".lvl" to the end, but if it still won't let you you need to change your level name.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Apr 09, 2016 1:06 pm
by pal4
Okay, I did it, but the code still does nothing. I put in a Text.print() code, to show my variable and still no changes occurred. Nothing showed up.

Re: Need help with lua? - LunaLua General Help

Posted: Sat Apr 09, 2016 1:10 pm
by Hoeloe
pal4 wrote:Okay, I did it, but the code still does nothing. I put in a Text.print() code, to show my variable and still no changes occurred. Nothing showed up.
Can you show another screenshot of your level folder, and post your code?

Re: Need help with lua? - LunaLua General Help

Posted: Sat Apr 09, 2016 6:34 pm
by Hani
Oh! I wonder if there is a way where I can make all blocks slippery instead of just selecting a block and enable slippery.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:40 am
by Quantumenace
To do something with multiple objects you need to use a loop. If you want every block in the entire level,

Block.get()

returns a table with references to all the blocks. To do something with them you can use the "pairs" keyword which cycles through all entries in the table using the variables provided:

for k,v in pairs(Block.get()) do ...... end

In this case, v represents the value at index k in the table. The value v is a reference to the block, and you can modify its "slippery" flag with v.slippery = true.

Code: Select all

for k,v in pairs(Block.get()) do 
	v.slippery = true
end
Don't forget the "end" or you'll get a "function failed to close" error.

You need to put this in an onStart() function or something, just putting it outside functions will try to run it before the blocks are even loaded.

Anyways, the wiki has a lot of information on this stuff. This page is a good place to start on the basics.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 11:29 am
by Quantix
So, I'm trying to use the Raocoins.lua for my episode, but when I put this in the lunaworld file:

Code: Select all

local raocoin = loadAPI("raocoin");
...the thing crashes. I read the error and it's something about it using registerEvent with strings. Is there anything I can do to fix this?

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 12:32 pm
by Hoeloe
Quantix wrote:So, I'm trying to use the Raocoins.lua for my episode, but when I put this in the lunaworld file:

Code: Select all

local raocoin = loadAPI("raocoin");
...the thing crashes. I read the error and it's something about it using registerEvent with strings. Is there anything I can do to fix this?
You're using the wrong library. "raocoin" is an old outdated library, while "raocoin2" is a modern one.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 1:49 pm
by PixelPest
Hoeloe wrote:
Quantix wrote:So, I'm trying to use the Raocoins.lua for my episode, but when I put this in the lunaworld file:

Code: Select all

local raocoin = loadAPI("raocoin");
...the thing crashes. I read the error and it's something about it using registerEvent with strings. Is there anything I can do to fix this?
You're using the wrong library. "raocoin" is an old outdated library, while "raocoin2" is a modern one.
Also use API.load since loadAPI is deprecated

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:04 pm
by Hani
Quantumenace wrote:To do something with multiple objects you need to use a loop. If you want every block in the entire level,

Block.get()

returns a table with references to all the blocks. To do something with them you can use the "pairs" keyword which cycles through all entries in the table using the variables provided:

for k,v in pairs(Block.get()) do ...... end

In this case, v represents the value at index k in the table. The value v is a reference to the block, and you can modify its "slippery" flag with v.slippery = true.

Code: Select all

for k,v in pairs(Block.get()) do 
	v.slippery = true
end
Don't forget the "end" or you'll get a "function failed to close" error.

You need to put this in an onStart() function or something, just putting it outside functions will try to run it before the blocks are even loaded.

Anyways, the wiki has a lot of information on this stuff. This page is a good place to start on the basics.
This is what the code looks like when I made it, it crashed.

Code: Select all

onStart() function

for k,v in pairs(Block.get()) do 
   v.slippery = true
end
I don't know what I did wrong.

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:07 pm
by Mario_and_Luigi_55
Catastrophe wrote:
Quantumenace wrote:To do something with multiple objects you need to use a loop. If you want every block in the entire level,

Block.get()

returns a table with references to all the blocks. To do something with them you can use the "pairs" keyword which cycles through all entries in the table using the variables provided:

for k,v in pairs(Block.get()) do ...... end

In this case, v represents the value at index k in the table. The value v is a reference to the block, and you can modify its "slippery" flag with v.slippery = true.

Code: Select all

for k,v in pairs(Block.get()) do 
	v.slippery = true
end
Don't forget the "end" or you'll get a "function failed to close" error.

You need to put this in an onStart() function or something, just putting it outside functions will try to run it before the blocks are even loaded.

Anyways, the wiki has a lot of information on this stuff. This page is a good place to start on the basics.
This is what the code looks like when I made it, it crashed.

Code: Select all

onStart() function

for k,v in pairs(Block.get()) do 
   v.slippery = true
end
I don't know what I did wrong.
1. Function onStart() not onStart() function
2. On start does things once, when level starts. Use function onLoop() or function onTick() there

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:10 pm
by underFlo
^ Also, you need one more end

(even though I'm pretty sure that onStart() would be the right function for this, but I may be wrong)

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:12 pm
by PixelPest
Catastrophe wrote:
You really need take some time to learn the basics, if you don't even know where to put "function"

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:15 pm
by Hani
The code didn't crash when I added the other end but it's not making the blocks slippery. ???

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:16 pm
by PixelPest
Catastrophe wrote:The code didn't crash when I added the other end but it's not making the blocks slippery. ???
Then use function onTick(). That should work

Re: Need help with lua? - LunaLua General Help

Posted: Sun Apr 10, 2016 2:18 pm
by Hani
PixelPest wrote:
Catastrophe wrote:The code didn't crash when I added the other end but it's not making the blocks slippery. ???
Then use function onTick(). That should work
function onTick() also doesn't work.