Forum

> > CS2D > Scripts > Removing image after dying
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Removing image after dying

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Removing image after dying

Nori-chan
User Off Offline

Zitieren
Hello guys!

I'm having a problem with a image, here is the code:

Spoiler >


(each reward in my script are divided into pon1, pon2, pon3...).
the 'pon' is your points in that life.

This is what should happen:

Spoiler >


So, what command I must use to remove the image?

alt Re: Removing image after dying

Alistaire
User Off Offline

Zitieren
user Nori-chan hat geschrieben
user Alistaire hat geschrieben
Dude. Don't add images more than once.


Sorry to ask that, but what do you mean with adding more than once?
i'm trying to remove the image when I die.


You're using the move hook. Every time the player moves 1 pixel, that hook is called. This means, that if the player walks 5 tiles, there's 160 images on the player. If you understand that you can only free the last image because the last image-object's id is stored in the image[id] table you made, and it frees that one, you hopefully understand that you can not free a stack of 160 images in any way.

Don't ever call image() without conditions in a move hook anyways, it's as useless as calling image() in an always hook.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function array(v)
	local a = {}
	for i = 1, 32 do
		a[i] = v
	end
	return a;
end

ponImg = array(false)

addhook('die', 'dieHook')

function dieHook(id)
	pon7[id] = 0
	checkImage(id)
end

--use checkImage in any function that adds points
function checkImage(id)
	if pon7[id] >= 2000 then
		if ponImg[id] then
			freeimage(ponImg[id])
		end
		ponImg[id] = true
		ponImg[id] = image('gfx/car_01.png', 1, 0, 200+id)
	else
		freeimage(ponImg[id])
		ponImg[id] = false
	end
end

alt Re: Removing image after dying

Nori-chan
User Off Offline

Zitieren
user Alistaire hat geschrieben
user Nori-chan hat geschrieben
user Alistaire hat geschrieben
Dude. Don't add images more than once.


Sorry to ask that, but what do you mean with adding more than once?
i'm trying to remove the image when I die.


You're using the move hook. Every time the player moves 1 pixel, that hook is called. This means, that if the player walks 5 tiles, there's 160 images on the player. If you understand that you can only free the last image because the last image-object's id is stored in the image[id] table you made, and it frees that one, you hopefully understand that you can not free a stack of 160 images in any way.

Don't ever call image() without conditions in a move hook anyways, it's as useless as calling image() in an always hook.


But, if you see my code, you can see that when I have 2000 points or more, It will add an image and the the pon7 will be pon7 - 10000, so i will have -8000 points and I will not add more images when i'm moving.

EDIT: Nevermind, I used the freeimage and now it's working. Thank you for helping me.
1× editiert, zuletzt 20.04.13 23:36:31
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht