Forum

> > CS2D > Scripts > FreeImage
Forums overviewCS2D overview Scripts overviewLog in to reply

English FreeImage

12 replies
To the start Previous 1 Next To the start

old FreeImage

kalis
User Off Offline

Quote
i got error !
local y = 200 first

1
2
3
x = 100
y = y + y
id = image('gfx/kalis/tank.bmp', x, y, 2)
i have 10 images name "id"
how to freeimage() with all image name "id"?
i use freeimage(id) but only last image has been removed !

old Re: FreeImage

Apache uwu
User Off Offline

Quote
Bad idea to use 1 variable for all the images.

Use an array instead.

1
2
3
4
5
6
7
local y=200
local x=100
my_img={}
	for i=1,10 do
		my_img[i] = image('gfx/kalis/tank.bmp', x, y, 2)
		y=y+y
	end

To free all of them simply use this.

1
2
3
for i=1,10 do
	freeimage(my_img[i])
end

old Re: FreeImage

kalis
User Off Offline

Quote
thank
i use array for iamge !
img = Array(32,0) ...

Problem
last image removed !
but some orther image still haave !

i want o use like :
img1 array
image2 array
ect..
but some peoples say

code like baby 5 years old !

old Re: FreeImage

kalis
User Off Offline

Quote
i want to use 10 image with orther array
ex :
img1[id]
img2[oid]
img3[id]
img4[id]
ect..

but some player said ,your code like Children !

old Re: FreeImage

Apache uwu
User Off Offline

Quote
user kalis has written
i want to use 10 image with orther array
ex :
img1[id]
img2[oid]
img3[id]
img4[id]
ect..

but some player said ,your code like Children !


You don't have an array from every image, you have an array containing all the images.

1
2
3
4
5
6
7
my_img[1]
my_img[2]
my_img[3]
...
my_img[8]
my_img[9]
img_img[10]

old Re: FreeImage

archmage
User Off Offline

Quote
Perhaps this will help:
1
2
3
4
5
6
7
8
9
10
11
12
imgMngr = {}
imgMngr.dat = {}
imgMngr.add = function (imgID)
				imgMngr.dat[#imgMngr.dat] = imgID
			end

imgMngr.removeAll = function()
					for i = 1, #imgMngr.dat do
						freeimage(imgMngr.dat[i])
					end
					imgMngr.dat = {}
				end

To add an image use:
1
2
3
imgMngr.add(image(...))
 -- and to free all
imgMngr.removeAll()

old Re: FreeImage

Apache uwu
User Off Offline

Quote
Potentially you could just write it without assign:

1
2
3
4
my_img={}
function add_img(path,x,y,mode)
	table.insert(my_img,image(path,x,y,mode))
end

And to remove all:

1
2
3
4
5
function free_all()
	for _,key in ipairs(my_img) do
		freeimage(key)
	end
end

And if you wanted to add 10 images:

1
2
3
4
5
6
local y=200
local x=100
	for i=1,10 do
		add_img('gfx/kalis/tank.bmp', x, y, 2)
		y=y+y
	end

And freeing all of them:

1
free_all()

That's really only saving the removal part. And having a variable number of images opposed to only having 10.

old Re: FreeImage

kalis
User Off Offline

Quote
thank 2 you much !
i going tot test

got a error with lua of @text
line 83 here :
1
table.insert(my_img,image(path,x,y,mode))
error with "image" !

old Re: FreeImage

Infinite Rain
Reviewer Off Offline

Quote
1
2
3
4
5
6
7
8
9
id = {}
id[1] = image()
id[2] = image()

function randomhook()
	for n, w in ipairs(id) do
		freeimage(w)
	end
end

old Re: FreeImage

kalis
User Off Offline

Quote
ok thank you first !
my code work ?
1
2
3
4
5
6
7
local ct_img = {}

    		for i=1,10 do

			ct_img[i] = image("gfx/z_kalis/100_score.bmp", x_img[id], y_img[id], 2)

		end
want use free image
i can use
randomhook() ?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview