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 » Tue Mar 22, 2016 11:58 am

0 is not a valid index for the player powerup. It goes from 1 to 7 where the numbers are the same as those on the player character sheet filename.

If you want to do something with the reserve box, try
Player.reservePowerup = NPCID (where NPCID is the ID of the NPC you want to store, from 0 to 300).

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 » Tue Mar 22, 2016 12:02 pm

Enjl wrote:0 is not a valid index for the player powerup.
I believe 0 maps to the small sprite, though don't quote me on that.

Also, "END" will not work. Case matters in most programming languages, so you have to use "end".

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Tue Mar 22, 2016 12:13 pm

Enjl wrote:0 is not a valid index for the player powerup. It goes from 1 to 7 where the numbers are the same as those on the player character sheet filename.

If you want to do something with the reserve box, try
Player.reservePowerup = NPCID (where NPCID is the ID of the NPC you want to store, from 0 to 300).

Well, the point is that I'm already using it. How can I improve the code?
Level

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 Mar 22, 2016 12:18 pm

reposted to hastebin for convenience
http://hastebin.com/ataqafodaf.lua

Looking over this right now and it seems very dodgy. Let me try out the level.

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Tue Mar 22, 2016 12:21 pm

Enjl wrote:reposted to hastebin for convenience
http://hastebin.com/ataqafodaf.lua

Looking over this right now and it seems very dodgy. Let me try out the level.

I know :) terrible coding ?

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 Mar 22, 2016 12:24 pm

Where exactly are you saving the player's powerup at the start of the level?

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Tue Mar 22, 2016 12:25 pm

Enjl wrote:Where exactly are you saving the player's powerup at the start of the level?

I want to do that and I don't know how to begin. I tried

Code: Select all

function onStart()
local savedpowerup=player.powerup
player.powerup=0
end
But it returns NIL...

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 Mar 22, 2016 12:27 pm

Those lines aren't even in the code from the level file which you posted.

function onStart()
if player.powerup == PLAYER_BIG then
player.powerup = PLAYER_SMALL
player.reservePowerup = 9
end
end

is the onStart function from there.

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Tue Mar 22, 2016 12:30 pm

Enjl wrote:Those lines aren't even in the code from the level file which you posted.

function onStart()
if player.powerup == PLAYER_BIG then
player.powerup = PLAYER_SMALL
player.reservePowerup = 9
end
end

is the onStart function from there.
I removed them, they do nothing

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 Mar 22, 2016 12:31 pm

Mario_and_Luigi_55 wrote:
Enjl wrote:Those lines aren't even in the code from the level file which you posted.

function onStart()
if player.powerup == PLAYER_BIG then
player.powerup = PLAYER_SMALL
player.reservePowerup = 9
end
end

is the onStart function from there.
I removed them, they do nothing
That's not true. If the player enters the level big, they will get a mushroom in the reserve box and become small.

Anyways, try replacing "player.powerup = 0" with "player.powerup = PLAYER_SMALL"

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Tue Mar 22, 2016 12:36 pm

Enjl wrote:
Mario_and_Luigi_55 wrote:
Enjl wrote:Those lines aren't even in the code from the level file which you posted.

function onStart()
if player.powerup == PLAYER_BIG then
player.powerup = PLAYER_SMALL
player.reservePowerup = 9
end
end

is the onStart function from there.
I removed them, they do nothing
That's not true. If the player enters the level big, they will get a mushroom in the reserve box and become small.

Anyways, try replacing "player.powerup = 0" with "player.powerup = PLAYER_SMALL"
They start as small if they have mushroom, because it's different powerup than the mushroom. How did the mushroom turn into spring mushroom? With magic? That's why I used this lin just to show players:Hey, that's not the normal mushroom...

Plus PLAYER_SMALL made me start small, but saved NIL to the savedpowerup, when I was starting as Hammer Mario.
Last edited by Mario_and_Luigi_55 on Tue Mar 22, 2016 12:39 pm, edited 1 time in total.

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 Mar 22, 2016 12:37 pm

Your new powerup replaces the regular mushroom powerup (PLAYER_BIG). So as far as the game is concerned, yes. This is a normal mushroom. It just does some different stuff.

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Tue Mar 22, 2016 12:42 pm

Enjl wrote:Your new powerup replaces the regular mushroom powerup (PLAYER_BIG). So as far as the game is concerned, yes. This is a normal mushroom. It just does some different stuff.
Look at that, It makes me start small, but saves NIL as savedpowerup value (I was starting with hammer suit)

Code: Select all

local springlotus = 0
timerApi = loadAPI("leveltimer");

function onLoop()
	Text.print(savedpowerup,0,0) 
	for k,v in pairs(NPC.get(276, -1)) do
		v.id = 26
   end
   if player.powerup == PLAYER_BIG then
		Text.print ("Spring Lotuses left:",210,0)
		Text.print (springlotus,610,0)
   end
   if player:mem(0x122,FIELD_WORD)==1 then
		springlotus=3
   end
   if player.powerup == PLAYER_BIG and springlotus > 1 then
		player.reservePowerup = 275
	end
	if player.powerup == PLAYER_BIG and player.reservePowerup == 0 then
		springlotus = 0
		player:harm()
	end
	if player.powerup ~= PLAYER_BIG and player.reservePowerup == 275 then
		player.reservePowerup = 0
	end
end

function onStart()
	local savedpowerup=player.powerup
	player.powerup=PLAYER_SMALL
end

function onKeyDown(keycode)
	 if (keycode == KEY_SEL) then
		if player.powerup == PLAYER_BIG and springlotus > 1 then
			springlotus = springlotus - 1
		end
	end
end

function onLoad()  
	timerApi.setSecondsLeft(300);
	timerApi.setTimerState(true);
end
Last edited by Mario_and_Luigi_55 on Tue Mar 22, 2016 12:44 pm, edited 2 times in total.

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 Mar 22, 2016 12:44 pm

Your savedpowerup is local, it only exists in onStart.

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Tue Mar 22, 2016 12:47 pm

Enjl wrote:Your savedpowerup is local, it only exists in onStart.

OK. I managed it to save, but i there a way to make lotus spawn in your hands after pressing some kind of button instead of using powerup box?

Actual code is:

Code: Select all

local springlotus = 0
timerApi = loadAPI("leveltimer");
local savedpowerup
local characterback
local powerupbox

function onLoop()
	Text.print(savedpowerup,0,0) 
	Text.print(Level.winState(),20,0)
	for k,v in pairs(NPC.get(276, -1)) do
		v.id = 26
   end
   if player.powerup == PLAYER_BIG then
		Text.print ("Spring Lotuses left:",210,0)
		Text.print (springlotus,610,0)
   end
   if player:mem(0x122,FIELD_WORD)==1 then
		springlotus=3
   end
   if player.powerup == PLAYER_BIG and springlotus > 1 then
		player.reservePowerup = 275
	end
	if player.powerup == PLAYER_BIG and player.reservePowerup == 0 then
		springlotus = 0
		player:harm()
	end
	if player.powerup ~= PLAYER_BIG and player.reservePowerup == 275 then
		player.reservePowerup = 0
	end
	if Level.winState() ~= 0 then
		player.character = characterback
		player.powerup = savedpowerup
		if player.character == CHARACTER_LUIGI or player.character == CHARACTER_MARIO then
			player.reservePowerup = powerupbox
		end
	end
end

function onStart()
	Text.showMessageBox("You will get your powerup after end of the level!")
	savedpowerup=player.powerup
	player.powerup=PLAYER_SMALL
	if player.character==CHARACTER_MARIO or player.character==CHARACTER_LUIGI then
		powerupbox=player.reservePowerup
	end
	characterback=player.character
	player.character=CHARACTER_LUIGI
end

function onKeyDown(keycode)
	 if (keycode == KEY_SEL) then
		if player.powerup == PLAYER_BIG and springlotus > 1 then
			springlotus = springlotus - 1
		end
	end
end

function onLoad()  
	timerApi.setSecondsLeft(300);
	timerApi.setTimerState(true);
end


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 » Tue Mar 22, 2016 9:12 pm

Mario_and_Luigi_55 wrote:
Enjl wrote:Your savedpowerup is local, it only exists in onStart.

OK. I managed it to save, but i there a way to make lotus spawn in your hands after pressing some kind of button instead of using powerup box?

Actual code is:

Code: Select all

local springlotus = 0
timerApi = loadAPI("leveltimer");
local savedpowerup
local characterback
local powerupbox

function onLoop()
	Text.print(savedpowerup,0,0) 
	Text.print(Level.winState(),20,0)
	for k,v in pairs(NPC.get(276, -1)) do
		v.id = 26
   end
   if player.powerup == PLAYER_BIG then
		Text.print ("Spring Lotuses left:",210,0)
		Text.print (springlotus,610,0)
   end
   if player:mem(0x122,FIELD_WORD)==1 then
		springlotus=3
   end
   if player.powerup == PLAYER_BIG and springlotus > 1 then
		player.reservePowerup = 275
	end
	if player.powerup == PLAYER_BIG and player.reservePowerup == 0 then
		springlotus = 0
		player:harm()
	end
	if player.powerup ~= PLAYER_BIG and player.reservePowerup == 275 then
		player.reservePowerup = 0
	end
	if Level.winState() ~= 0 then
		player.character = characterback
		player.powerup = savedpowerup
		if player.character == CHARACTER_LUIGI or player.character == CHARACTER_MARIO then
			player.reservePowerup = powerupbox
		end
	end
end

function onStart()
	Text.showMessageBox("You will get your powerup after end of the level!")
	savedpowerup=player.powerup
	player.powerup=PLAYER_SMALL
	if player.character==CHARACTER_MARIO or player.character==CHARACTER_LUIGI then
		powerupbox=player.reservePowerup
	end
	characterback=player.character
	player.character=CHARACTER_LUIGI
end

function onKeyDown(keycode)
	 if (keycode == KEY_SEL) then
		if player.powerup == PLAYER_BIG and springlotus > 1 then
			springlotus = springlotus - 1
		end
	end
end

function onLoad()  
	timerApi.setSecondsLeft(300);
	timerApi.setTimerState(true);
end

Why are you using onStart and onLoad? You should put everything from onLoad into onStart and just get rid of onLoad, and use onTick instead of onLoop.

Mario_and_Luigi_55
Spike
Spike
Posts: 270
Joined: Sat Feb 27, 2016 12:01 pm

Re: Need help with lua? - LunaLua General Help

Postby Mario_and_Luigi_55 » Wed Mar 23, 2016 3:38 am

Is there a way to make Mario able to grab all npc's without using cheat buffer function?

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 » Wed Mar 23, 2016 6:52 am

Mario_and_Luigi_55 wrote:Is there a way to make Mario able to grab all npc's without using cheat buffer function?
http://wohlsoft.ru/pgewiki/SMBX_Fields
Use the cheat through defines and then change the value of Defines.player_hasCheated

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 » Wed Mar 23, 2016 10:00 pm

How do I change the sprites for the player when the shadowstar cheat is active? (I want them to be normal; not black)

Ness-Wednesday
Purple Yoshi Egg
Purple Yoshi Egg
Posts: 1661
Joined: Sun Jun 28, 2015 3:50 pm
Flair: Diverse Scouts
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Ness-Wednesday » Wed Mar 23, 2016 11:03 pm

I want Wart to shoot a dozen of npcs, but when I tried this:
Spoiler: show

Code: Select all

function onLoop()
	for k,v in pairs(NPC.get(15,player.section)) do
		npca = ownRNG.randomInt(0, 1000)
		if(npca < 100) then
			tableofdath[m]:mem(0xE2, FIELD_WORD, 30)
			tableofdath[m].height = 32
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 210)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 202)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 134)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 282)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 87)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 27)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 7)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 153)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 246)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 259)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 12)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 17)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 40)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 45)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 48)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 85)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 133)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 137)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 166)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 179)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 206)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 230)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 269)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 276)
			tableofdath[m].height = 32
			
		else
			tableofdath[m]:mem(0xE2, FIELD_WORD, 286)
			tableofdath[m].height = 32
		end
	end
end
I got an error stating that end expected (to close to if at line 7) near else.
I tried to put ends, but it doesn't work.
Any ideas?


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 5 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari