Currently Online

Latest Posts

Topic: Give goods periodically in script

SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2015-02-19, 17:28

I have read the tutorial linked there when I was creating the tutorials. What is still unclear to me: How do I know/find out whether I have to use p.func(a) and when p:func(a) other than by trial-and-error or looking at examples in the code? That is, is there a way to document that in the .cc files from which the documentation is created? These docs are the place where I expect(ed) such things.

You need to use : if you call a method, i.e. a function defined in a class (most), you need to use . if you call a function. For example

g = wl.Game()  -- creates a game class. This calls a method in the module 'wl'.
p = game.players[1] -- gets the first entry of the players property of this class which is an array of Player classes. There is no function call here.
p:get_buildings("blub") -- same as p.get_buildings(p, "blub"), calls a method on the class P.

Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2015-02-19, 17:29

SirVer wrote:

I have read the tutorial linked there when I was creating the tutorials. What is still unclear to me: How do I know/find out whether I have to use p.func(a) and when p:func(a) other than by trial-and-error or looking at examples in the code? That is, is there a way to document that in the .cc files from which the documentation is created? These docs are the place where I expect(ed) such things.

You need to use : if you call a method, i.e. a function defined in a class (most things in the API are methods), you need to use . if you call a function. For example

g = wl.Game()  -- creates a game class. This calls a method in the module 'wl'.
p = game.players[1] -- gets the first entry of the players property of this class which is an array of Player classes. There is no function call here.
p:get_buildings("blub") -- same as p.get_buildings(p, "blub"), calls a method on the class P.

Top Quote