It uses player
Is cid then what is refered by boolean?
Just trying to learn
I have compat lua
Does that mean no 1.1 scripts will have cid?
Thanks for helping
In pre-1.1 servers, cid is the monster, player or npc id
In 1.0 in order to access the metamethods of the above mentioned you need pass cid to to their respective constructors.
Lets take a player for instance, if you wanted to construct a player you would pass cid to Player
Code:
local player = Player(cid)
From there you would proceed with your code and check if player is a player or is nil.
Code:
if player then
-- do something
end
If its nil this means either cid is nil or cid is not a player.
When writing scripts you want to test all values which you are creating, returning, comparing or deleting.
A very simple way to do this is to use the print function
This will print whatever value player holds even if player is nil to the console, if player is a table it will print table and then some arbitrary number after it.
You can also check to see what type a value is simply by using type.
If you want to test more then 1 value you would place a comma after the initial value.
Code:
print(player, type(player), player:getId(), player:getName())
When writing scripts, its important to test everything
The compat.lua in every distro is not necessarily a compatibility file, it is a library file which simplifies code.
An example of 1.2 compat.lua
Code:
function isPlayer(cid) return Player(cid) ~= nil end
The cid you see in isPlayer is called a parameter, the value you pass to this function is called an argument, the parameter cid in isPlayer can easily be named anything, like id.
Code:
function isPlayer(id) return Player(id) ~= nil end
The parameter is not as important as the value or argument which is passed to the function, the parameter of a function/metamethod its scope or life only exists within the function definition and nowhere else.
1.0
Code:
function onStepin(cid, item slot)
if isPlayer(cid) then -- this will call the isPlayer function from compat.lua
-- do something
end
end
In the movement script, cid is the argument, and will pass the value of cid to isPlayer.