Forum

> > CS2D > Scripts > LUA question - Function
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch LUA question - Function

8 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt LUA question - Function

Infinite Rain
Reviewer Off Offline

Zitieren
I make function but it dosent works
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook('use','epress')
function pre(id,t)
	function epress(p)
		local dot=object(0,'table')
		for b=1,#dot do
			return ((player(p,'tilex')==object(dot[b],'tilex')-1 and player(p,'tiley')==object(dot[b],'tiley')-1) or
			(player(p,'tilex')==object(dot[b],'tilex')-1 and player(p,'tiley')==object(dot[b],'tiley')) or
			(player(p,'tilex')==object(dot[b],'tilex')-1 and player(p,'tiley')==object(dot[b],'tiley')+1) or
			(player(p,'tilex')==object(dot[b],'tilex') and player(p,'tiley')==object(dot[b],'tiley')+1) or
			(player(p,'tilex')==object(dot[b],'tilex')+1 and player(p,'tiley')==object(dot[b],'tiley')+1) or
			(player(p,'tilex')==object(dot[b],'tilex')+1 and player(p,'tiley')==object(dot[b],'tiley')) or
			(player(p,'tilex')==object(dot[b],'tilex')+1 and player(p,'tiley')==object(dot[b],'tiley')-1) or
			(player(p,'tilex')==object(dot[b],'tilex') and player(p,'tiley')==object(dot[b],'tiley')-1)) and object(dot[b],'type')==t and p==id
		end
	end
end

after that I make this

1
2
3
4
5
6
addhook('always','chk')
function chk()
	if pre(1,7) then
		msg(':DDD')
	end
end
Its not works please help
1× editiert, zuletzt 13.04.11 16:48:08

alt Re: LUA question - Function

DannyDeth
User Off Offline

Zitieren
You are completely mad, aren't you?
First and foremost, pre is defining epress, so when the player presses E, epress is nil unless pre has been called.

Then you want to know if calling pre(1,7) returns something. pre does not return aything because it has no return command in it.

Learn Lua ( not LUA! It's a word from portuguese not an ancronym! ) before trying ( yet obviously failing ) to code in it.

alt Re: LUA question - Function

BrahOrkah
BANNED Off Offline

Zitieren
Don't be so mad DannyDeth.

you shouldn't wrap the function epress inside the function pre.
Could you tell me what you're trying to achieve ( in words) with this code? I don't really see it because the code is such a mess.

alt Re: LUA question - Function

DannyDeth
User Off Offline

Zitieren
I'm not mad, I'm tired of stupidity. I have had more than enough of it today.

I mean, how can you not see something that obvious?

alt Re: LUA question - Function

DannyDeth
User Off Offline

Zitieren
.........?
.......?
....?
..?

What? pre is being added to the hook 'always' ( stupid idea ), so there.

Just think. I know it might be difficult for you, but try as hard as you can.

alt Re: LUA question - Function

KimKat
GAME BANNED Off Offline

Zitieren
Basicly, either change epress or pre to be equal with eachother, that will fix the small issue. I also think you cannot put a function inside a function. But possibly you can attach more hooks to a function. To fix the other prob, create a seperate function. That's all I can help with for now.

What I ment with be equal to eachother is explained below.
1
2
3
4
5
6
7
8
9
10
addhook("use","epress")
function epress(id,button ...?) -- the parameters you should put them between the paranthesis/brackets, I currently don't know the use hook's parameters atm.
	if button==true then
		pre()
	end
end

function pre()
	-- the seperate function.
end
I know the code will return a error, but still it's something to work on, in other words just a example.

alt Re: LUA question - Function

archmage
User Off Offline

Zitieren
@KimKat
It is possible to define a function inside another function. I just do not know why you would want to do so. Maybe for something like:
Mehr >


@factis699
Your function pre does nothing more than define another function, epress. Also it does not return any values so it will always return nil (or false).

You do not need pre. It is completely useless!

Define epress like this
1
2
3
function epress(id, event, data, x, y)
	-- Code here
end

Now call addhook.
1
addhook("use", "epress");

alt Re: LUA question - Function

Banaan
User Off Offline

Zitieren
Dark Byte hat geschrieben
@KimKat
It is possible to define a function inside another function. I just do not know why you would want to do so.


local functions might be handy from time to time, and should (in some cases) be declared within another function. Can't think of any other reasons though.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht