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
h2643
Ludwig von Koopa
Ludwig von Koopa
Posts: 2896
Joined: Sat Dec 21, 2013 7:23 am
Flair: Украинец
Current Project: RL
Chat Username: h/hnumbers

Re: Need help with lua? - LunaLua General Help

Postby h2643 » Mon Jun 27, 2016 7:47 am

Creepermon wrote:lunaworld.lua or lunadll.lua?
Here you can see the difference between lunadll.lua and lunaworld.lua: http://wohlsoft.ru/pgewiki/Lua_Files
lunadll.lua only affects the level it's in, lunaworld.lua affects all the levels that are in your game/episode.

seiteom
Goomba
Goomba
Posts: 4
Joined: Mon Jun 27, 2016 5:59 pm

Re: Need help with lua? - LunaLua General Help

Postby seiteom » Mon Jun 27, 2016 6:13 pm

S1eth wrote:
Mario_and_Luigi_55 wrote:
RhysOwens wrote:Has anyone forgotten about me?
I'm not really making levels with LunaLua right now.
I'm messing around with it and experimenting with it so I can get used to it.

The NPCs all take more hits even when I've set the ID to 1 NPC with HealthPoint.lua.


I have same problem.
It's not you. HealthPoint is bugged.

First of all, when you load the API, it automatically sets all NPCs to 3 health. (the creator apparently thought that was a good idea...)
If you don't want that, you'd want to iterate over all NPC ids and call healthPoint.makeNPCNormal(id), but that doesn't work either.

healthPoint.makeNPCNormal is supposed to remove the entry for a specific NPC id from a table, but instead, it removes the value with the index of the npc id, and then pushes all other indexes in the table forward to fill in the gap.
It's pretty broken.

Here is a fix: http://hastebin.com/anerequxef.lua

Create a new text file inside your level folder. Copy and paste the hastebin text in there. Rename the file to HealthPoint.lua (remove the .txt extension)

Test it by having the following code in your lunadll.lua file for your level:

Code: Select all

local healthPoint = API.load("HealthPoint");

--healthPoint.healthbar = true; -- optional, use to activate healthbars above NPCs

for _,id in pairs(healthPoint.allNPCs) do
	healthPoint.makeNPCNormal(id);
end

healthPoint.setNPCHealth(1, 3);
This makes a goomba (ID 1) take 3 hits to kill. All other enemies are unaffected.
I wish S1eths code was still available. Anyway, if we look past the problem that all npcs are assigned 3 health points by default by the HealthPoint API, it is also true that setNPCHealth cannot be called within the onLoop function. If you call it in the onLoad function it works well however, and healthPoint.setNPCHealth(1, 1) will make Goombas die after only one hit.

Hope this helps someone!

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

Re: Need help with lua? - LunaLua General Help

Postby S1eth » Mon Jun 27, 2016 6:31 pm

seiteom wrote:
I wish S1eths code was still available. Anyway, if we look past the problem that all npcs are assigned 3 health points by default by the HealthPoint API, it is also true that setNPCHealth cannot be called within the onLoop function. If you call it in the onLoad function it works well however, and healthPoint.setNPCHealth(1, 1) will make Goombas die after only one hit.

Hope this helps someone!
https://www.mediafire.com/?ue6293oz6dm7id3

User avatar
Quantix
Ripper II
Ripper II
Posts: 328
Joined: Tue Jan 26, 2016 5:04 pm

Re: Need help with lua? - LunaLua General Help

Postby Quantix » Mon Jun 27, 2016 7:57 pm

S1eth wrote:
seiteom wrote:
I wish S1eths code was still available. Anyway, if we look past the problem that all npcs are assigned 3 health points by default by the HealthPoint API, it is also true that setNPCHealth cannot be called within the onLoop function. If you call it in the onLoad function it works well however, and healthPoint.setNPCHealth(1, 1) will make Goombas die after only one hit.

Hope this helps someone!
https://www.mediafire.com/?ue6293oz6dm7id3
I think you should put this in the PGE wiki.
viewtopic.php?f=69&p=286856#p286855

Generic Quote Collection:
Spoiler: show
Skant wrote:The egg will fuck you if you don't catch it
rockythechao wrote:f6 is an over-the-counter generic run-of-the-mill store-brand bootleg knockoff f5
some people wrote:The021stYoshiFromThe021stCentury: Who would win, a tophat wearing a tophat, or hoeloe wearing hoeloe?
Hoeloe: yes
glitch4: f6
rockythecomet: that's a trick question
rockythecomet: a top hat wearing a hoeloe
Waffles & Stuff (timocomlita) wrote:No matter what you do, it's impossible to get rid of the impossible.
Petrifying wrote:Piss off with your sex doll SMBX 2.0
Enjl wrote:it puts a twist on classic 4 step level design which i like to call "2 and a half steps backwards design"

User avatar
Aero
Palom
Palom
Posts: 4611
Joined: Fri Mar 28, 2014 2:51 pm
Flair: Pirate economy
Chat Username: aero

Re: Need help with lua? - LunaLua General Help

Postby Aero » Mon Jun 27, 2016 8:17 pm

I searched but couldn't find anywhere where this question was asked: Is it possible to have variables not reset in a luaworld.lua file when a level is loaded in an episode? When a new level is loaded the integer variables reset to 0 when they should be increasing as you play levels. Also, is it possible to save variable data and then load it? I'm not sure how limited my options are (or what my options even are.)

PixelPest
Link
Link
Posts: 7116
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Mon Jun 27, 2016 9:47 pm

AeroMatter wrote:I searched but couldn't find anywhere where this question was asked: Is it possible to have variables not reset in a luaworld.lua file when a level is loaded in an episode? When a new level is loaded the integer variables reset to 0 when they should be increasing as you play levels. Also, is it possible to save variable data and then load it? I'm not sure how limited my options are (or what my options even are.)
Use the Data class: http://wohlsoft.ru/pgewiki/Data_(class). A tutorial for it can be found here: http://wohlsoft.ru/pgewiki/How_To:_Using_the_data_class. The best way you can avoid variable resets that I can think of is to test one string of data to see if it's nil (if Data:get("stringkey") == nil then) and then only set the data if it is nil. If not, then you will know that you can access the held values from before. Not sure if it was a typo, but it's also lunaworld.lua and not luaworld.lua

User avatar
LM280
Swooper
Swooper
Posts: 122
Joined: Wed Jan 15, 2014 7:10 pm
Current Project: Super Mario-Troid

Re: Need help with lua? - LunaLua General Help

Postby LM280 » Mon Jun 27, 2016 10:17 pm

Spinda wrote:Looks like a fault on the API. Wind reported a similar problem on the irc, and the problem seems to be that it uses Graphics.placeSprite instead of Graphics.drawImage. You could probably update it on your end, but the API should hopefully be updated soon.
Do you know how you would do this? As far as I can tell it hasn't been updated, and I tried replacing all of the Graphics.placeSprite with Graphics.drawImage and that just gave me an error.

User avatar
WerewolfGD
Wart
Wart
Posts: 3265
Joined: Tue Dec 02, 2014 2:28 am
Flair: Legalize Awooo!
Current Project: Howling
Chat Username: Alagirez
Contact:

Help me with this lua code D:

Postby WerewolfGD » Mon Jun 27, 2016 10:27 pm

I'm trying to do a small trick : when an event is called, the player will be killed.

Code: Select all

function onEvent()
	if calledEvent =="KILLPlayer" then
		player:kill()
	end
end
This code doesn't give me any errors but this code doesn't work :/
halp
Yea... I'm back, but with different view.

Known also as Camacho or Harvey36Dice.
Also a furry

Image
Awooo!
If you want to talk with me, go here : Alagirez#2056

User avatar
HenryRichard
Ludwig von Koopa
Ludwig von Koopa
Posts: 2846
Joined: Mon Dec 23, 2013 12:09 pm
Flair: Is this where I type my password?
Contact:

Re: Need help with lua? - LunaLua General Help

