Page 6 of 47

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Tue Apr 07, 2015 12:59 pm
by Kevsoft
Sure, backwards compatbility will always be.

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Sat May 02, 2015 2:58 pm
by HenryRichard
Is there a way to trigger events when you collide with a block? I know there is if you use autocode, but I'd rather use Lua if it's possible.

EDIT: Also, is there any way to scale/transform images that are displayed? We could do a ton of cool things if that's possible...

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Sat May 02, 2015 4:39 pm
by Kevsoft
HenryRichard wrote:Is there a way to trigger events when you collide with a block? I know there is if you use autocode, but I'd rather use Lua if it's possible.
Yes there is. You can use the Block:collidesWith function + triggerEvent function. But I don't have a sample code at the moment.

HenryRichard wrote:EDIT: Also, is there any way to scale/transform images that are displayed? We could do a ton of cool things if that's possible...
not yet, but with the new opengl render coming, we will see what is possible :P

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Sat May 02, 2015 5:30 pm
by HenryRichard
Kevsoft wrote:
HenryRichard wrote:Is there a way to trigger events when you collide with a block? I know there is if you use autocode, but I'd rather use Lua if it's possible.
Yes there is. You can use the Block:collidesWith function + triggerEvent function. But I don't have a sample code at the moment.
That's good to know - to bad I can't figure out how to get it to work since I'm a complete l=Lua noob and all I know is based off of Java and C. If you do happen to make an example at some point, I'd like to see it.
Kevsoft wrote:
HenryRichard wrote:EDIT: Also, is there any way to scale/transform images that are displayed? We could do a ton of cool things if that's possible...
not yet, but with the new opengl render coming, we will see what is possible :P
Let's hope for the best - even if we can't scale or rotate, we're still gonna be able to do great things!

Also, I can't seem to get a line of text that displays your current star count. I tried to use this -

Code: Select all

Text.print(mem(0x00B251E0,FIELD_WORD),48,16);
but I get an error every time I test -
Image

Any idea what I'm doing wrong?

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Sun May 03, 2015 12:58 am
by Kevsoft
LunaLua 0.7 is still not released yet. That's why Text.print doesn't work.

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Fri May 15, 2015 9:37 am
by Onule
Any estimate on 0.7's release date? Been skimming through the talkhaus thread and you've guys been working on a opengl renderer? Sounds awesome.

Also, is it possible to make it so while holding down a key, it adds +1 to a variable?

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Fri May 15, 2015 2:10 pm
by Wohlstand
Onule wrote:Also, is it possible to make it so while holding down a key, it adds +1 to a variable?
Use on key event (look at documentation) and var=var+1

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Fri May 15, 2015 4:08 pm
by Onule
Tried messing with that, only managed to make it add +1 every time I pressed the key.

When I tried something like this, the game freezes.

Code: Select all

function onKeyDown(keycode)
	while keycode == KEY_DOWN do
		a = a + 1
	end
end

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Fri May 15, 2015 4:44 pm
by Kevsoft
That's because you are in a endless loop.
You have to do this like that:

Code: Select all

local a = 0
function onKeyDown(keycode)
   if(keycode == KEY_DOWN) do
      a = a + 1
   end
end

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Fri May 15, 2015 6:22 pm
by Onule
I did that before, only adds 1 every time the key is pressed, I want to make it so that while I'm holding down the key, it would add 1, so I could use it like a timer.

Example would be this


I tried to mess with this, but couldn't get it to work.
Image

also if do :roll:

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Sat May 16, 2015 1:22 am
by Kevsoft
Try:

Code: Select all

if(player:mem(0xF4, FIELD_WORD) == -1)then
a = a + 1
end

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Sat May 16, 2015 8:57 pm
by Onule
Oh it's -1? I tried that before but with 1 instead.

Just making sure, if it perfectly fine to have something like this on a loop?

Code: Select all

if (player.x > -200000) then
		triggerEvent("ShowLayer")
	  else	
		triggerEvent("HideLayer")
	end
end
Would it be constantly triggering an event or only when possible?

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Sun May 17, 2015 1:45 am
by Kevsoft
It would constantly trigger the event. The trick is using a local variable in the gloal scope:

Code: Select all

local isLayerShown = false
function onLoop()
    if (player.x > -200000 and isLayerShown == false) then
        triggerEvent("ShowLayer")
        isLayerShown = true
    else
        if(isLayerShown == true)then
              triggerEvent("HideLayer")
        end
   end
end

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Sun May 17, 2015 5:08 pm
by Onule
Wouldn't that cause the layer to show for just a frame?

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Mon May 18, 2015 12:43 am
by Kevsoft
Oh, yea, you right. You have to check also in the other direction.

Here:

Code: Select all

local isLayerShown = false
function onLoop()
    if (player.x > -200000 and isLayerShown == false) then
        triggerEvent("ShowLayer")
        isLayerShown = true
    elseif(player.x <= -200000 and isLayerShown == true)then
        triggerEvent("HideLayer")
        isLayerShown = false
   end
end

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Mon May 18, 2015 10:18 am
by lighthouse64
I have a problem :/

Code: Select all

local g = 3
gravity = g
onJump(gravity = g*-1)
It seems that line 3 has an error, but I don't see anything wrong with the code. :/

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Mon May 18, 2015 12:27 pm
by Kevsoft
1.) You need to work with defines, see here:
http://engine.wohlnet.ru/pgewiki/SMBX_Fields
2.) You calling the function onJump, rather than defining as a event.

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Tue May 19, 2015 5:19 pm
by HenryRichard
I'm having a big problem. I'm using this code:

Code: Select all

function onLoop()
	cannonBlocks = findblocks(34);
	for k,v in pairs(cannonBlocks) do
      if(v:collidesWith(player) == 1) then
			cannon(player);
		elseif(v:collidesWith(player2) == 1) then
			cannon(player2);
		end
    end
end

function cannon(thePlayer)
	thePlayer.x = thePlayer.x + 240;
	thePlayer.y = thePlayer.y - 256;
	thePlayer.speedX = 12;
	thePlayer.speedY = -12;
	thePlayer.HasJumped = -1;
	thePlayer.FacingDirection = 1;
	--playSFXSDL("SM64-cannonfire.wav");
end
The level loads fine, but the game freezes when I test, and I get a "SuperMarioBrosX.org has stopped working" window. Is this a problem with my installation or my code or my computer or something else?

What really frustrates me is that it was working just fine but then just stopped working...

EDIT: I just tried re-installing lunalua, and I think it was a bit outdated. However, it's still freezing.

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Wed May 20, 2015 4:04 am
by Kevsoft
Overall it looks fine to me. I will test it, when I am back home.

EDIT: Uhm one note here. Maybe try:

Code: Select all

function onLoop()
   cannonBlocks = findblocks(34);
   for k,v in pairs(cannonBlocks) do
      if(v:collidesWith(player) == 1) then
         cannon(player);
      if(player2) then
         if(v:collidesWith(player2) == 1) then
            cannon(player2);
         end
      end
    end
end

Re: LunaLua - Lunadll with lua [Streaming Question Poll]

Posted: Wed May 20, 2015 1:21 pm
by HenryRichard
Thanks, it's working perfectly now!
I'll remember to check if player2 exists next time.