Page 31 of 50

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 14:12
by Hoeloe
Lejes wrote:There seems to be some kind of problem with this code.

Code: Select all

if (player.holdingNPC ~= nil) then
		local npcID = player.holdingNPC.id
		if (npcID == 31) then
			--printText(tostring(v.speedX), 3, 0, 0);
			--printText(tostring(v.speedY), 3, 0, 32);
			holding_key = true;
		end
	end
But I can't figure out what it is. It checks if the player is holding a key just fine, but crashes if the player has a Yoshi or turns into a Tanooki statue. The problem seems to be specifically with the line where npcID is declared.
It's possible that something is being invalidated at some point. See if this helps:

Code: Select all

if (player.isValid and player.holdingNPC ~= nil) then
		local npcID = player.holdingNPC.id
		if (npcID == 31) then
			--printText(tostring(v.speedX), 3, 0, 0);
			--printText(tostring(v.speedY), 3, 0, 32);
			holding_key = true;
		end
	end
Otherwise, stick a bunch of windowDebugs in there to see how many execute before the crash. You can pinpoint which line the crash happens on that way.

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 14:16
by Rednaxela
Alice wrote:Out of curiosity, since there's no readme in the zip or install instructions in the op (only update instructions), do I just unzip the LunaLua stuff straight into the base folder for SMBX?
There's a reason there's only update instructions in a way. You need to start with a version of smbx.exe that's been patched to knows to load LunaDLL.dll in the first place. Vanilla smbx.exe won't work.
Lejes wrote:
S1eth wrote:Tried and no crashes, but: while on Yoshi/in statue form, player.holdingNPC.id is always 0 (whether you'e holding an item or not).
I suspected Yoshi and statue forms are altering held item IDs, but if they're ID 0 I'm not sure why that would cause a problem. npcID would be declared as 0, and the conditional immediately after would just evaluate to false. What version of LunaLua are you using? I'm somewhat sure this wasn't happening before, and I might roll it back to check. I've got the most recent now.
Can you check the value of player.HeldNPCIndex before that line maybe? Wondering what that is when the problem occurs.
You might also try including a "player.holdingNPC.isValid" check.

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 14:43
by Alice
Rednaxela wrote:There's a reason there's only update instructions in a way. You need to start with a version of smbx.exe that's been patched to knows to load LunaDLL.dll in the first place. Vanilla smbx.exe won't work.
This should probably be made clearer then because it's not at all clear. With there only being update instructions in the OP (and nothing about needing a specific version of SMBX) it's kinda confusing for anyone who's new to the subject.

And using an incorrect version of SMBX shouldn't be my issue either to be clear on that for anyone who might have ideas why it's not working for me. I'm using the one from MaGLx2 so it should work with that.

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 14:52
by Kevsoft
Sorry about that. I updated the main topic, now it should be a bit clearer.

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 14:54
by Lejes

Code: Select all

local holding_key = false;
	if ((player.holdingNPC ~= nil) and (player.holdingNPC.isValid)) then
		local npcID = player.holdingNPC.id
		if (npcID == 31) then
			--printText(tostring(v.speedX), 3, 0, 0);
			--printText(tostring(v.speedY), 3, 0, 32);
			holding_key = true;
		end
	end
This has (tentatively?) fixed it, for both Tanooki and mounts. I guess that validity check was all it needed. I thought that checking it against nil would be enough, but it wasn't. Still pretty unfamiliar with Lua.

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 14:58
by Hoeloe
Lejes wrote: This has (tentatively?) fixed it, for both Tanooki and mounts. I guess that validity check was all it needed. I thought that checking it against nil would be enough, but it wasn't. Still pretty unfamiliar with Lua.
It's a problem with how SMBX handles objects. It often clears out the relevant data, but not in a way that is considered "nil" in Lua. If Lua returns, for example, the number 0 instead of a player object, then that's still not nil (which means no object at all), but at the same time causes some really funky behaviour if you try and treat it as a player object. Validity checks are there to make sure things like that don't happen.

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 15:03
by S1eth
When you use the Tanookie Statue, (player.holdingNPC ~= nil) evaluates to TRUE.
Then, you try to access player.holdingNPC.id (even though you're not holding any item), which causes the error.

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 15:26
by Kevsoft
Which error do you get?

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 17:53
by Isocitration
Anyone know what property of npcs prevents them from dying when thrown inside a wall? Most non-enemy carryable npcs seem to behave in this way. The closest I've come to figuring it out is to set "Is Interactable" for the npc, but while that indeed prevents death in that way, it has the unfortunate side effect of making the npc disappear when touched by the player.

If nothing else, can an npc be assigned to use the AI of a different npc? Like a smb2 mushroom block that moves as a paragoomba or similar.

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 18:04
by Rednaxela
Isocitration wrote:Anyone know what property of npcs prevents them from dying when thrown inside a wall? Most non-enemy carryable npcs seem to behave in this way. The closest I've come to figuring it out is to set "Is Interactable" for the npc, but while that indeed prevents death in that way, it has the unfortunate side effect of making the npc disappear when touched by the player.

If nothing else, can an npc be assigned to use the AI of a different npc? Like a smb2 mushroom block that moves as a paragoomba or similar.
You can make an NPC totally invincible by setting offset 0x156 to a >=2 value each tick. Would that do the job for you? Since you mention "when thrown", you could also do this conditionally only when the NPC is in a thrown state.

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 18:41
by S1eth
Kevsoft wrote:Which error do you get?
It's just an "Invalid NPC-Pointer" as described by Hoeloe. (unless you're asking about something else)

Re: Presenting: Lunadll for Lua!

Posted: 09 Mar 2015, 19:31
by Isocitration
Rednaxela wrote:You can make an NPC totally invincible by setting offset 0x156 to a >=2 value each tick. Would that do the job for you? Since you mention "when thrown", you could also do this conditionally only when the NPC is in a thrown state.
Unfortunately it doesn't seem like invincibility frames will prevent block related death.

Re: Presenting: Lunadll for Lua!

Posted: 10 Mar 2015, 20:47
by S1eth
How would you go about creating a wind effect? (wind pushing your character). I tried playing around and ran into problems.

1. speed. Running/Flying is impossible if I lower the speed too much. And if I change the speed once, I lose all information on what the normal speed would be. (=I cannot have the speed always be normal speed + flat value)

2. changing player coordinates. If I push the player by changing coordinates, you can very easily glitch through walls. I wanted to check how the "conveyor" NPC handles this, but then I saw even that one makes you glitch through walls.

I've come up with this code to change the player's distance traveled per frame while moving (both decreasing and increasing), and haven't run into any glitches so far, but what I would really want is a wind that can push you around while standing (and not push you through walls), and can also push NPCs around.

Code: Select all

local lastFrameX;
local deltaX;

function onLoad()
	lastFrameX = player.x;
end

function onLoop()
	deltaX = player.x - lastFrameX;
	lastFrameX = player.x;
	
	if(math.abs(player.speedX) > 0.6) then
		player.x = player.x - player.speedX*0.5; --halfs the X distance traveled per frame
	end
	
	printText("speedX: "..tostring(player.speedX),3,0,60);
	printText("deltaX: "..tostring(deltaX),3,0,80);
	printText("coordX: "..tostring(player.x),3,0,120);
end

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 01:35
by romajiQuadhash
Horikawa Otane wrote:Would it be possible to play a random mp3 from an array of mp3s in the intro.lvl stage via lunalua?
I think you could play a random .ogg or .wav.

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 01:46
by Wohlstand
Horikawa Otane wrote:Would it be possible to play a random mp3 from an array of mp3s in the intro.lvl stage via lunalua?
Use the math.random(x) function
Where x - total number of musics in the array.
Don't forget rules:
1) music of section should be switched to "none". It will release music stream for our purposes and we can freely use lua to play any music files.
2) all paths for musicOpen function relative to level custom directory. Use "../" prefix to take music from episode.
3) use onLoop() event and boolean variables-semaphores to trigger music playback

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 03:26
by Alice
So thanks to romajiQuadhash I have a copy of A2XT that works with LunaLua but I'm still really confused on why it wasn't working for me in the first place. Maybe someone here will have some idea. I used the copy of SMBX that was linked in the MaGLx2 OP, downloaded all the files from the OP here, and dumped them in the same place they're located in romajiQuadhash's copy of A2XT. But despite all that it still doesn't work at all.

Not too huge an issue since I have a working copy now and can just copy over the original graphics for what I wanted but it seems really odd that it doesn't work and might be some issue that needs to get figured out or something.

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 04:35
by Isocitration
Is there a way to check if a key has just been tapped, as opposed to being held down? I swear I remember reading something about this but my searching isn't yielding anything.

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 05:04
by Rednaxela
Alice wrote:Not too huge an issue since I have a working copy now and can just copy over the original graphics for what I wanted but it seems really odd that it doesn't work and might be some issue that needs to get figured out or something.
Hmm... do you have a copy of it that doesn't work that you can put in a zip?
Isocitration wrote:Is there a way to check if a key has just been tapped, as opposed to being held down? I swear I remember reading something about this but my searching isn't yielding anything.
Just been tapped... so you want onKeyUp?

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 05:47
by Alice
Rednaxela wrote:Hmm... do you have a copy of it that doesn't work that you can put in a zip?
Sure, my non-working version can be grabbed here.

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 05:51
by Rednaxela
Alice wrote:Sure, my non-working version can be grabbed here.
The HTTP Server wrote:404 - File or directory not found.

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 05:51
by Isocitration
Rednaxela wrote:
Isocitration wrote:Is there a way to check if a key has just been tapped, as opposed to being held down? I swear I remember reading something about this but my searching isn't yielding anything.
Just been tapped... so you want onKeyUp?
Turns out onKeyDown is what ended up suiting my needs best. Thanks for pointing me in the right direction.

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 06:29
by Hoeloe
Wohlstand wrote: 2) all paths for musicOpen function relative to level custom directory. Use "../" prefix to take music from episode.
Not sure about this one. There was a recent update that allowed some functions (such as loadImage) to accept absolute paths as well (getSMBXDirectory() is useful for that), but I don't know if musicOpen was among them.

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 06:34
by Rednaxela
Hoeloe wrote:
Wohlstand wrote:2) all paths for musicOpen function relative to level custom directory. Use "../" prefix to take music from episode.
Not sure about this one. There was a recent update that allowed some functions (such as loadImage) to accept absolute paths as well (getSMBXDirectory() is useful for that), but I don't know if musicOpen was among them.
I can confirm from looking at that revision that that change only affected playSFXSDL and loadImage, not musicOpen.

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 06:56
by Alice
Rednaxela wrote:
Alice wrote:Sure, my non-working version can be grabbed here.
The HTTP Server wrote:404 - File or directory not found.
Er, well that's really weird. The file is clearly there on my server but cannot be accessed for some weird reason. If this doesn't work I'll try uploading it to some place else such as MediaFire. This time it looks to work for me though so I'm really not sure what's up with the previous upload.

Re: Presenting: Lunadll for Lua!

Posted: 11 Mar 2015, 17:47
by Arctangent
I wanted to try and learn this, but I've hit a stumbling block that I can't see to find the answer to: my code just flat-out doesn't seem to get noticed. I have the modified .exe, all of the LunaLua stuff and its .dlls have been installed, the LunaLua version numbering shows up on SMBX, the sounds are all strange and stuff, all that stuff. But when I go make a level and shove lunadll.lua into its resource folder, I can't even get a "Hello, world!" to pop up. Is there some sort of extra step I'm missing?