Loop the table to find out whats inside?
int LuaScriptInterface::luaGameGetClientVersion(lua_State* L)
{
// Game.getClientVersion()
lua_createtable(L, 0, 3);
setField(L, "min", CLIENT_VERSION_MIN);
setField(L, "max", CLIENT_VERSION_MAX);
setField(L, "string", CLIENT_VERSION_STR);
return 1;
}
print(versionClient["min"]) // minimum version required
print(versionClient["max"]) // maximum version required
print(versionClient["string"]) // this I have no idea what will print, check it out yourself
You should see in your print that you're trying to print a table and in case of lua it does tell you it's a table, Game.getClientVersion() is here:
C++:int LuaScriptInterface::luaGameGetClientVersion(lua_State* L) { // Game.getClientVersion() lua_createtable(L, 0, 3); setField(L, "min", CLIENT_VERSION_MIN); setField(L, "max", CLIENT_VERSION_MAX); setField(L, "string", CLIENT_VERSION_STR); return 1; }
and this basically means your versionClient variable is an array with 3 keys: min, max, string. You should access them like that:
LUA:print(versionClient["min"]) // minimum version required print(versionClient["max"]) // maximum version required print(versionClient["string"]) // this I have no idea what will print, check it out yourself
I wanted to start the version of the player when entering the game.
print max and min will print versions from my definitions, I think
tfs 1.3
How to print version?
I trying this in login.lua:
LUA:local versionClient = Game.getClientVersion() print(versionClient)
But look what this print:
Code:table: 0x41bfdfb8 table: 0x41074b00
unpack = _VERSION == 'Lua 5.1' and unpack or table.unpack
print( unpack( Game.getClientVersion() ) )
A special function with multiple returns is unpack. It receives an array and returns as results all elements from the array, starting from index 1:
Code:print(unpack{10,20,30}) --> 10 20 30 a,b = unpack{10,20,30} -- a=10, b=20, 30 is discarded
An important use for unpack is in a generic call mechanism. A generic call mechanism allows you to call any function, with any arguments, dynamically. In ANSI C, for instance, there is no way to do that. You can declare a function that receives a variable number of arguments (with stdarg.h) and you can call a variable function, using pointers to functions. However, you cannot call a function with a variable number of arguments: Each call you write in C has a fixed number of arguments and each argument has a fixed type. In Lua, if you want to call a variable function f with variable arguments in an array a, you simply write
Code:f(unpack(a))
local client = Game.getClientVersion()
print(client.min, client.max, client.string)
for _, value in ipairs(Game.getClientVersion()) do
print(value)
end
I wanted to start the version of the player when entering the game.
print max and min will print versions from my definitions, I think
You sure that is correct @Printer? ipairs can't iterate over non-numeric indexes and it most certainly won't index over numeric indexes which exceed the range/size of the table.E.g 1:
Code:local client = Game.getClientVersion() print(client.min, client.max, client.string)
E.g 2:
Code:for _, value in ipairs(Game.getClientVersion()) do print(value) end
All guys above, I think he wants to print user's client version, not definintions from server
You should have a look here C++ - Game.getClientVersion().
Just like WibbenZ wrote, you should use player::getClient() instead and just remember it will also return an array / table with these keys: "version" (protocol version used by client), "os" (operating system client is running on).
// Edit forgot you can use player:getClient() that returns a table with version and os