Need help with lua? - LunaLua General Help

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

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?
Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Need help with lua? - LunaLua General Help

Postby Emral » Mon Feb 20, 2017 3:22 am

I'm convinced you didn't copypaste the full code. There are variable declarations missing. Like the error hinted at.

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

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Mon Feb 20, 2017 8:06 am

Enjl wrote:I'm convinced you didn't copypaste the full code. There are variable declarations missing. Like the error hinted at.
Actually the source is missing the variable that's causing the error (although the code he posted does in fact not include the other three).

https://github.com/suicvne/lunaluascrip ... unadll.lua

Inspirited
Snifit
Snifit
Posts: 242
Joined: Sun Oct 30, 2016 5:58 pm

Re: Need help with lua? - LunaLua General Help

Postby Inspirited » Mon Feb 20, 2017 3:23 pm

I want my episode to be 1-player only and Wario only.

Why doesn't my script work?

Code: Select all

function onStart()
    player.character = CHARACTER_WARIO
end
It's a lunadll.lua file I put in my episode folder. it does nothing in the world map and nothing in my level.

I use SMBX 2.0 beta 3.

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

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Mon Feb 20, 2017 3:54 pm

lunadll.lua is only for levels and is placed in the custom graphics folder of the level. For all levels of the episode it needs to be lunaworld.lua and for the world map it should be entitled lunaoverworld.lua

Inspirited
Snifit
Snifit
Posts: 242
Joined: Sun Oct 30, 2016 5:58 pm

Re: Need help with lua? - LunaLua General Help

Postby Inspirited » Mon Feb 20, 2017 5:40 pm

Thanks, that helped. My script now works.

Is there a way to edit the content of Wario's shop? Can't find it in the documentations.

PersonNamedUser
Reznor
Reznor
Posts: 2882
Joined: Fri Feb 27, 2015 8:07 pm

Re: Need help with lua? - LunaLua General Help

Postby PersonNamedUser » Mon Feb 20, 2017 6:17 pm

PixelPest wrote:As I set before, you have a variable that isn't set to anything at the start such that it is nil. You need to add local frameCount = 0; to the very top (as the first line). Also use onTick() instead of onLoop(). And also, you should really only use code if you understand it and therefore look through the code and learn what it's doing. This is a pretty simple fix.

It's not great code though and has multiple bugs. I'd suggest not using it
I actually did what you told me to do and it pretty much works fine.

I actually fixed it before you edited your post.

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Tue Feb 21, 2017 2:55 am

Inspirited wrote:I want my episode to be 1-player only and Wario only.

Why doesn't my script work?

Code: Select all

function onStart()
    player.character = CHARACTER_WARIO
end
It's a lunadll.lua file I put in my episode folder. it does nothing in the world map and nothing in my level.

I use SMBX 2.0 beta 3.
Lunadll.lua needs to be in the LEVEL folder. A folder inside the episode folder which has the same name as your level.
The episode-wide file is called lunaworld.lua!
For the world map, you want lunaoverworld.lua.

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Tue Feb 21, 2017 8:37 pm

All right, I give up. Why the heck is textblox.Block not showing up? Even the example code on the wiki isn't working:

Code: Select all

local textblox = API.load("textblox");

local block1 = textblox.Block (400,300, "Hello there.", {})

function onLoop()
	textblox.printExt ("Testing!", {x=400,y=150, halign=textblox.HALIGN_MID, valign=textblox.VALIGN_MID})
end
The printExt one works but Block doesn't. If I set the block to pause the game until it's done it does that, so I know it's actually being initiated, but still nothing is actually visible. I'm using Beta 3 if that matters, but it shouldn't because it still works in VVinter Redemption.

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Tue Feb 21, 2017 8:55 pm

Quantumenace wrote:All right, I give up. Why the heck is textblox.Block not showing up? Even the example code on the wiki isn't working:

Code: Select all

local textblox = API.load("textblox");

local block1 = textblox.Block (400,300, "Hello there.", {})

function onLoop()
	textblox.printExt ("Testing!", {x=400,y=150, halign=textblox.HALIGN_MID, valign=textblox.VALIGN_MID})
end
The printExt one works but Block doesn't. If I set the block to pause the game until it's done it does that, so I know it's actually being initiated, but still nothing is actually visible. I'm using Beta 3 if that matters, but it shouldn't because it still works in VVinter Redemption.
Pretty sure wiki default bind is documented wrong. Try bind=textblox.BIND_SCREEN

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Tue Feb 21, 2017 9:29 pm

Thanks but that didn't fix it, it looks like textblox.Block is either broken or its documentation is severely outdated. Using the local_textblox file included with VVinter Redemption finally works.



Edit: has anyone seen any levels that get the current version to work?

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Feb 22, 2017 4:45 am

I use the current version frequently for all my textblox-related shenanigans. You can check out December Collapse for several levels that use it. It's local though because I modified some things that are unrelated to getting a text block to work.
The bind issue is something that worked for someone else who was facing the same problem, though. Curious.

ssumday
Swooper
Swooper
Posts: 78
Joined: Wed May 14, 2014 1:18 pm
Flair: Nope

Re: Need help with lua? - LunaLua General Help

Postby ssumday » Wed Feb 22, 2017 8:09 am

I have a problem when using camera coordinates to NPC spawn. This don't work because need int values. How can I fix this? (I already used camera coordinates to NPC warp and it worked well...)

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Wed Feb 22, 2017 11:20 pm

Ok, for some reason the block is showing up now. Thanks. Now to get it to be in the right place...
ssumday wrote:I have a problem when using camera coordinates to NPC spawn. This don't work because need int values. How can I fix this? (I already used camera coordinates to NPC warp and it worked well...)
NPC.spawn(int npcId, number x, number y, int sectionNumber)

You need an integer for its id and section. The x and y values don't need to be integers.

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

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Thu Feb 23, 2017 7:05 am

And if you ever do need an integer, you can use math.floor() or math.ceil() to round

ssumday
Swooper
Swooper
Posts: 78
Joined: Wed May 14, 2014 1:18 pm
Flair: Nope

Re: Need help with lua? - LunaLua General Help

Postby ssumday » Thu Feb 23, 2017 9:05 am

When using camera values to NPC.spawn coordinates , it shows a error saying "attempt to index upvalue 'camera' (a nil value)". What means it and how to fix?
Means it I am trying to index a function like a table or something?

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

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Thu Feb 23, 2017 9:08 am

It basically means that you haven't set a value to the variable camera. You need to at the top of your file write:

Code: Select all

local camera = Camera.get()[1]; 
This will grab the camera object which you can then get values from

ssumday
Swooper
Swooper
Posts: 78
Joined: Wed May 14, 2014 1:18 pm
Flair: Nope

Re: Need help with lua? - LunaLua General Help

Postby ssumday » Thu Feb 23, 2017 10:55 pm

I've done this before but the error continues. What is wrong?
Here is the code:

Code: Select all

local Camera = Camera.get()[player.section]

function SpawnBombs()
	NPC.spawn(133,Camera.x,Camera.y,player.section)
end

function onTick()
	SpawnBombs()
end

Quantumenace
Chain Chomp
Chain Chomp
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Need help with lua? - LunaLua General Help

Postby Quantumenace » Thu Feb 23, 2017 11:01 pm

Camera (capitalized) is the name of the table of camera functions. Don't capitalize the name of your variable, or name it something else.

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

Re: Need help with lua? - LunaLua General Help

Postby PixelPest » Fri Feb 24, 2017 6:39 am

Also in the first line, use exactly what I posted. In addition to what Quantumenace posted, use the number 1 instead of player.section in the first line. Camera.get() is returning a table of cameras and [1] means "get the first value in the table"

ssumday
Swooper
Swooper
Posts: 78
Joined: Wed May 14, 2014 1:18 pm
Flair: Nope

Re: Need help with lua? - LunaLua General Help

Postby ssumday » Fri Feb 24, 2017 7:39 am

Very thanks, now it worked! My error was writing the number of section on the brackets.

I have another question, not quite an error. I need to make a code activate when a certain NPC makes contact with the player.
It is possible? At the moment I improvised this using player coordinates in relation to NPC coordinates.
I believe there is an easier way, but I haven't found it yet.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 3 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari