Change Images By Timer

corroder

What is cheating?
Mar 3, 2017
17
0
1
#1
Hi, how do this :

First try : (stupid way)
Code:
f = createForm()
f.Width = 500
f.Height = 500
i1 = createImage(f)
i1.Width = 500
i1.Height = 500
i1.Stretch = true
i1.Picture.loadFromStream(findTableFile('mainWall.jpg').Stream)

t_index = 1
counter = 3
c=createTimer(nil)
c.Interval= 5000
c.OnTimer=function(c)
 if t_index <= counter then
  i1.Picture.loadFromStream(findTableFile('mainWall1.jpg').Stream)
  t_index = t_index + 1
 else
  i1.Picture.loadFromStream(findTableFile('mainWall2.jpg').Stream)
  t_index = 1
 end
end
c.Enabled=true

function closeGLP()
 c.destroy()
 closeCE()
 return caFree
end

f.onClose = closeGLP
f.show()

-- result : Images change as timer provided, but only display 2 images from 3 images want to show

Second way : more than stupid, it's a dumb way
Code:
t = {}
t[1] = 'mainWall.jpg'
t[2] = 'mainWall1.jpg'
t[3] = 'mainWall2.jpg'
t[4] = 'mainWall3.jpg'

f = createForm()
f.Width = 400
f.Height = 400
img = createImage(f)
img.Width = 400
img.Height = 400
img.Stretch = true

timer=createTimer(nil, false)
timer.Interval=3000
timer.OnTimer=function(timer)
for i=1, 4 do
 img.Picture.loadFromStream(findTableFile(t[i]).Stream)
 i=i+1
end
end
timer.Enabled=true

result : only image t[4] shown
How do 2nd way in smart way ?

Thanks
 

Eric

Administrator
Administrator
Mar 2, 2017
39
0
6
#2
Code:
t = {}
t[1] = 'mainWall.jpg'
t[2] = 'mainWall1.jpg'
t[3] = 'mainWall2.jpg'
t[4] = 'mainWall3.jpg'

pics={}
for i=1,4 do
  pics[i]=createPicture()
  pics[i].loadFromStream(findTableFile(t[i]).Stream)
end


f = createForm()
f.Width = 400
f.Height = 400
img = createImage(f)
img.Width = 400
img.Height = 400
img.Stretch = true

pics.currentPicture=1

timer=createTimer(f, false)
timer.Interval=3000
timer.OnTimer=function(timer)
  img.Picture=pics[pics.currentPicture] --same as img.Picture.assign(pics[pics.currentPicture])
  pics.currentPicture=(pics.currentPicture % 4)+1
end
timer.Enabled=true
 

corroder

What is cheating?
Mar 3, 2017
17
0
1
#3
Eric post_id=980 time=1489068032 user_id=59 said:
Code:
t = {}
t[1] = 'mainWall.jpg'
t[2] = 'mainWall1.jpg'
t[3] = 'mainWall2.jpg'
t[4] = 'mainWall3.jpg'

pics={}
for i=1,4 do
  pics[i]=createPicture()
  pics[i].loadFromStream(findTableFile(t[i]).Stream)
end


f = createForm()
f.Width = 400
f.Height = 400
img = createImage(f)
img.Width = 400
img.Height = 400
img.Stretch = true

pics.currentPicture=1

timer=createTimer(f, false)
timer.Interval=3000
timer.OnTimer=function(timer)
  img.Picture=pics[pics.currentPicture] --same as img.Picture.assign(pics[pics.currentPicture])
  pics.currentPicture=(pics.currentPicture % 4)+1
end
timer.Enabled=true
Well done, work proper;y without issue.
Thanks so much Eric..

Regards