for loop

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
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

for loop

Post by elsalvador »

i want to put 5 images in an x NOT y
and i tried the for and it didnt work

is this how to do it?
and where do i put it the load and draw confuse me still i dont know where to put it???
with the print it worked i got 5 replies but with images didnt! can someone give me an example?

for i= 1 ,5 do
love.graphics.draw(' image','100,100)
end

and i also used the x but still didnt? worked
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: for loop

Post by Plu »

Right now you are putting all the images in the same spot. The two numbers after image are the location of the image. So you need to make sure each image is in a different location on the screen by varying the first number you give out (if you want to put them in a horizontal row)

Also, you have to create an image resource, not the word image as a string.

Try something like this:

Code: Select all

image = love.graphics.newImage( 'image.png' ) -- make sure an image.png exists next to your main.lua
for i = 1, 5 do
  love.graphics.draw( image, 50 + 50 * i, 100 )
end
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: for loop

Post by elsalvador »

Oh.. I see thank you So much Got It..
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: for loop+text

Post by elsalvador »

Okay what am i doing wrong???
i am trying to make random text appears
did i used random wrong? or whats???

:( :( :(

Code: Select all

function love.load()	
	v ={t1,t2}
	t1 =('first text')
	t2 =('second text')
end

function love.draw()
	for k,v in pairs(v) do
		g.setColor(255,255,255,255)				
		g.print(k,math.random(v),100,100) 
	end	
end
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: for loop+text

Post by Robin »

Ye got the order wrong:

Code: Select all

function love.load()	
	t1 =('first text')
	t2 =('second text')
	v ={t1,t2}
end
Help us help you: attach a .love.
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: for loop

Post by elsalvador »

the random and graphics.print is right???
all i did was put the text? below instead of above?
cool.. thanks.. hope it works .. :ultrahappy:
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: for loop

Post by Roland_Yonaba »

elsalvador wrote:the random and graphics.print is right???
all i did was put the text? below instead of above?
cool.. thanks.. hope it works .. :ultrahappy:
Actually, no. What happened with your code is, when you write this:

Code: Select all

v ={t1,t2}
You create a table, and you save a reference to this table in a variable named v.
In this very table, you insert some other variables named t1 and t2.
But, since t1 and t2 are not defined yet, they are both nil. So,

Code: Select all

v={t1,t2}
results in:

Code: Select all

v={nil,nil}
Then right after that, you create tables t1 and t2, but they have no relationship with the previous table v.
Hence Robin's comment:
Robin wrote:Ye got the order wrong
.

So you should have defined tables t1 and t2 first, then insert them into table v.
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: for loop

Post by Zeliarden »

the random and graphics.print is right???
no
recommend you to check out
http://www.lua.org/pil/4.3.5.html (for loop)
and
https://www.love2d.org/wiki/love.graphics.print and https://www.love2d.org/wiki/love.math.random
for correct syntax
elsalvador
Citizen
Posts: 54
Joined: Thu Oct 24, 2013 1:29 am

Re: for loop

Post by elsalvador »

thank you ill read it so i can get it ...
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests