|
Variables Name for Lua Global Var
|
Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Tkl1129
Hong Kong (43 posts) bio
|
| Date |
Tue 27 Dec 2011 03:13 PM (UTC) [ quote
] |
| 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 (848 posts) bio
Global Moderator |
| Date |
Reply #1 on Tue 27 Dec 2011 04:22 PM (UTC) [ quote
] 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. |
http://aardwolfclientpackage.googlecode.com/ | top |
|
| Posted by |
Tkl1129
Hong Kong (43 posts) bio
|
| Date |
Reply #2 on Wed 28 Dec 2011 01:25 AM (UTC) [ quote
] |
| 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 (848 posts) bio
Global Moderator |
| Date |
Reply #3 on Wed 28 Dec 2011 01:35 AM (UTC) [ quote
] 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. |
http://aardwolfclientpackage.googlecode.com/ | top |
|
| Posted by |
Nick Gammon
Australia (18,770 posts) bio
Forum Administrator |
| Date |
Reply #4 on Wed 28 Dec 2011 01:54 AM (UTC) [ quote
] |
| 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) [ quote
] |
| 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.
1,090 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )