• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ Game.getClientVersion()

Lais Prad

Disgusting Scammer
Joined
Apr 12, 2017
Messages
153
Solutions
6
Reaction score
15
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
 
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
 
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
 
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 can use github to find out what the function return etc etc

Add Game.getVersion (table) by WibbenZ · Pull Request #2086 · otland/forgottenserver · GitHub
I wrote it so we only return what is in defitions.h, min max and the string we send to the client (used if you login with the wrong protocol ex only 10.98 is allowed, 10.98 is the keyword).
So if you want it to work as you wish you need to modify the function in the source code.

// Edit forgot you can use player:getClient() that returns a table with version and os
 
Last edited:
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
Lua:
unpack = _VERSION == 'Lua 5.1' and unpack or table.unpack
print( unpack( Game.getClientVersion() ) )
 
use unpack as codex says

from lua(dot)org
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))
 
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 :)

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 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).
 
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
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.

I think that was a clerical error :p unless... Game.getClientVersion() has numeric indexes?
 
Last edited:
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
 
Back
Top