Page 1 of 1

technical questions

Posted: Thu Feb 23, 2017 6:25 am
by vtx
AND

Did it work like all other programming language ?

Code: Select all

if not a AND not b AND not c then hello world! end
Hello world will only be display when all value are not false ?

Function

I need to access player within myfunction did I have to place it in argument ?

Code: Select all

myfunction(player,max)
or

Code: Select all

myfunction(max)
Scope and good programming

The variable that I'll only use within myfunction did I have to prefix it with local or the default behavior is local ?

Re: technical questions

Posted: Thu Feb 23, 2017 12:46 pm
by bobingabout
AND, look up LUA definitions.

Long story short though, when looking at it from the True/False logic perspective... It will check the first entity first. if it fails, it ends. if it doesn't fail, it checks the next condition. There is a lot more to it than that though, because you can compare numbers, or strings, etc.


Functions.

There are actually several different ways to do a function. If you are in a single player game, you don't need to pass the player variable. However, that is bad practice, since the mod may be used in multiplayer. You should instead make use of game.players[]. Now, you could pass the game.players[#] variable directly, but I would recommend sending game.players[#].index... or just the # part as: myfunction(player_index,max). Then in the function, you access the player using game.players[player_index].

I hope that clears a few things up.