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 May 28, 2016 4:15 pm

Creasion wrote:By homing I mean like an npc that literally flies to you like a heat seeking missile and any direction you go to try and avoid it , it will stick to you and not fly off like a parakoopa does.

Do those codes do this?
The code I posted handles precise homing on the horizontal axis. For the vertical axis you only have to replace the x's with y's and the width's with height's. Make sure that when you use a code you also understand it, otherwise you won't be able to adjust it if something's off. And I can't stress enough how much better (albeit more complicated) just making your own object with lua is, because it gives frees you from the restrictions of speedX and speedY and all the oddities around it.

Nightmare7
Shy Guy
Shy Guy
Posts: 7
Joined: Wed Apr 06, 2016 1:08 pm

Re: Need help with lua? - LunaLua General Help

Postby Nightmare7 » Sun May 29, 2016 2:12 pm

I saw this video few days ago https://www.youtube.com/watch?v=uVu_IwuNyxM and I wanted to recreate this for one of my level. I've tried to make a Lunaddl.lua file and copy BlockType = rand(); in the file but everytime I try the level I get "attempt to call global 'rand' (a nil value)" and it does not work. Can someone help me ?

Btw is it possible to apply this but for only one section of a level ? It's okay if not.

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 May 29, 2016 2:27 pm

Nightmare7 wrote:I saw this video few days ago https://www.youtube.com/watch?v=uVu_IwuNyxM and I wanted to recreate this for one of my level. I've tried to make a Lunaddl.lua file and copy BlockType = rand(); in the file but everytime I try the level I get "attempt to call global 'rand' (a nil value)" and it does not work. Can someone help me ?

Btw is it possible to apply this but for only one section of a level ? It's okay if not.
I have no idea what BlockType = rand(); but it won't work by itself. It's probably part of an custom API that you don't have or a hoax. To do this though, you would need to get all of the blocks in the level in a table and then check if player.section == Section(#) (replace # with whatever section number you want here, remember 0 is the first section). Then you would need to manipulate each block's ID (find that here: http://wohlsoft.ru/pgewiki/Block_(class)) to a random number between 1 and 638. You can either use the built in random number generator (math.random(min, max)) or the API (which I would recommend since it is more random), rng.lua (found here: http://wohlsoft.ru/pgewiki/Rng.lua)

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 May 29, 2016 2:29 pm

PixelPest wrote:[
I have no idea what BlockType = rand();
Since that video is from before LunaLua existed, my guess is that the code is actually referring to a C++ patch, and not LunaLua at all.

Nightmare7
Shy Guy
Shy Guy
Posts: 7
Joined: Wed Apr 06, 2016 1:08 pm

Re: Need help with lua? - LunaLua General Help

Postby Nightmare7 » Sun May 29, 2016 2:50 pm

Hoeloe wrote:
PixelPest wrote:[
I have no idea what BlockType = rand();
Since that video is from before LunaLua existed, my guess is that the code is actually referring to a C++ patch, and not LunaLua at all.
Do you think it can't be done with lunalua ?

Thanks PixelPest, first of all I'm a newbie so sorry if don't understand some things. So for the section 9 the code is player.section == Section(10) I guess, but I get the message " '=' expected near '==' ". But after I'm don't understand how I manipulate each block ID...

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 May 29, 2016 3:10 pm

Nightmare7 wrote:
Hoeloe wrote:
PixelPest wrote:[
I have no idea what BlockType = rand();
Since that video is from before LunaLua existed, my guess is that the code is actually referring to a C++ patch, and not LunaLua at all.
Do you think it can't be done with lunalua ?

Thanks PixelPest, first of all I'm a newbie so sorry if don't understand some things. So for the section 9 the code is player.section == Section(10) I guess, but I get the message " '=' expected near '==' ". But after I'm don't understand how I manipulate each block ID...
For section 9 it would be section 8
Do you know anything about Lua?
Last edited by PixelPest on Sun May 29, 2016 3:12 pm, edited 2 times in total.

S1eth
Bot
Bot
Posts: 54
Joined: Sat Apr 23, 2016 10:44 am

Re: Need help with lua? - LunaLua General Help

Postby S1eth » Sun May 29, 2016 3:11 pm

PixelPest wrote:
Nightmare7 wrote:
Hoeloe wrote:
Since that video is from before LunaLua existed, my guess is that the code is actually referring to a C++ patch, and not LunaLua at all.
Do you think it can't be done with lunalua ?

Thanks PixelPest, first of all I'm a newbie so sorry if don't understand some things. So for the section 9 the code is player.section == Section(10) I guess, but I get the message " '=' expected near '==' ". But after I'm don't understand how I manipulate each block ID...
For section 9 it would be:

Code: Select all

if player.section == Section(8) then
Do you know anything about Lua?
player.section is an integer field, so it would be

Code: Select all

if player.section == 8 then

Code: Select all

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

function onTick() -- every tick
  for _,v in pairs(Block.get()) do -- for every block
    v.id = rng.randomInt(1,638); -- change the id of the block
  end
end


Last edited by S1eth on Sun May 29, 2016 3:18 pm, edited 5 times in total.

TDK
Phanto
Phanto
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Need help with lua? - LunaLua General Help

Postby TDK » Sun May 29, 2016 3:12 pm

Nightmare7 wrote:
Do you think it can't be done with lunalua ?

Thanks PixelPest, first of all I'm a newbie so sorry if don't understand some things. So for the section 9 the code is player.section == Section(10) I guess, but I get the message " '=' expected near '==' ". But after I'm don't understand how I manipulate each block ID...
It can be done with LunaLua.
For example:

Code: Select all

local rng = API.load("rng")
function onTick()
	if player.section == 8 then
		all_block = Block.get()
		for _,v in pairs(all_block) do
			v.id = rng.randomInt(1,638)
		end
	end
end
When you're using double equals ('=='), you should have an 'if' before it (e.g. if player.section == 8).
Also to manipulate each block ID use the Block.get() function to get a table of all the blocks, and the 'for' loop.

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 May 29, 2016 3:13 pm

S1eth wrote:player.section is an interger field, so it would be

Code: Select all

if player.section == 8 then
Oh right. Forgot about that.
TheDinoKing432 wrote:
I was trying not to do it all for them

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 May 29, 2016 3:59 pm

pretty sure that you have to limit the blocks to the section coordinates since the blocks from other sections are affected as long as Mario is Section 9.

Nightmare7
Shy Guy
Shy Guy
Posts: 7
Joined: Wed Apr 06, 2016 1:08 pm

Re: Need help with lua? - LunaLua General Help

Postby Nightmare7 » Sun May 29, 2016 4:08 pm

Ok thanks, I've tried this code but when I load the level I get the message "attempt to index global 'API' (a nil value)"

Code: Select all

local rng = API.load("rng")
function onTick()
   if player.section == 8 then
      all_block = Block.get()
      for _,v in pairs(all_block) do
         v.id = rng.randomInt(1,638)
      end
   end
end
Should I replace something over "rng" ?

TDK
Phanto
Phanto
Posts: 1440
Joined: Wed Nov 11, 2015 12:26 pm
Flair: Retired

Re: Need help with lua? - LunaLua General Help

Postby TDK » Sun May 29, 2016 4:16 pm

Nightmare7 wrote:Ok thanks, I've tried this code but when I load the level I get the message "attempt to index global 'API' (a nil value)"

Code: Select all

local rng = API.load("rng")
function onTick()
   if player.section == 8 then
      all_block = Block.get()
      for _,v in pairs(all_block) do
         v.id = rng.randomInt(1,638)
      end
   end
end
Should I replace something over "rng" ?
That probably means that you have an outdated version of LunaLua. You should have version 0.7.3 or higher (downlaod here).
Alternatively you can use loadAPI instead of API.load .

Nightmare7
Shy Guy
Shy Guy
Posts: 7
Joined: Wed Apr 06, 2016 1:08 pm

Re: Need help with lua? - LunaLua General Help

Postby Nightmare7 » Sun May 29, 2016 4:22 pm

TheDinoKing432 wrote:
Nightmare7 wrote:Ok thanks, I've tried this code but when I load the level I get the message "attempt to index global 'API' (a nil value)"

Code: Select all

local rng = API.load("rng")
function onTick()
   if player.section == 8 then
      all_block = Block.get()
      for _,v in pairs(all_block) do
         v.id = rng.randomInt(1,638)
      end
   end
end
Should I replace something over "rng" ?
That probably means that you have an outdated version of LunaLua. You should have version 0.7.3 or higher (downlaod here).
Alternatively you can use loadAPI instead of API.load .

Yes it works finally ! Thanks to you all for helping me !!!

Fennor
Buster Beetle
Buster Beetle
Posts: 94
Joined: Sat Apr 25, 2015 12:08 pm

Re: Need help with lua? - LunaLua General Help

Postby Fennor » Sun May 29, 2016 5:05 pm

Another thing about the shell speed someone asked for:

What do you think about this?
Spoiler: show

Code: Select all

function onLoop() 
	for k,v in pairs(NPC.get(5, player.section)) do
		if v.speedX > 0 then
			v.x = v.x - 1.5
		else
			if v.speedX < 0 then
				v.x = v.x + 1.5
			end	
		end			
	end	
end	
So instead of artificially setting the x pos every frame, it lets the shell go with normal speed but at the same time moves it constantly to the left when going right. This way it can still collide. The only problem I can think of so far is that it will mess up the jumping on sloaps. You could simply not allow the shell to get below a certain speed, but this would also mess with throwing the shell up. You could check for the y speed only when x speed is 0, but that would still cause problems when throwing it up diagonally.

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 May 29, 2016 5:08 pm

Nightmare7 wrote:
Do you think it can't be done with lunalua ?
I'd also suggest reading the Lunalua tutorials on the wiki. They might help you understand some of the fundamentals.

http://wohlsoft.ru/pgewiki/How_To:_LunaLua_basics

Fennor
Buster Beetle
Buster Beetle
Posts: 94
Joined: Sat Apr 25, 2015 12:08 pm

Re: Need help with lua? - LunaLua General Help

Postby Fennor » Sun May 29, 2016 5:13 pm

Fennor wrote:Another thing about the shell speed someone asked for:

What do you think about this?
Spoiler: show

Code: Select all

function onLoop() 
	for k,v in pairs(NPC.get(5, player.section)) do
		if v.speedX > 0 then
			v.x = v.x - 1.5
		else
			if v.speedX < 0 then
				v.x = v.x + 1.5
			end	
		end			
	end	
end	
So instead of artificially setting the x pos every frame, it lets the shell go with normal speed but at the same time moves it constantly to the left when going right. This way it can still collide. The only problem I can think of so far is that it will mess up the jumping on sloaps. You could simply not allow the shell to get below a certain speed, but this would also mess with throwing the shell up. You could check for the y speed only when x speed is 0, but that would still cause problems when throwing it up diagonally.
Oh I am sorry, that's what has been allready said in a cleaner way. Missed that.

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 May 29, 2016 6:34 pm

Is there a way to use Lua to draw an image with an additive filter?

Image

The red box on the left is a block-225 with an all-red GIF image and white mask, resulting in an additive blend.

The second box is an attempt to use Graphics.drawImageToSceneWP with the GIF. It ignores the mask and is not transparent at all. The third and fourth are PNGs, with no transparency and half transparency respectively.

What I want is to be able to draw things with Lua like the first box, which would be useful for light effects and such.

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 » Mon May 30, 2016 4:12 am

Quantumenace wrote:Is there a way to use Lua to draw an image with an additive filter?
There is a trick you can use, but it's complicated. When you draw something with glDraw, you can supply vertex colours for the pygon you're drawing. These colours require premultiplied alpha values to work like pngs, but if you supply non premultiplied values (a colour value with alpha 0), you get an additive blend. The particles API uses this trick.

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 » Mon May 30, 2016 6:13 pm

Thanks! I saw that blend option in particles but I couldn't tell how it was supposed to work just from the script. The default particle textures don't work correctly with it because the actual color is all white.

Also, the "split" function in particles.lua writes to the global variable "i" instead of a local one. Is that intended? I had inconsistent bugs with other things because I accidentally was reading from that, and if it was nil the problem would have been obvious right away.

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 May 31, 2016 2:57 am

Quantumenace wrote:Thanks! I saw that blend option in particles but I couldn't tell how it was supposed to work just from the script. The default particle textures don't work correctly with it because the actual color is all white.
They do work correctly. The reason they're white is because that allows the emitter colour values to set the colour of the particle correctly. It is important to note that, when using additive particles, you should keep the alpha channel of your colourings at 0, because otherwise you will get an alpha blend.
Quantumenace wrote:Also, the "split" function in particles.lua writes to the global variable "i" instead of a local one. Is that intended? I had inconsistent bugs with other things because I accidentally was reading from that, and if it was nil the problem would have been obvious right away.
Hmm, that looks like an oversight on my part.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari