Forum

> > CS2D > Scripts > LUA question - Function
Forums overviewCS2D overview Scripts overviewLog in to reply

English LUA question - Function

8 replies
To the start Previous 1 Next To the start

old LUA question - Function

Infinite Rain
Reviewer Off Offline

Quote
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
edited 1×, last 13.04.11 04:48:08 pm

old Re: LUA question - Function

DannyDeth
User Off Offline

Quote
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.

old Re: LUA question - Function

BrahOrkah
BANNED Off Offline

Quote
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.

old Re: LUA question - Function

DannyDeth
User Off Offline

Quote
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?

old Re: LUA question - Function

DannyDeth
User Off Offline

Quote
.........?
.......?
....?
..?

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.

old Re: LUA question - Function

KimKat
GAME BANNED Off Offline

Quote
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.

old Re: LUA question - Function

archmage
User Off Offline

Quote
@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:
More >


@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");

old Re: LUA question - Function

Banaan
User Off Offline

Quote
Dark Byte has written
@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.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview