Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
User avatar
Zant
Volcano Lotus
Volcano Lotus
Posts: 570
Joined: Sat Dec 21, 2013 2:58 pm

Re: Need help with lua? - LunaLua General Help

Postby Zant » Fri Apr 29, 2016 12:43 pm

Is it possible to create a portal system(like in Mari0)with LunaLua?

lotus006
Mega Mole
Mega Mole
Posts: 284
Joined: Thu Sep 24, 2015 12:59 am

Re: Need help with lua? - LunaLua General Help

Postby lotus006 » Fri Apr 29, 2016 1:37 pm

Zant wrote:Is it possible to create a portal system(like in Mari0)with LunaLua?
That's why I asked about to link boundaries to a block if this possible and how I can do this :S
I mean on an earlier post or thread not sure wich one :S

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

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Fri Apr 29, 2016 1:39 pm

lotus006 wrote:
Zant wrote:Is it possible to create a portal system(like in Mari0)with LunaLua?
That's why I asked about to link boundaries to a block if this possible and how I can do this :S
I mean on an earlier post or thread not sure wich one :S
Keep in mind that you have to essentially get rid of collision for the blocks where the portals are on. Making the player show on both ends can be troublesome, too.
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Mario_and_Luigi_55
Mega Mole
Mega Mole
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm
Current Project: Super Mario Bros Adventure

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Sat Apr 30, 2016 7:17 am

Can I make check if player touches ice block?

I have that:

Code: Select all

timerApi.setSecondsLeft(timerApi.getSecondsLeft()-3)
and I want to reduce time every time that player touches ice block.
Image
Image

My best levels:
Goomba Lands - 5/10
Stars of the trees - 5.5/10
Koopa Cave - 3.42
Green Grass Hill - 3.42
Grassy Valley - 5.47

S1eth
Spiny
Spiny
Posts: 54
Joined: Sat Apr 23, 2016 10:44 am

Re: Need help with lua? - LunaLua General Help

Postby S1eth » Sat Apr 30, 2016 7:34 am

Mario_and_Luigi_55 wrote:Can I make check if player touches ice block?

I have that:

Code: Select all

timerApi.setSecondsLeft(timerApi.getSecondsLeft()-3)
and I want to reduce time every time that player touches ice block.
You can use (Block.collidesWith(player) > 0) to check if a player touches a block.

Code: Select all

for _,iceblock in pairs(Block.get(put_Ice_block_id_here) do
	if (iceblock.collidesWith(player) > 0) then
		--do stuff
	end
end
EDIT: iceblock:collidesWith ( : instead of . )

You need: http://wohlsoft.ru/pgewiki/Block_%28class%29 and http://wohlsoft.ru/pgewiki/LunaLua_glob ... _functions

Now, this would be put into onTick or onLoop.
If you don't want to reduce the timer every frame the player touches the block, you'll need to remember which block the player has touched.
I don't think blocks have some kind of unique id for you to access, so you'd have to get some other unique information, such as the block's x and y coordinates and save them in a table. (doesn't work with moving layers)
Or if you have a very limited number of blocks, you could put each block on their own layer and use the layer to identify the block.

Or you create "invincibility frames" in which your timer cannot be reduced which lasts X ticks after touching an ice block.

Or do you mean ice blocks as in NPCs turned into ice?
Last edited by S1eth on Sat Apr 30, 2016 8:06 am, edited 1 time in total.

User avatar
Mario_and_Luigi_55
Mega Mole
Mega Mole
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm
Current Project: Super Mario Bros Adventure

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Sat Apr 30, 2016 7:54 am

S1eth wrote:
Mario_and_Luigi_55 wrote:Can I make check if player touches ice block?

I have that:

Code: Select all

timerApi.setSecondsLeft(timerApi.getSecondsLeft()-3)
and I want to reduce time every time that player touches ice block.
You can use (Block.collidesWith(player) > 0) to check if a player touches a block.

Code: Select all

for _,iceblock in pairs(Block.get(put_Ice_block_id_here) do
	if (iceblock.collidesWith(player) > 0) then
		--do stuff
	end
end
You need: http://wohlsoft.ru/pgewiki/Block_%28class%29 and http://wohlsoft.ru/pgewiki/LunaLua_glob ... _functions

Now, this would be put into onTick or onLoop.
If you don't want to reduce the timer every frame the player touches the block, you'll need to remember which block the player has touched.
I don't think blocks have some kind of unique id for you to access, so you'd have to get some other unique information, such as the block's x and y coordinates and save them in a table. (doesn't work with moving layers)
Or if you have a very limited number of blocks, you could put each block on their own layer and use the layer to identify the block.

Or you create "invincibility frames" in which your timer cannot be reduced which lasts X ticks after touching an ice block.

Or do you mean ice blocks as in NPCs turned into ice?
Code:

Code: Select all

function onLoopSection0()
	local odlicz=0
	Text.print(odlicz,0,0)
	for e,f in pairs(Block.get(633)) do
		if (f.collidesWith(player)> 0) then
			if odlicz == 0 then 
				timerApi.setSecondsLeft(timerApi.getSecondsLeft()-3)
				odlicz=300
			else
				odlicz=odlicz-1
			end
		end
	end
end
gives me this:
Image
Image
Image

My best levels:
Goomba Lands - 5/10
Stars of the trees - 5.5/10
Koopa Cave - 3.42
Green Grass Hill - 3.42
Grassy Valley - 5.47

User avatar
underFlo
Mario
Mario
Posts: 4481
Joined: Mon Jul 14, 2014 10:44 am
Flair: sup im lesbiab
Current Project: actually nothing i lied to you
Chat Username: underFlo
Contact:

Re: Need help with lua? - LunaLua General Help

Postby underFlo » Sat Apr 30, 2016 7:57 am

collidesWith is a method, so you need to write it with a colon (':') instead of a period ('.'), so it's f:collidesWith(player). Also, I recommend giving all your variables English names, as it makes your code far more comprehensible for other people.
im a girl yo

S1eth
Spiny
Spiny
Posts: 54
Joined: Sat Apr 23, 2016 10:44 am

Re: Need help with lua? - LunaLua General Help

Postby S1eth » Sat Apr 30, 2016 8:17 am

What Spinda said. I did this quickly and obviously without testing.

object:function() is just syntactic sugar for object.function(object), and collidesWith requires two parameters (the block, and the player).

Code: Select all

for e,f in pairs(Block.get(633)) do


As a general recommendation: e,f is your (key, value) pair. Typically written as "k, v".
If you do not use the 'key' in your code, it is common to store it in "_", so: for _,v in pairs(.....) do
Then, everyone who reads your code knows that they can ignore that variable.
As for "f", you should just name it "v" for value, or name it after the type of object you are working with, in this case "block" or "iceblock".
Last edited by S1eth on Sat Apr 30, 2016 9:06 am, edited 2 times in total.

User avatar
Mario_and_Luigi_55
Mega Mole
Mega Mole
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm
Current Project: Super Mario Bros Adventure

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Sat Apr 30, 2016 8:33 am

S1eth wrote:What Spinda said. I did this quickly and obviously without testing.

object:function() is just syntactic sugar for object.function(object), and collidesWith requires two parameters (the block, and the player).

Code: Select all

for e,f in pairs(Block.get(633)) do


As a generation recommendation: e,f is your (key, value) pair. Typically written as "k, v".
If you do not use the 'key' in your code, it is common to store it in "_" for it, so: for _,v in pairs(.....) do
Then, everyone who reads your code knows that they can ignore that variable.
As for "f", you should just name it "v" for value, or name it after the type of object you are working with, in this case "block" or "iceblock".

That's my whole code, so e,f aren't just random:

Code: Select all

local bloki = { 80, 81, 82, 83, 84, 85, 86, 87, 263, 264, 265, 266, 273, 299, 300, 301, 302, 303, 304, 309, 310, 616, 617, 618, 619 }
timerApi = loadAPI("leveltimer");
local particles = API.load("particles");
local odlicz = 0

function onTick()
	for a, b in pairs (Block.get(bloki)) do
		b.slippery = true
	end
	for c, d in pairs (NPC.get(9,-1)) do
		d.id = 185
	end
end

function onLoad()  
	timerApi.setSecondsLeft(300);
	timerApi.setTimerState(true);
end

local effect = particles.Emitter(0, 0, Misc.resolveFile("particles\\p_snow.ini"));
effect:AttachToCamera(Camera.get()[1]);
 
function onCameraUpdate()
    effect:Draw();
end


function onLoopSection0()
	Text.print(odlicz,0,0)
	for e,f in pairs(Block.get(633)) do
		if (f:collidesWith(player) > 0) then
			if odlicz == 0 then 
				timerApi.setSecondsLeft(timerApi.getSecondsLeft()-5)
				odlicz=50
			else
				odlicz=odlicz-1
			end
		end
	end
end
I'm waiting for you to say that the variables aren't in English. I have a link that may help: translate.google.com
Image
Image

My best levels:
Goomba Lands - 5/10
Stars of the trees - 5.5/10
Koopa Cave - 3.42
Green Grass Hill - 3.42
Grassy Valley - 5.47

User avatar
Hoeloe
Grinder
Grinder
Posts: 1055
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 Apr 30, 2016 9:03 am

Mario_and_Luigi_55 wrote: That's my whole code, so e,f aren't just random:
Those variables only exist inside the loop. There's no reason to give them unique names because the variable "a", for example, doesn't exist outside the loop it's used in anyway.

