Page 19 of 76
Re: Need help with lua? - LunaLua General Help
Posted: Fri Apr 29, 2016 1:37 pm
by lotus006
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
Re: Need help with lua? - LunaLua General Help
Posted: Fri Apr 29, 2016 1:39 pm
by Emral
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.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 30, 2016 7:17 am
by Mario_and_Luigi_55
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.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 30, 2016 7:34 am
by S1eth
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?
Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 30, 2016 7:54 am
by Mario_and_Luigi_55
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:

Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 30, 2016 7:57 am
by underFlo
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.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 30, 2016 8:17 am
by S1eth
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".
Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 30, 2016 8:33 am
by Mario_and_Luigi_55
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
Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 30, 2016 9:03 am
by Hoeloe
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.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 30, 2016 8:32 pm
by underFlo
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.
Re: Need help with lua? - LunaLua General Help
Posted: Sun May 01, 2016 5:12 am
by Alagirez
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.
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 02, 2016 4:45 pm
by pal4
Enjl wrote:You make a file with the extension .lua
How do I do
that?
Re: Need help with lua? - LunaLua General Help
Posted: Mon May 02, 2016 5:59 pm
by Hoeloe
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.
Re: Need help with lua? - LunaLua General Help
Posted: Wed May 04, 2016 8:48 am
by Zant
I want to have a background with five bg layers how do I do dis?
Re: Need help with lua? - LunaLua General Help
Posted: Wed May 04, 2016 10:04 am
by Hoeloe
Zant wrote:I want to have a background with five bg layers how do I do dis?
http://wohlsoft.ru/pgewiki/ParalX.lua
Re: Need help with lua? - LunaLua General Help
Posted: Thu May 05, 2016 3:52 am
by Reign
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
Re: Need help with lua? - LunaLua General Help
Posted: Thu May 05, 2016 5:04 am
by Emral
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
Re: Need help with lua? - LunaLua General Help
Posted: Thu May 05, 2016 5:22 am
by Reign
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
Re: Need help with lua? - LunaLua General Help
Posted: Thu May 05, 2016 5:25 am
by Emral
Familiarise yourself with the basics of programming in lua. Strings have to be put in "".
triggerEvent("Toggle Blue")
Re: Need help with lua? - LunaLua General Help
Posted: Thu May 05, 2016 5:32 am
by Reign
Enjl wrote:Familiarise yourself with the basics of programming in lua. Strings have to be put in "".
triggerEvent("Toggle Blue")
Thanks, now that I got this one I think I'll be able to proceed for quite a while without stupid questions.
