Page 5 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 21, 2016 4:27 pm
by Nat The Porcupine
Silly question but... How does one remove a collider from existence? I have an API for a custom enemy that I'm working on and I can't figure out how to remove the colliders I attached to it after it dies.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 21, 2016 4:28 pm
by Hoeloe
Mario_and_Luigi_55 wrote: Why? The / is flipped it should be \
This is incorrect. Both / and \ will work, but \ is also the escape character (allowing characters like \n for newline), so to use it as a string it needs to be a double slash: \\. It's also worth noting that particles.lua is NOT included in the SMBX 2.0 beta by default (the update will, however, include it) because it was developed after the beta was released. It is likely that you simply do not have the "particles" folder included in your LuaScriptsLib folder.
Nat The Porcupine wrote:Silly question but... How does one remove a collider from existence? I have an API for a custom enemy that I'm working on and I can't figure out how to remove the colliders I attached to it after it dies.
You simply stop referencing the collider. Once you have no more references to a collider, Lua will destroy it for you. All you need to do is stop testing it, and set all the variables storing the colliders to nil.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 21, 2016 4:32 pm
by HenryRichard
@Mario_and_Luigi_55: Try putting Misc.resolveFile() around the path.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 21, 2016 5:14 pm
by Nat The Porcupine
Hoeloe wrote: You simply stop referencing the collider. Once you have no more references to a collider, Lua will destroy it for you. All you need to do is stop testing it, and set all the variables storing the colliders to nil.
Thanks. That helped me track down the issue I was having.

P.S. This API of yours is simply brilliant!

Re: Need help with lua? - LunaLua General Help

Posted: Mon Mar 21, 2016 11:36 pm
by Alagirez
Pls tell me how to change the fog color... (the fog comes from Particles.lua)
Spoiler: show
I mean fog this
Image

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 1:39 am
by Mario_and_Luigi_55
Hoeloe wrote:
Mario_and_Luigi_55 wrote: Why? The / is flipped it should be \
This is incorrect. Both / and \ will work, but \ is also the escape character (allowing characters like \n for newline), so to use it as a string it needs to be a double slash: \\. It's also worth noting that particles.lua is NOT included in the SMBX 2.0 beta by default (the update will, however, include it) because it was developed after the beta was released. It is likely that you simply do not have the "particles" folder included in your LuaScriptsLib folder.
Nat The Porcupine wrote:Silly question but... How does one remove a collider from existence? I have an API for a custom enemy that I'm working on and I can't figure out how to remove the colliders I attached to it after it dies.
You simply stop referencing the collider. Once you have no more references to a collider, Lua will destroy it for you. All you need to do is stop testing it, and set all the variables storing the colliders to nil.

I have particles in LuaScriptsLib and when I use \\ it gives me :

Debug
C:\Programy\SMBX 2 Open Beta \ LuaScriptsLitAparticles.lua:574: Could not open particle descriptor file C:\Programy\SMBX 2 Open Beta\LuaScriptsLib\particles\p_snow.ini


