Cannot get lua to work

Need help with any SMBX game-related issues? Ask your questions here.

Moderator: Userbase Moderators

asianqueen
Shy Guy
Shy Guy
Posts: 6
Joined: Thu Dec 28, 2017 9:25 pm

Cannot get lua to work

Postby asianqueen » Sat Dec 30, 2017 9:59 pm

I got t his codes from youtube and try to apply. However it's not working. I tried other codes as well and nothing happens when I test the game. I'm using notepad++.

Code: Select all

local playerDirection = 0;

function onloop()
	playerDirection = player:mem(0x106, FIELD_WORD)
end

function onKeyDown(keycode)
	if keycode == KEY_JUMP then
		a = NPC.spawn(1, player.x, player.y - 128,player.section)
		a.speedY = -2;
		a.speedX = 5 * playerDirection;
	end
end

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Cannot get lua to work

Postby PixelPest » Sat Dec 30, 2017 10:04 pm

This is actually really close!

The only issue I can see that would cause it to not work is that "onloop" should have a capital "L" instead of a lowercase "l".

Code: Select all

local playerDirection = 0;

function onloop()
   playerDirection = player:mem(0x106, FIELD_WORD)
end

function onKeyDown(keycode)
   if keycode == KEY_JUMP then
      a = NPC.spawn(1, player.x, player.y - 128,player.section)
      a.speedY = -2;
      a.speedX = 5 * playerDirection;
   end
end
Just be wary of a few things though. (1) onLoop is deprecated and onTick should be used instead. (2) onKeyDown isn't needed here and should be onInputUpdate instead in which you can check player.jumpKeyPressing. (3) Make sure you declare a in a local scape, like you've done playerDirection.

Code: Select all

local playerDirection = 0;

function onTick()
   playerDirection = player:mem(0x106, FIELD_WORD)
end

function onInputUpdate()
   if player.jumpKeyPressing then
      local a = NPC.spawn(1, player.x, player.y - 128,player.section)
      a.speedY = -2;
      a.speedX = 5 * playerDirection;
   end
end

asianqueen
Shy Guy
Shy Guy
Posts: 6
Joined: Thu Dec 28, 2017 9:25 pm

Re: Cannot get lua to work

Postby asianqueen » Sat Dec 30, 2017 10:10 pm

so the syntax and everything else is case sensitive? If it is; this is not a easy language.

PixelPest
Link
Link
Posts: 7111
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Contact:

Re: Cannot get lua to work

Postby PixelPest » Sat Dec 30, 2017 10:11 pm

asianqueen wrote:so the syntax and everything else is case sensitive? If it is; this is not a easy language.
Most languages are case sensitive and this is in fact probably one of the easiest besides drag-and-drop interfaces. Don't worry. It's not bad when you get used to it. It uses a specific pattern; when you have multiple words together (without a space or period) in most cases it will start with a lowercase letter and then all other words will start with capitals: onTick, player.jumpKeyPressing, etc.

asianqueen
Shy Guy
Shy Guy
Posts: 6
Joined: Thu Dec 28, 2017 9:25 pm

Re: Cannot get lua to work

Postby asianqueen » Sat Dec 30, 2017 10:17 pm

yeah, I copy and paste your script then save it. Still not working. I'm not sure what I did wrong. Here's my steps to launch the script.

Open up smbx2.exe > choose editor > Load my level > script > Lunalua Script -> level global. It opens up with notepad++. Pasted the code in there and save it. Run the test.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Cannot get lua to work

Postby Emral » Sat Dec 30, 2017 10:18 pm

asianqueen wrote:yeah, I copy and paste your script then save it. Still not working. I'm not sure what I did wrong. Here's my steps to launch the script.

Open up smbx2.exe > choose editor > Load my level > script > Lunalua Script -> level global. It opens up with notepad++. Pasted the code in there and save it. Run the test.
The editor saves it under the wrong name in Beta 3. You need to rename it to lunadll.lua (inside level folder) or lunaworld.lua (inside episode folder). The name changes to luna.lua in Beta 4.

asianqueen
Shy Guy
Shy Guy
Posts: 6
Joined: Thu Dec 28, 2017 9:25 pm

Re: Cannot get lua to work

Postby asianqueen » Sat Dec 30, 2017 10:24 pm

Enjl wrote:
asianqueen wrote:yeah, I copy and paste your script then save it. Still not working. I'm not sure what I did wrong. Here's my steps to launch the script.

Open up smbx2.exe > choose editor > Load my level > script > Lunalua Script -> level global. It opens up with notepad++. Pasted the code in there and save it. Run the test.
The editor saves it under the wrong name in Beta 3. You need to rename it to lunadll.lua (inside level folder) or lunaworld.lua (inside episode folder). The name changes to luna.lua in Beta 4.
Perfect. It works now. Wow, didn't know it as simple as renaming it. Time to create some useful script. I'm new to it, but hopefully I can come up with something to the community. Thanks a bunch.


Return to “Help and Support”

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari