Scripts / What does the ; mean in lua? ( semicolon )

Author
Message
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 10th Aug 2015 15:06
I Hope this isn't a silly Question. But what is the function of the semicolon in lua scripting?

I have been meaning to ask this for a while.

I noticed it is used a lot in the ai scripts.
i:e:
AISetEntityControl(EntObjNo,AI_MANUAL);
EntObjNo = g_Entity[e]['obj'];
PathIndex = -1;
pClosest = 99999;
tDistX = g_Entity[e]['x'] - ai_start_x[e];
tDistZ = g_Entity[e]['z'] - ai_start_z[e];
ai_soldier_state[e] = "combat";

I have searched the lua Reference Manual & lua tutorials , but all I can find out about it is, that it is a token..


Cheers...

I may be old, but at least my memory still ....hmmm

DT:Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528, AutoCAD, 3DsMax, Paint.Net, Solidworks.
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 10th Aug 2015 18:01
If I am correct it is used if you use more statements in a line, like:
Hide(e) ; Prompt(e)
b=a+c ; d=b+c

I did not know why there are everythere in the standart scripts even when they make no sense at all. If you write each statement in a seperate line, there is no need to use them

another small tipp if you learn lua:
Learn the basics with one tutorial on the internet, they are there in any language.
Then look at the commands, so you have a good overview and know what to do

Never use the standart scripts as a references. They are bad and unoptimized, have a lot of useless code.
Look in the forum from other scripters like smallg. They are good and most of the time commented
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
Avram
GameGuru TGC Backer
18
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 10th Aug 2015 19:54
Corno_1 wrote: "I did not know why there are everythere in the standart scripts even when they make no sense at all. If you write each statement in a seperate line, there is no need to use them"


It's just because 99% other programming languages require them after each command, even if you have only one command per line. Some examples are C, C++, C#, Java, Pascal, PHP, JavaScript and so on... so those of us who work(ed) with other languages are simply "trained" to automatically place them at the end of every line. But as you said, they are not required if you have only one command per line
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 11th Aug 2015 11:57
Thanks for the responses

Corno_1; Avram

Cheers


I may be old, but at least my memory still ....hmmm

DT:Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528, AutoCAD, 3DsMax, Paint.Net, Solidworks.
Ratall
16
Years of Service
User Offline
Joined: 29th Jun 2008
Location: Not Here
Posted: 23rd Aug 2015 09:54 Edited at: 23rd Aug 2015 10:03
I would be careful about ";" as it is possible in LUA (but not advisable) to spread some commands over multiple lines the " ;" at the end of a line removes any possible ambiguity that may arise.


Lua 5.2 Reference Manual by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, Waldemar Celes wrote: " 3.3.1 – Blocks

A block is a list of statements, which are executed sequentially:

block ::= {stat}

Lua has empty statements that allow you to separate statements with semicolons, start a block with a semicolon or write two semicolons in sequence:

stat ::= ‘;’

Function calls and assignments can start with an open parenthesis. This possibility leads to an ambiguity in Lua's grammar. Consider the following fragment:

a = b + c
(print or io.write)('done')

The grammar could see it in two ways:

a = b + c(print or io.write)('done')

a = b + c; (print or io.write)('done')

The current parser always sees such constructions in the first way, interpreting the open parenthesis as the start of the arguments to a call. To avoid this ambiguity, it is a good practice to always precede with a semicolon statements that start with a parenthesis:

;(print or io.write)('done')

"

personally I think placing the ";" at the end of each line is simpler to remember.
CPU:i7-4720HQ Mem: 16G
Graphic: GTX 980M 8G and intel HD4600
OS: Windows10
PM

Login to post a reply

Server time is: 2024-12-22 05:14:10
Your offset time is: 2024-12-22 05:14:10