我正在将FiveM的Lua脚本转换成JavaScript (NodeJS platform),我遇到了一个奇怪的问题,我想不通了。
我要转换的功能很简单,它接受一个FiveM标识符(由fivem记录的用户流),并将其从十六进制转换为十进制。然后,它将十进制值传递给steam web API,以便我们可以解析配置文件名称/头像等的json响应。
代码本身运行良好。这个问题就像转换一样。由于显而易见的原因,我不能发布API密钥或steam ID,因此我将其清除以进行演示。
在LUA中:
local steamid = tonumber(tempSteam,16)检索十六进制steam id并将其转换为dec。
在JS中:
var steamid = parseInt(tempSteam,16);JS等同于上面的。
奇怪的是这一点。在JS中传入tempSteam会导致流结束###0,这与我的结束###6的配置文件不匹配(所有其他数字都是相同的)。
编辑:剪切解释内容,后来我发现(感谢评论) JS不能转换64位的值。因此,我现在需要找到一种解决方法。
发布于 2021-02-05 00:32:25
感谢对未知信息的评论,我不知道JS本身不能处理64位数字。
我已经找到了一个解决方案,所以我把它贴在这里,以防其他人遇到这个问题。
NodeJS 10+有一个新的BigInt函数,可以将十六进制值转换为64位有符号整数。
// Our steamhex variable, this is normally pulled via FiveM's identifiers
// so this const is just to demonstrate what it is.
// The 0x is important, without it the BigInt function seems to fail with a
// generic `cannot convert`.
const steamHex = '0x110000103d27e1d';
//If using fiveM use a replace i.e
//steamHex = steamHex.replace('steam:','0x');
//Returns 76561198024392221
var result = BigInt(steamHex);
//...pop result into your steam api call etc....https://stackoverflow.com/questions/66044920
复制相似问题