Forum

> > CS2D > Scripts > lua: how many ends
Forums overviewCS2D overview Scripts overviewLog in to reply

English lua: how many ends

11 replies
To the start Previous 1 Next To the start

moved lua: how many ends

Homam
User Off Offline

Quote
Hey, i just want little help that is really important for me.
I'd like to ask one question about lua:

How do you know how many ends you put in your lua ?

Please help,
Thanks.

Admin/mod comment

lua questions should go to the scripting forum... moved

old Re: lua: how many ends

DannyDeth
User Off Offline

Quote
You count them
But it is best to tab everything to you can see if you have too many ends or if you have an if/function/for statement that has no end.

old Re: lua: how many ends

Yasday
User Off Offline

Quote
Hmm.. I do it like that:
1
2
3
function lol() --first I write this

end -- then I write the end and just after that I move to the next code-block, in this case: UP

old Re: lua: how many ends

DC
Admin Off Offline

Quote
each if, each function and each loop-type (for/while/repeat) needs exactly one end to be ended.

if you know other programming languages like c(++), java(script), php, etc.: it's like the bracket stuff { }. Lua doesn't have these brackets and therefore it needs "end".
if/function/for/while/repeat is the opening bracket, end is the closing bracket.

old Re: lua: how many ends

DannyDeth
User Off Offline

Quote

How can you not use For and While loops ( repeat isn't that commonly used, I get that. )? They are another very neccisary piece of code one should use.

old Re: lua: how many ends

Jezis
User Off Offline

Quote
DC has written
each if, each function and each loop-type (for/while/repeat) needs exactly one end to be ended.

if you know other programming languages like c(++), java(script), php, etc.: it's like the bracket stuff { }. Lua doesn't have these brackets and therefore it needs "end".
if/function/for/while/repeat is the opening bracket, end is the closing bracket.


and what about programing language from Pascal?

old Re: lua: how many ends

Arne
User Off Offline

Quote
If you get Notepad++ you can see if you are lacking any ends or if you need more!

old Re: lua: how many ends

SQ
Moderator Off Offline

Quote
Steam Friends ADMIN has written
and what about programing language from Pascal?

It is slightly different.
In Pascal, each Begin requires End

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function NewDay() : Integer;
	var i : Integer;
		TempApples : InitArray;
	begin
		TempApples := Apples;
		for i := 1 to ApplesCount do
			begin
				if IsInArray(i) and TempApples[i] then
					begin
						Apples[i + 1] := true;
						Apples[i - 1] := true;
					end;
			end;
	end;
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview