Page 28 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jun 27, 2016 6:13 pm
by seiteom
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!

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jun 27, 2016 6:31 pm
by S1eth
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

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jun 27, 2016 7:57 pm
by Quantix
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.

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jun 27, 2016 8:17 pm
by aero
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.)

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jun 27, 2016 9:47 pm
by PixelPest
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

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jun 27, 2016 10:17 pm
by LM280
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.

Help me with this lua code D:

Posted: Mon Jun 27, 2016 10:27 pm
by Alagirez
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

Re: Need help with lua? - LunaLua General Help

Posted: Mon Jun 27, 2016 10:55 pm
by HenryRichard
You have to put calledEvent between the first pair of parenthesis.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 12:00 am
by aero
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 3:09 am
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 3:53 am
by Reign
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?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 4:03 am
by S1eth
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 7:39 am
by Reign
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?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 7:43 am
by PixelPest
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

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 8:57 am
by Reign
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?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 9:03 am
by PixelPest
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

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 10:14 am
by Emral
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

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 10:57 am
by aero
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 12:20 pm
by Mario_and_Luigi_55
Would it be possible to make a health bar like on this picture:
Image
for both player and a boss?

Re: Need help with lua? - LunaLua General Help

Posted: Tue Jun 28, 2016 12:28 pm
by h2643
There's a boss in 2k16 VVinter Redemption that has a health bar, so yes.