(Path to p_snow.ini: "C:\Programy\SMBX 2 Open Beta\LuaScriptsLib\particles\p_snow.ini"


and // - Can't fint file

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 4:39 am
by Hoeloe
Mario_and_Luigi_55 wrote: I have particles in LuaScriptsLib and when I use \\ it gives me :

Debug
C:\Programy\SMBX 2 Open Beta \ LuaScriptsLitAparticles.lua:574: Could not open particle descriptor file C:\Programy\SMBX 2 Open Beta\LuaScriptsLib\particles\p_snow.ini


(Path to p_snow.ini: "C:\Programy\SMBX 2 Open Beta\LuaScriptsLib\particles\p_snow.ini"


and // - Can't fint file
Please note that "particles.lua" is not the same thing as the "particles" folder. There should be a folder named "particles" in your LuaScriptsLib folder, with files such as "p_snow.ini" in it.

As I said before, \\ will give you the same result as /, but // makes no sense, as / isn't an escape character, which is why that doesn't work.

I suggest you try re-installing particles.
Camacho wrote:Pls tell me how to change the fog color... (the fog comes from Particles.lua)
Spoiler: show
I mean fog this
Image
You can do this by copying the ini file into your level folder (from LuaScriptsLib/Particles) and adding a line into it. You need the hexadecimal colour code for the colour you want to use, and then add this line to the ini file:

Code: Select all

col=0xFF0000FF
This will tint it red, but if you fill in the hexadecimal colour code like this:

Code: Select all

col=0x######FF
You will get any colour you like. It's also worth noting that when you copy the file into your level folder, you will need to change the path of the ini file in your code, as it will no longer be "particles/p_fog.ini", but just "p_fog.ini".

Alternatively, if you don't want to copy the ini file, you can do it from Lua too. When you create your fog particle system, just call:

Code: Select all

fogEmitter:SetParam("col",particles.ColFromHexRGB(0x######));
Which will do exactly the same thing, but without copying the ini file.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 5:29 am
by Wohlstand
HVMetal wrote:Hello!
So I decided to download LunaLua too... but when I wanted to test my level I got this error message:
Spoiler: show
Image
Version of PGE is 0.3.1.8

Thanks for the help!
I see you placed PGE into folder with non-ASCII path, so, I fixed that bug and PGE can be placed in any folder with no dependency.
https://github.com/Wohlhabend-Networks/ ... 15b3abe7f5

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 5:54 am
by Lukas Old Account
Greetings, I was having the idea of having a boss with a hp bar, but unfortunatly, I have no clue where to start, not even the slightest idea of how making the npc react to the hp bar. I need some help.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 6:54 am
by Mario_and_Luigi_55
Hoeloe wrote:
Mario_and_Luigi_55 wrote: I have particles in LuaScriptsLib and when I use \\ it gives me :

Debug
C:\Programy\SMBX 2 Open Beta \ LuaScriptsLitAparticles.lua:574: Could not open particle descriptor file C:\Programy\SMBX 2 Open Beta\LuaScriptsLib\particles\p_snow.ini


(Path to p_snow.ini: "C:\Programy\SMBX 2 Open Beta\LuaScriptsLib\particles\p_snow.ini"


and // - Can't fint file
Please note that "particles.lua" is not the same thing as the "particles" folder. There should be a folder named "particles" in your LuaScriptsLib folder, with files such as "p_snow.ini" in it.

As I said before, \\ will give you the same result as /, but // makes no sense, as / isn't an escape character, which is why that doesn't work.

I suggest you try re-installing particles.



Still doesn't work i tried copying to level folder. Could not open particle descriptor file.

Code: Select all

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

Code: Select all

grad_1={0,0.2,1},{0,1,0}
colTime={0,0.5,1},{0xFFFFFF00,0xFFFFFF99,0xFFFFFF00}
limit=1000
rate=500:2000
xOffset=-800:800
yOffset=-600:600
rotation=40:45
speedX=-1:-200
speedY=1:250
texture=part_default.png
scale=0.25:0.5
lifetime=1

snow.ini (And yes, I copied texture file)

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 6:57 am
by PixelPest
Also make sure that you're using API.load instead of loadAPI

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 7:08 am
by Mario_and_Luigi_55
PixelPest wrote:Also make sure that you're using API.load instead of loadAPI

Attempt to index global 'API' (a nil value)

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 7:09 am
by Hoeloe
Mario_and_Luigi_55 wrote: Still doesn't work i tried copying to level folder. Could not open particle descriptor file.
Hoeloe wrote: I suggest you try re-installing particles.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 7:13 am
by Mario_and_Luigi_55
Hoeloe wrote:
Mario_and_Luigi_55 wrote: Still doesn't work i tried copying to level folder. Could not open particle descriptor file.
Hoeloe wrote: I suggest you try re-installing particles.
I did that and still nothing...


It shows the error is in particles.lua in line 574 , so this:

Code: Select all

		p,s = parseFile(source);

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 7:35 am
by Hoeloe
Mario_and_Luigi_55 wrote:
PixelPest wrote:Also make sure that you're using API.load instead of loadAPI

Attempt to index global 'API' (a nil value)
AH. If this is your issue you probably have an outdated LunaLua version. Update it.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 7:41 am
by Mario_and_Luigi_55
Hoeloe wrote:
Mario_and_Luigi_55 wrote:
PixelPest wrote:Also make sure that you're using API.load instead of loadAPI

Attempt to index global 'API' (a nil value)
AH. If this is your issue you probably have an outdated LunaLua version. Update it.
Now it's fine. Well, SMBX 2.0 has outdated Lua apparently.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 7:44 am
by Hoeloe
Mario_and_Luigi_55 wrote: Now it's fine. Well, SMBX 2.0 has outdated Lua apparently.
Yes it does. There were a lot of changes made to LunaLua since the first beta was released. The updated version will have an up-to-date version.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 11:20 am
by Mario_and_Luigi_55
Can I somehow save at the beggining of the level the powerup of the player and give it back to him after finishing the level?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 11:31 am
by PixelPest
Mario_and_Luigi_55 wrote:Can I somehow save at the beggining of the level the powerup of the player and give it back to him after finishing the level?
Use the parameter player.powerup

Re: Need help with lua? - LunaLua General Help

Posted: Tue Mar 22, 2016 11:38 am
by Mario_and_Luigi_55
PixelPest wrote:
Mario_and_Luigi_55 wrote:Can I somehow save at the beggining of the level the powerup of the player and give it back to him after finishing the level?
Use the parameter player.powerup

Yes, but at the beggining I have to save the powerup. I made a custom powerup but the script is terrible I guess, because it uses powerup box. That's why I don't know how to save the powerup at the start of the level. Would that work

Code: Select all

function onStart()
local savedpowerup=player.powerup
player.powerup=0
END