Postby HenryRichard » Mon Jun 27, 2016 10:55 pm

You have to put calledEvent between the first pair of parenthesis.
Jesus is my savior.

User avatar
Aero
Palom
Palom
Posts: 4611
Joined: Fri Mar 28, 2014 2:51 pm
Flair: Pirate economy
Chat Username: aero

Re: Need help with lua? - LunaLua General Help

Postby Aero » Tue Jun 28, 2016 12:00 am

PixelPest wrote:
AeroMatter wrote:I searched but couldn't find anywhere where this question was asked: Is it possible to have variables not reset in a luaworld.lua file when a level is loaded in an episode? When a new level is loaded the integer variables reset to 0 when they should be increasing as you play levels. Also, is it possible to save variable data and then load it? I'm not sure how limited my options are (or what my options even are.)
Use the Data class: http://wohlsoft.ru/pgewiki/Data_(class). A tutorial for it can be found here: http://wohlsoft.ru/pgewiki/How_To:_Using_the_data_class. The best way you can avoid variable resets that I can think of is to test one string of data to see if it's nil (if Data:get("stringkey") == nil then) and then only set the data if it is nil. If not, then you will know that you can access the held values from before. Not sure if it was a typo, but it's also lunaworld.lua and not luaworld.lua
This guide kind of helped, as I was able to save my variable data. It's not exactly clear how I can save multiple variables though.

User avatar
Hoeloe
Kamikaze Koopa
Kamikaze Koopa
Posts: 1207
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 » Tue Jun 28, 2016 3:09 am

AeroMatter wrote: This guide kind of helped, as I was able to save my variable data. It's not exactly clear how I can save multiple variables though.
You can just uh... save multiple variables?

The "set" function takes a key and a value, so you can save two different keys to store two different values, and use the "get" function with the key you used to get individual values back.

User avatar
Reign
Ripper II
Ripper II
Posts: 320
Joined: Tue Jan 21, 2014 4:22 am
Current Project: Yet untitled.

Re: Need help with lua? - LunaLua General Help

Postby Reign » Tue Jun 28, 2016 3:53 am

Two issues I'm struggling with. :geek:

a) Reversed controls, meaning when the player presses right key, the character moves left and vice versa.

if(player.leftKeyPressing) then
player.leftKeyPressing = false;
player.rightKeyPressing = true;
end

if(player.rightKeyPressing) then
player.rightKeyPressing = false;
player.leftKeyPressing = true;
end

This doesn't seem to work as the player always goes left no matter which key you press.

b) A victory sound when the level ends

The level ends with a door warp which you need a key for. I currently have this set up in a way that once the key "dies", an event with a sound will occur. This works fine, however when the player throws the key to lava for example, the victory sound also plays. Another thing is when you play as Link, the sound plays immediately when you collect the key, not when you use it at the door.

So I was wondering if this victory sound when you enter a door could be done with LunaLua?
Episodes released:

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

Re: Need help with lua? - LunaLua General Help

Postby S1eth » Tue Jun 28, 2016 4:03 am

Reign wrote:Two issues I'm struggling with. :geek:

a) Reversed controls, meaning when the player presses right key, the character moves left and vice versa.

if(player.leftKeyPressing) then
player.leftKeyPressing = false;
player.rightKeyPressing = true;
end

if(player.rightKeyPressing) then
player.rightKeyPressing = false;
player.leftKeyPressing = true;
end

This doesn't seem to work as the player always goes left no matter which key you press.
You want to replace "end if" with "elseif".

Currently, you are turning all LEFT into RIGHT. And then, you are turning all RIGHT into LEFT., which includes all the LEFT which were just turned into RIGHT.

But what you want is: if X then Y elseif Y then X.

For your other issue, you will probably need lua for that. The thing is that your "key dies" trigger condition is not really what you want, since as you said, the key dies when Link picks it up.
If your door has a lock (bg object), you can check if the lock doesn't exist anymore with lua during onTick() and make that your trigger,
or check if the player with key collides with the locked door.

User avatar
Reign
Ripper II
Ripper II
Posts: 320
Joined: Tue Jan 21, 2014 4:22 am
Current Project: Yet untitled.

Re: Need help with lua? - LunaLua General Help

Postby Reign » Tue Jun 28, 2016 7:39 am

S1eth wrote:For your other issue, you will probably need lua for that. The thing is that your "key dies" trigger condition is not really what you want, since as you said, the key dies when Link picks it up.
If your door has a lock (bg object), you can check if the lock doesn't exist anymore with lua during onTick() and make that your trigger,
or check if the player with key collides with the locked door.
The reverse control works now, thank you!

Do you have an example (or could you point me to the right direction) on how you would check if a lock does not exist in the level anymore?
Episodes released:

PixelPest
Link
Link
Posts: 7116
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue Jun 28, 2016 7:43 am

Reign wrote:
S1eth wrote:For your other issue, you will probably need lua for that. The thing is that your "key dies" trigger condition is not really what you want, since as you said, the key dies when Link picks it up.
If your door has a lock (bg object), you can check if the lock doesn't exist anymore with lua during onTick() and make that your trigger,
or check if the player with key collides with the locked door.
The reverse control works now, thank you!

Do you have an example (or could you point me to the right direction) on how you would check if a lock does not exist in the level anymore?
You could check to see if the number of instances of that NPC is nil (or it might be 0, not exactly sure) or you could set a Death event for that NPC and check if the event has been triggered via LunaLua

User avatar
Reign
Ripper II
Ripper II
Posts: 320
Joined: Tue Jan 21, 2014 4:22 am
Current Project: Yet untitled.

Re: Need help with lua? - LunaLua General Help

Postby Reign » Tue Jun 28, 2016 8:57 am

Hmm, thanks for the advice but I'm at a dead end again. :) I tried something like

function onTick()
Text.print(tostring(BGO.count()), 0, 0)
if(BGO.count() == 51) then
triggerEvent("Exit level");
end

end

The idea is that I have 52 BGOs in the level and once the lock disappears there should be 51. However, once the lock disappears there still seems to be 52 BGOs in the level (I made the text.print to check that). The lock is not an NPC afaik so I'm not sure if a death event can be made for it. Or am I mistaken on that?
Episodes released:

PixelPest
Link
Link
Posts: 7116
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Tue Jun 28, 2016 9:03 am

Reign wrote:Hmm, thanks for the advice but I'm at a dead end again. :) I tried something like

function onTick()
Text.print(tostring(BGO.count()), 0, 0)
if(BGO.count() == 51) then
triggerEvent("Exit level");
end

end

The idea is that I have 52 BGOs in the level and once the lock disappears there should be 51. However, once the lock disappears there still seems to be 52 BGOs in the level (I made the text.print to check that). The lock is not an NPC afaik so I'm not sure if a death event can be made for it. Or am I mistaken on that?
Oh sorry. I thought you were referring to the blockade NPC that you stick a key in and then it disappears, allowing you to pass

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

Re: Need help with lua? - LunaLua General Help

Postby Enjl » Tue Jun 28, 2016 10:14 am

There's a player offset for link carrying a key. You can keep track of when he picks it up and when he loses it.
http://wohlsoft.ru/pgewiki/SMBX_Player_Offsets
The ABC of Creation
________________________________________________________
Image

User avatar
Aero
Palom
Palom
Posts: 4611
Joined: Fri Mar 28, 2014 2:51 pm
Flair: Pirate economy
Chat Username: aero

Re: Need help with lua? - LunaLua General Help

Postby Aero » Tue Jun 28, 2016 10:57 am

Hoeloe wrote:
AeroMatter wrote: This guide kind of helped, as I was able to save my variable data. It's not exactly clear how I can save multiple variables though.
You can just uh... save multiple variables?

The "set" function takes a key and a value, so you can save two different keys to store two different values, and use the "get" function with the key you used to get individual values back.
I didn't know that, thanks.

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 » Tue Jun 28, 2016 12:20 pm

Would it be possible to make a health bar like on this picture:
Image
for both player and a boss?
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


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest