Page 1 of 1

How to switch ipairs without having to rewrite?

Posted: Thu May 23, 2019 6:21 am
by MELO
Hello, This is my first post to the Love2d forums and even though I've been using this framework for about 4 years, I ran into an issue im having difficulty solving on my own.

I want to find a way for the ipairs to switch the name to something else.

for example:

Code: Select all

 for i,v in ipairs(opp) do 
		if majormel84:getCurrentFrame() >= 42 and majormel84:getCurrentFrame() <= 44
		and CheckCollision (v.x, v.y, v.w, v.h,majormel.l + 45 , light.y , light.w, light.h)
		and majormel.x < opp.x  and light.active == false and v.blocked==false then 
to

Code: Select all

 for i,v in ipairs(player1) do 
		if majormel84:getCurrentFrame() >= 42 and majormel84:getCurrentFrame() <= 44
		and CheckCollision (v.x, v.y, v.w, v.h,majormel.l + 45 , light.y , light.w, light.h)
		and majormel.x < opp.x  and light.active == false and v.blocked==false then 
I want to find a way to have the value in the parantheses change but I can't figure out how.
is there a way or something similar that can achieve this effect?

Re: How to switch ipairs without having to rewrite?

Posted: Thu May 23, 2019 11:20 am
by 4vZEROv
do a function ?

Code: Select all

function loop(x)
	for i,v in ipairs(x) do 
		--stuff
	end
end
loop(opp)
loop(player)

Re: How to switch ipairs without having to rewrite?

Posted: Thu May 23, 2019 1:59 pm
by raidho36
Try checking out programming books too, these write volumes about all the ways you can accomplish things in programming.

Re: How to switch ipairs without having to rewrite?

Posted: Sat May 25, 2019 6:46 am
by MELO
4vZEROv wrote: Thu May 23, 2019 11:20 am do a function ?

after a couple of hours (im pretty slow) i finally caught on to it! thanks!