[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Variables Name for Lua Global Var

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Variables Name for Lua Global Var
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] bio
Date Wed 28 Dec 2011 01:57 AM (UTC)  quote  ]
Message
okok, I try to rewrite in table format :D, thanks.

[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date 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:


_G ["lv_%1"] = "%2"


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
[Go to top] top

Posted by Fiendish   USA  (849 posts)  [Biography] bio   Global Moderator
Date 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/
[Go to top] top

Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] bio
Date 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,

lv_%1 = "%2"


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 '-'

-_-"
[Go to top] top

Posted by Fiendish   USA  (849 posts)  [Biography] bio   Global Moderator
Date 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

lv_%1 = "%2"

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/
[Go to top] top

Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] 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

a = b

, 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.
[Go to top] 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,094 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]