Plus, since you aren't using the keys, it's clearer to use _,v instead.

User avatar
underFlo
Mario
Mario
Posts: 4481
Joined: Mon Jul 14, 2014 10:44 am
Flair: sup im lesbiab
Current Project: actually nothing i lied to you
Chat Username: underFlo
Contact:

Re: Need help with lua? - LunaLua General Help

Postby underFlo » Sat Apr 30, 2016 8:32 pm

Mario_and_Luigi_55 wrote:I'm waiting for you to say that the variables aren't in English. I have a link that may help: translate.google.com
Like honestly if comprehension of your code requires using Google translate for literally every variable then that's just bad programing practice.
im a girl yo

User avatar
WerewolfGD
Wart
Wart
Posts: 3256
Joined: Tue Dec 02, 2014 2:28 am
Flair: Daily life of Alagirez
Current Project: Questioning my life
Chat Username: Alagirez
Contact:

Re: Need help with lua? - LunaLua General Help

Postby WerewolfGD » Sun May 01, 2016 5:12 am

Zant wrote:Is it possible to create a portal system(like in Mari0)with LunaLua?
I usually do that trick with Simple filters with a portal graphic and "function onEvent" code.
Yep, it's possible.

A former SMBX level designner
If you want to to talk with me, go here : Alagirez#2056
Also a furry

Image
YT Channel |MxW2 for those who wants it
My osu! Profile | My twitter
Image

Awooo!

pal4
Fighter Fly
Fighter Fly
Posts: 63
Joined: Wed Dec 23, 2015 7:57 pm

Re: Need help with lua? - LunaLua General Help

Postby pal4 » Mon May 02, 2016 4:45 pm

Enjl wrote:You make a file with the extension .lua
How do I do that?

User avatar
Hoeloe
Grinder
Grinder
Posts: 1055
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 » Mon May 02, 2016 5:59 pm

pal4 wrote:
Enjl wrote:You make a file with the extension .lua
How do I do that?
1. Right click where you want to make the file.
2. Select "New >Text Document"
3. A file will appear named "New Text Document.txt" (see note)
4. Rename the file to "lunadll.lua"

NOTE: If the file is called "New Text Document", and does not have ".txt" on the end, you may have to right click, and go to the folder properties to make sure the file extensions are not hidden, otherwise you can end up with "lunadll.lua.txt", which will not work.

Alternatively, open Notepad, and go to File > Save. From the dropdown menu, make sure "All Files" is selected (NOT "Text Document"), and save the empty file as lunadll.lua.

User avatar
Zant
Volcano Lotus
Volcano Lotus
Posts: 570
Joined: Sat Dec 21, 2013 2:58 pm

Re: Need help with lua? - LunaLua General Help

Postby Zant » Wed May 04, 2016 8:48 am

I want to have a background with five bg layers how do I do dis?

User avatar
Hoeloe
Grinder
Grinder
Posts: 1055
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 » Wed May 04, 2016 10:04 am

Zant wrote:I want to have a background with five bg layers how do I do dis?
http://wohlsoft.ru/pgewiki/ParalX.lua

User avatar
Reign
Mega Mole
Mega Mole
Posts: 298
Joined: Tue Jan 21, 2014 4:22 am
Current Project: On a break from projects.

Re: Need help with lua? - LunaLua General Help

Postby Reign » Thu May 05, 2016 3:52 am

Just starting with Lua and I've finally gotten it to work.

Now I'm wondering how to properly trigger events? Looking at the tutorial didn't make me smarter and I ended up getting errors. So if I want to trigger the event "Toggle Blue" every time the player jumps, what should I put in here?

function onJump()
???
end
Episodes released:

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7622
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 May 05, 2016 5:04 am

Keep in mind onJump only triggers on big jumps.

You can find out how to call the triggerEvent function here:
http://wohlsoft.ru/pgewiki/LunaLua_global_functions
ImageImageImageImage
ImageImageImageImageImageImage

User avatar
Reign
Mega Mole
Mega Mole
Posts: 298
Joined: Tue Jan 21, 2014 4:22 am
Current Project: On a break from projects.

Re: Need help with lua? - LunaLua General Help

Postby Reign » Thu May 05, 2016 5:22 am

Enjl wrote:Keep in mind onJump only triggers on big jumps.

You can find out how to call the triggerEvent function here:
http://wohlsoft.ru/pgewiki/LunaLua_global_functions
Thanks, but I actually already tried that. I'm afraid I'm going to need some dumbing down to get this to work.

function onJump()
triggerEvent(Toggle Blue)
end
Episodes released:

User avatar
Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 7622
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 May 05, 2016 5:25 am

Familiarise yourself with the basics of programming in lua. Strings have to be put in "".
triggerEvent("Toggle Blue")
ImageImageImageImage
ImageImageImageImageImageImage


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest