Page 1 of 1
for loop
Posted: Wed Nov 06, 2013 8:47 pm
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
Re: for loop
Posted: Wed Nov 06, 2013 8:56 pm
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
Re: for loop
Posted: Thu Nov 14, 2013 3:17 am
by elsalvador
Oh.. I see thank you So much Got It..
Re: for loop+text
Posted: Wed Jan 01, 2014 8:48 pm
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
Re: for loop+text
Posted: Wed Jan 01, 2014 9:00 pm
by Robin
Ye got the order wrong:
Code: Select all
function love.load()
t1 =('first text')
t2 =('second text')
v ={t1,t2}
end
Re: for loop
Posted: Wed Jan 01, 2014 11:42 pm
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 ..
Re: for loop
Posted: Thu Jan 02, 2014 9:55 am
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 ..
Actually, no. What happened with your code is, when you write this:
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,
results in:
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.
Re: for loop
Posted: Thu Jan 02, 2014 10:56 am
by Zeliarden
Re: for loop
Posted: Thu Jan 02, 2014 8:44 pm
by elsalvador
thank you ill read it so i can get it ...