Page 48 of 76
Re: Need help with lua? - LunaLua General Help
Posted: Mon Feb 20, 2017 3:22 am
by Emral
I'm convinced you didn't copypaste the full code. There are variable declarations missing. Like the error hinted at.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Feb 20, 2017 8:06 am
by PixelPest
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
Re: Need help with lua? - LunaLua General Help
Posted: Mon Feb 20, 2017 3:23 pm
by Inspirited
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.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Feb 20, 2017 3:54 pm
by PixelPest
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
Re: Need help with lua? - LunaLua General Help
Posted: Mon Feb 20, 2017 5:40 pm
by Inspirited
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.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Feb 20, 2017 6:17 pm
by PersonNamedUser
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.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 21, 2017 2:55 am
by Emral
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.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 21, 2017 8:37 pm
by Quantumenace
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.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 21, 2017 8:55 pm
by Emral
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
Re: Need help with lua? - LunaLua General Help
Posted: Tue Feb 21, 2017 9:29 pm
by Quantumenace
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?
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 22, 2017 4:45 am
by Emral
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.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 22, 2017 8:09 am
by ssumday
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...)
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 22, 2017 11:20 pm
by Quantumenace
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.
Re: Need help with lua? - LunaLua General Help
Posted: Thu Feb 23, 2017 7:05 am
by PixelPest
And if you ever do need an integer, you can use math.floor() or math.ceil() to round
Re: Need help with lua? - LunaLua General Help
Posted: Thu Feb 23, 2017 9:05 am
by ssumday
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?
Re: Need help with lua? - LunaLua General Help
Posted: Thu Feb 23, 2017 9:08 am
by PixelPest
It basically means that you haven't set a value to the variable camera. You need to at the top of your file write:
This will grab the camera object which you can then get values from
Re: Need help with lua? - LunaLua General Help
Posted: Thu Feb 23, 2017 10:55 pm
by ssumday
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
Re: Need help with lua? - LunaLua General Help
Posted: Thu Feb 23, 2017 11:01 pm
by Quantumenace
Camera (capitalized) is the name of the table of camera functions. Don't capitalize the name of your variable, or name it something else.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Feb 24, 2017 6:39 am
by PixelPest
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"
Re: Need help with lua? - LunaLua General Help
Posted: Fri Feb 24, 2017 7:39 am
by ssumday
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.