How to switch ipairs without having to rewrite?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
MELO
Prole
Posts: 2
Joined: Thu May 23, 2019 6:09 am

How to switch ipairs without having to rewrite?

Post 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?
User avatar
4vZEROv
Party member
Posts: 126
Joined: Wed Jan 02, 2019 8:44 pm

Re: How to switch ipairs without having to rewrite?

Post 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)
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: How to switch ipairs without having to rewrite?

Post by raidho36 »

Try checking out programming books too, these write volumes about all the ways you can accomplish things in programming.
MELO
Prole
Posts: 2
Joined: Thu May 23, 2019 6:09 am

Re: How to switch ipairs without having to rewrite?

Post 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!
Post Reply

Who is online

Users browsing this forum: K2-XT and 200 guests