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 » Sat Apr 02, 2016 4:09 pm

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"

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sat Apr 02, 2016 5:16 pm

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 (.

Zeus guy
Spiny
Spiny
Posts: 26
Joined: Fri Dec 20, 2013 12:46 pm

Re: Need help with lua? - LunaLua General Help

Postby Zeus guy » Sun Apr 03, 2016 1:16 pm

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:
Spoiler: show

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?

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sun Apr 03, 2016 1:56 pm

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.

Zeus guy
Spiny
Spiny
Posts: 26
Joined: Fri Dec 20, 2013 12:46 pm

Re: Need help with lua? - LunaLua General Help

Postby Zeus guy » Sun Apr 03, 2016 2:01 pm

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.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sun Apr 03, 2016 3:26 pm

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.

Zeus guy
Spiny
Spiny
Posts: 26
Joined: Fri Dec 20, 2013 12:46 pm

Re: Need help with lua? - LunaLua General Help

Postby Zeus guy » Sun Apr 03, 2016 3:31 pm

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?

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sun Apr 03, 2016 3:34 pm

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.

Zeus guy
Spiny
Spiny
Posts: 26
Joined: Fri Dec 20, 2013 12:46 pm

Re: Need help with lua? - LunaLua General Help

Postby Zeus guy » Sun Apr 03, 2016 3:44 pm

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

underFlo
Wart
Wart
Posts: 4456
Joined: Mon Jul 14, 2014 10:44 am
Flair: sup im lesbiab
Pronouns: They/She
Contact:

Re: Need help with lua? - LunaLua General Help

Postby underFlo » Sun Apr 03, 2016 3:49 pm

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).

Zeus guy
Spiny
Spiny
Posts: 26
Joined: Fri Dec 20, 2013 12:46 pm

Re: Need help with lua? - LunaLua General Help

Postby Zeus guy » Sun Apr 03, 2016 4:32 pm

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!

pal4
Swooper
Swooper
Posts: 63
Joined: Wed Dec 23, 2015 7:57 pm

Re: Need help with lua? - LunaLua General Help

Postby pal4 » Sun Apr 03, 2016 5:39 pm

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!!!! :evil:

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 » Sun Apr 03, 2016 5:43 pm

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!!!! :evil:
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

pal4
Swooper
Swooper
Posts: 63
Joined: Wed Dec 23, 2015 7:57 pm

Re: Need help with lua? - LunaLua General Help

Postby pal4 » Sun Apr 03, 2016 6:37 pm

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.

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 » Sun Apr 03, 2016 7:59 pm

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

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 » Sun Apr 03, 2016 8:30 pm

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.

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 » Sun Apr 03, 2016 8:39 pm

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

pal4
Swooper
Swooper
Posts: 63
Joined: Wed Dec 23, 2015 7:57 pm

Re: Need help with lua? - LunaLua General Help

Postby pal4 » Mon Apr 04, 2016 8:59 am

Image
Note "lunadll" was changed to "lunadll.lua" at a later point.

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 Apr 04, 2016 9:08 am

pal4 wrote:Image
Note "lunadll" was changed to "lunadll.lua" at a later point.
What's your question then?

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 Apr 05, 2016 12:04 am

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.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari