Forum

> > CS2D > Scripts > I need to figure out some stuff
Forums overviewCS2D overview Scripts overviewLog in to reply

English I need to figure out some stuff

2 replies
To the start Previous 1 Next To the start

old I need to figure out some stuff

Zeik
User Off Offline

Quote
Well I came back to CS2D with the intention to learn some coding. I used to do some codes when I played but I was just trying stuff and not actually understanding it.
Now I have at least basic knowledge of programming with C, and was figuring out how the sample codes worked.

So I need to know what these things are for:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--------------------------------------
-- BADWORDS TABLE (LOWERCASE)       --
--------------------------------------
sample.badwords.words = {"lol","no","bad","words","for","you"}


--------------------------------------
-- HANDLE BADWORDS IN SAY MESSAGES  --
--------------------------------------
addhook("say","sample.badwords.say")
function sample.badwords.say(p,t)
	t=string.lower(t)
	for i = 1,#sample.badwords.words do
		if (string.find(t,sample.badwords.words[i])~=nil) then
			msg(player(p,"name").." said a bad word!")
			parse("kick "..p)
			break
		end
	end
end

I wonder what does the "#" behind the variable "sample.badwords.words".
Also, the for starts with i=1 but it doesn't keep adding (1..2..etc) anywhere. I mean, the "i" indicates the position in the array "sample.badwords.words" or I am wrong?

It would be cool if you can explain me this two things. Thanks.


If you don't understand something, tell me and I'll answer you... English is not my main lenguage so maybe I wrote something confusing

old Re: I need to figure out some stuff

Apache uwu
User Off Offline

Quote
I highly recommend reading the documentation.

In it, you can see the syntax for the for loop.

for variable = from_exp , to_exp [, step_exp] do block end


The step_exp, which is what the loop goes up by, is defaulted to one.

The length operator is denoted by the token #, as written here.

Putting it all together, we can see that the for loop goes from 1 (tables begin at one), to the length of the table declared above.

old Re: I need to figure out some stuff

Zeik
User Off Offline

Quote
Oh thanks man!! It makes a lot of sense now lol
Also, thank you for responding so fast.

I will read the manual next time I don't understand something

Admin/mod comment

Removed quote. /user useigor
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview