Page 25 of 76

Re: Need help with lua? - LunaLua General Help

Posted: Sat May 28, 2016 4:15 pm
by Emral
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 2:12 pm
by Nightmare7
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 2:27 pm
by PixelPest
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)

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 2:29 pm
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 2:50 pm
by Nightmare7
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...

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 3:10 pm
by PixelPest
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?

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 3:11 pm
by S1eth
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



Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 3:12 pm
by TDK
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.

Re: Need help with lua? - LunaLua General Help

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

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 3:59 pm
by underFlo
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 4:08 pm
by Nightmare7
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" ?

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 4:16 pm
by TDK
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 .

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 4:22 pm
by Nightmare7
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 !!!

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 5:05 pm
by Fennor
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.

Re: Need help with lua? - LunaLua General Help

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

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 5:13 pm
by Fennor
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.

Re: Need help with lua? - LunaLua General Help

Posted: Sun May 29, 2016 6:34 pm
by Quantumenace
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.

Re: Need help with lua? - LunaLua General Help

Posted: Mon May 30, 2016 4:12 am
by Hoeloe
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.

Re: Need help with lua? - LunaLua General Help

Posted: Mon May 30, 2016 6:13 pm
by Quantumenace
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.

Re: Need help with lua? - LunaLua General Help

Posted: Tue May 31, 2016 2:57 am
by Hoeloe
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.