如何使字符串成为LUA脚本中的一个数字(我的问题并不那么简单)

发布于 2025-01-31 20:00:55 字数 258 浏览 3 评论 0原文

我想知道如何在lua脚本中以一个字符串中的数字转换一个数字,但是我知道是否这样做

= 10, 那么“ var”等于10 但是我的问题并不简单,我的意思是将数字转换为字符串,但要继续有其价值

示例 var = 10 因此,如果我添加10 + 5等于15 我想要的是: var + 5 = 15 因此,“ var”尽管是一个数字,但“ var”

(我想这样做,因为我都无法将变量与消息(var)一起显示,以及另一个将在“您的数字为::”之间显示的消息(var)。

I wanna know How to convert a number in one String,in lua script,but i know If do this

Var = 10 ,
then the "var" Will be equal to 10
But my question is not simple I mean Literally transform the number into a String but keep having its value

Example
Var = 10
So if I add 10 + 5 is equal to 15
And what i want is :
Var + 5 = 15
So the "var" despite being a String works as a number

(I want to do this because I can't pull my variable to be displayed in a message (Var) along with another message that will be between "Your number is:"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹤仙姿 2025-02-07 20:00:55

这很简单,只需将您的变量包裹起来:

var x = tonumber(x)

print(type(x))

-- Output : number.

这将转换字符串x将基本b [2..36,默认值:10]中的数字表示为一个数字,或者如果无效,则nil;对于基本10,它接受完整格式(例如“ 1.5E6”)。

It’s quite simple, just wrap your variable like this:

var x = tonumber(x)

print(type(x))

-- Output : number.

This converts string x representing a number in base b [2..36, default: 10] to a number, or nil if invalid; for base 10, it accepts full format (e.g. "1.5e6").

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文