Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Variables Name for Lua Global Var
|
Variables Name for Lua Global Var
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Tkl1129
Hong Kong (43 posts) Bio
|
| Date
| Tue 27 Dec 2011 03:13 PM (UTC) |
| Message
| Hi all,
I have a question for this coding method, please kindly advice, thanks.
Case:
Trigger - > Skill: Unarmed - 100 lv
Sword - 120 lv
Pattern %1 = skill name, %2 = lv
local a = tostring("lv_" .. "%1")
local b = "%2"
SetVariables(a , b)
The Variables set in Mushclient was
Name : "lv_Sword"
Value: "120"
however this only use in Mush Global Var, how can I perform the same effect but only save in Lua Global Var?
what I want is
"lv_unarmed" - "100"
"lv_sword" - "120"
"lv_xxxx" - "xxx"
Normal Global var set in lua is
, but this will occur error
tostring("lv_" .. "%1") = "%2"
Do there any method can write in this way? I want to write in seperate var, not in Lua table. | | Top |
|
| Posted by
| Fiendish
USA (2,558 posts) Bio
Global Moderator |
| Date
| Reply #1 on Tue 27 Dec 2011 04:22 PM (UTC) Amended on Tue 27 Dec 2011 04:26 PM (UTC) by Fiendish
|
| Message
| %x expansion happens before the script engine is run, so you can just do
But I think you should reconsider the decision to not do it inside a table. A table would guarantee that you can easily keep track of all of your dynamically created variables. |
https://github.com/fiendish/aardwolfclientpackage | | Top |
|
| Posted by
| Tkl1129
Hong Kong (43 posts) Bio
|
| Date
| Reply #2 on Wed 28 Dec 2011 01:25 AM (UTC) |
| Message
| Thanks, it's work, but a problem again.
For the skill name
1. Sword
2. Unarmed
3. Axe
This 3 cap in the code below is work,
but for this case won't be work, it occur error base on "=" & "-"
1. Big-sword
2. Big-Axe
I cannot cap in Lua Global Var "lv_Big-Axe"
Error Message:
[String "Trigger: "]:3: '=' expected near '-'
-_-"
| | Top |
|
| Posted by
| Fiendish
USA (2,558 posts) Bio
Global Moderator |
| Date
| Reply #3 on Wed 28 Dec 2011 01:35 AM (UTC) Amended on Wed 28 Dec 2011 01:36 AM (UTC) by Fiendish
|
| Message
| | You're probably going to need to use the dostring function. Again, I think you should reconsider using table members. |
https://github.com/fiendish/aardwolfclientpackage | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Wed 28 Dec 2011 01:54 AM (UTC) |
| Message
| I strongly agree with Fiendish here. You are better off making a table and indexing into it. Then you can do this...
skills = skills or {} -- make table if necessary
test = "Big-sword"
skills [test] = 42
Or even:
skills ["Big-sword"] = 42
However if you *must* use global variables <sigh> then you can do this:
However I warn you that it is easy to serialize (save for tomorrow) a normal table, not the _G table. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Tkl1129
Hong Kong (43 posts) Bio
|
| Date
| Reply #5 on Wed 28 Dec 2011 01:57 AM (UTC) |
| Message
| okok, I try to rewrite in table format :D, thanks.
| | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
20,002 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top