Page 9 of 76
Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 02, 2016 4:09 pm
by Emral
x is expected near y means that the code expected x where it found y. For example if you write:
if ... do
then it will tell you "then expected near do"
Re: Need help with lua? - LunaLua General Help
Posted: Sat Apr 02, 2016 5:16 pm
by Hoeloe
Ness-Wednesday wrote:What does it mean if I get an error saying that ( is expected near if?
This doesn't make sense to me.
It means you've got a ) somewhere without a matching (.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 1:16 pm
by Zeus guy
Alright so I'm doing a thing and there's a thing I can't completely get to work.
First of all, here's the fabulous code:
Code: Select all
local colliders = loadAPI("colliders")
local encrypt = loadAPI("encrypt")
local myData = encrypt.Data(Data.DATA_LEVEL,true)
local small = Graphics.loadImage("small.gif")
local inputs = loadSharedAPI("inputs");
function onStart()
myData:set("flipped",0)
myData:set("onBlock",0)
myData:save()
end
function onExitLevel()
myData:set("flipped",0)
myData:save()
end
function onLoop()
Text.print(myData:get("flipped"),0,0)
Text.print(myData:get("onBlock"),0,16)
--Text.print(jumpheight(),0,0)
for k,v in pairs(NPC.get(152,-1)) do
if (colliders.collide(player, v)) then
myData:set("flipped",0)
myData:save()
end
end
for r,j in pairs(NPC.get(88,-1)) do
if (colliders.collide(player, j)) then
myData:set("flipped",1)
myData:save()
end
end
if myData:get("flipped") == 1 then
Graphics.sprites.mario[1].img = small
if myData:get("onBlock") == 0 then
if player.speedY > -12 then
player.speedY = player.speedY-0.8
end
end
else
Graphics.sprites.mario[1].img = nil
end
if myData:get("flipped") == 1 then
if player:mem(0x14A,FIELD_WORD) == 2 then
myData:set("onBlock",1)
elseif player:mem(0x146,FIELD_WORD) == 2 then
myData:set("onBlock",1)
else
myData:set("onBlock",0)
end
end
end
function onTick()
if myData:get("onBlock") == 1 then
if inputs.state["jump"] == inputs.PRESS then
player.speedY = 20
end
end
end
And now here's the thing: As you can see, this code implements a gravity flip: You touch an smb1 coin and your gravity flips, returning back to normal when you touch a ring. So far three things work: the player's sprite flipping upside down, inverted gravity, and being able to jump while touching the ceiling (but the last one is a bit bugged)
The only problem is that I can't get the player character to stand still in mid-air as if he was touching the ground. I already tried setting player offset 0x146 to 2 but that didn't seem to do anything. Any suggestions?
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 1:56 pm
by Hoeloe
Zeus guy wrote:
The only problem is that I can't get the player character to stand still in mid-air as if he was touching the ground. I already tried setting player offset 0x146 to 2 but that didn't seem to do anything. Any suggestions?
This isn't currently possible to do. It's a lot more complex than just that.
My suggestion for anti-gravity would be the following:
1) Make two versions of the level, one the right way up, one upside down, in separate sections.
2) When you want to flip gravity, move the player and all NPCs to the opposite section.
3) When in the reversed section, apply some code using LunaLua's Capture Buffers to flip the screen upside down.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 2:01 pm
by Zeus guy
Hoeloe wrote:Zeus guy wrote:
The only problem is that I can't get the player character to stand still in mid-air as if he was touching the ground. I already tried setting player offset 0x146 to 2 but that didn't seem to do anything. Any suggestions?
This isn't currently possible to do. It's a lot more complex than just that.
My suggestion for anti-gravity would be the following:
1) Make two versions of the level, one the right way up, one upside down, in separate sections.
2) When you want to flip gravity, move the player and all NPCs to the opposite section.
3) When in the reversed section, apply some code using LunaLua's Capture Buffers to flip the screen upside down.
That's what I feared. Well, thanks anyway.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 3:26 pm
by Hoeloe
Zeus guy wrote:
That's what I feared. Well, thanks anyway.
I mean, you could spawn a block or NPC underneath the player, but that would affect other NPCs as well.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 3:31 pm
by Zeus guy
Hoeloe wrote:I mean, you could spawn a block or NPC underneath the player, but that would affect other NPCs as well.
Yeah I realized that after replying to the other post. An npc with npcblock=0 and npcblocktop=0 wouldn't affect other npcs, right?
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 3:34 pm
by Hoeloe
Zeus guy wrote:Hoeloe wrote:I mean, you could spawn a block or NPC underneath the player, but that would affect other NPCs as well.
Yeah I realized that after replying to the other post. An npc with npcblock=0 and npcblocktop=0 wouldn't affect other npcs, right?
Possibly not, actually. Worth a try.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 3:44 pm
by Zeus guy
Hoeloe wrote:Possibly not, actually. Worth a try.
Well, npcblock=0 seems to work correctly.
But npcblocktop doesn't want to work. Npcs still stand on top of whatever it is. :C
Also, how can I show and hide layers? Everything I've tried doesn't seem to work
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 3:49 pm
by underFlo
Use Layer.get(name) to get a layer by its name, and then use Layer:show(hideSmoke) and Layer:hide(ShowSmoke) (where ShowSmoke is a boolean, if it's true then there won't be any smoke).
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 4:32 pm
by Zeus guy
Spinda wrote:Use Layer.get(name) to get a layer by its name, and then use Layer:show(hideSmoke) and Layer:hide(ShowSmoke) (where ShowSmoke is a boolean, if it's true then there won't be any smoke).
That worked, thank you!
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 5:39 pm
by pal4
I found a way to attach it, but it's saying my board attachment quota has been reached. I haven't attached a single picture yet!!!!

Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 5:43 pm
by PixelPest
pal4 wrote:I found a way to attach it, but it's saying my board attachment quota has been reached. I haven't attached a single picture yet!!!!

Many people have told you how to upload pictures by using imgur and you also received a response from an Admin that the attachment quota likely won't be increased, so you should probably just listen to them. You've asked this question so many times and in the wrong spots, but never listened to anyone
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 6:37 pm
by pal4
I added the .lua, but I'm starting to feel something's up. I updated to 1.3.0.1, and it's notifying me of an attached lunalua. I only tried the level in the editor, but I have some suspicion that it's trying to indicate it will work if I play it in the actual game. I'm not trying it yet since my adventure isn't nearly done yet. Spoiler alert: I am currently working on world 4, and will upload the project when I finish that. The level with the problem is a ghost house serving as a transition between worlds and 4.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 7:59 pm
by PixelPest
What's wrong with this? I pretty much mooched this code off of the documentation but I'm getting the error "unknown collider type":
Code: Select all
local colliders = API.load("colliders");
function onTick()
for _, v in pairs(BGO.get(38)) do
if (colliders.collide(player, v)) then
player:kill();
end
if (colliders.collide(npc, v)) then
npc:kill(9);
Audio.playSFX(16);
end
end
end
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 8:30 pm
by Quantumenace
PixelPest wrote:What's wrong with this? I pretty much mooched this code off of the documentation but I'm getting the error "unknown collider type":
Code: Select all
local colliders = API.load("colliders");
function onTick()
for _, v in pairs(BGO.get(38)) do
if (colliders.collide(player, v)) then
player:kill();
end
if (colliders.collide(npc, v)) then
npc:kill(9);
Audio.playSFX(16);
end
end
end
Which line in lunadll.lua gives the error?
Where do you define the variable "npc"? If it's nil that may be causing that error.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Apr 03, 2016 8:39 pm
by PixelPest
Quantumenace wrote:PixelPest wrote:What's wrong with this? I pretty much mooched this code off of the documentation but I'm getting the error "unknown collider type":
Code: Select all
local colliders = API.load("colliders");
function onTick()
for _, v in pairs(BGO.get(38)) do
if (colliders.collide(player, v)) then
player:kill();
end
if (colliders.collide(npc, v)) then
npc:kill(9);
Audio.playSFX(16);
end
end
end
Which line in lunadll.lua gives the error?
Where you define the variable "npc"? If it's nil that may be causing that error.
Nm. Got it resolvedish
Re: Need help with lua? - LunaLua General Help
Posted: Mon Apr 04, 2016 8:59 am
by pal4

Note "lunadll" was changed to "lunadll.lua" at a later point.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Apr 04, 2016 9:08 am
by PixelPest
pal4 wrote:
Note "lunadll" was changed to "lunadll.lua" at a later point.
What's your question then?
Re: Need help with lua? - LunaLua General Help
Posted: Tue Apr 05, 2016 12:04 am
by Quantumenace
You have a LunaSavedVars file almost as new as the lunadll file, which implies that the script is being run and saving that.
Do you happen to have more than one onLoop() function? I think they will overwrite each other if you try to make more than one with the same name.
Edit: General question: What's the difference between API.load and the other API loading functions? API.load isn't mentioned at all on the wiki.