[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]  Making Use of Serialised Variables?
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Making Use of Serialised Variables?

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Simimi   (40 posts)  [Biography] bio
Date Sat 01 Sep 2007 09:10 AM (UTC)  quote  ]
Message
I have a variables serialised as follows:

data = {}
  data.enchantments = {}
    data.enchantments.perfection = 108386
    data.enchantments.kingdom = 55407
    data.enchantments.mercy = 114946
  data.cube = {}
    data.cube.cube = 67697

In theory, I would be adding to the data.enchantments table at any time. I want to have an alias (recharge) that send, in psuedocode;

recharge first thing in data.enchantments (in this case 108386) from cube# (in this case 68697)


I am trying to make an alias to recharge a list of random enchanted jewlery from a given cube, but I want to set it up such that it can be another plugin for people to use. I could not think of a way to do this via script functions and an alias, so I decided to use a serialised variable instead.
The syntax for the in game command is;

Syntax: RECHARGE <item> FROM <cube>

So recharge would have to send the command for each thing in the data.enchantments table, for whatever given person has...

I guess this is 2 questions in essence...
1) How do we interface with a serialised variable, to use the information in an alias?
2) Is there a 'better' (or more plugin/user friendly) way to achieve this goal, aside from a serialised plugin?

Yours,
Mimi
[Go to top] top

Posted by Nick Gammon   Australia  (19,599 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 01 Sep 2007 10:40 AM (UTC)  quote  ]
Message
The quick answer is you can use loadstring to get Lua to "read" the string back into the same table it came from. It isn't totally clear if that is what you want.

http://www.gammon.com.au/forum/?id=4960


If you really want the variable serialized into some sort of local variable, see setfenv:

http://www.gammon.com.au/scripts/doc.php?lua=setfenv


Either way, it doesn't seem to me to be a very natural way of doing things, to get one plugin to communicate to another, or are you doing something like CallPlugin to send data from one plugin to another.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Simimi   (40 posts)  [Biography] bio
Date Reply #2 on Sat 01 Sep 2007 12:41 PM (UTC)  quote  ]
Message
I'm just trying to get the alias itself to work, and then I want to package it as a plugin for others to use. It does not seem natural to me but I can not think of any other way other than a bunch of mush variables and a big fat alias...

Which might not be a bad idea now that I think about it...
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #3 on Sat 01 Sep 2007 05:02 PM (UTC)  quote  ]
Message
Although I am not sure of what the whole kingdom/perfection/mercy thing is, probably the best thing to do to grab the 'first' thing in a list is to make a list with numbers as keys instead of words.

data = {}
  data.enchantments = {}
    data.enchantments.perfection = 108386
    data.enchantments.kingdom = 55407
    data.enchantments.mercy = 114946
  data.cube = {}
    data.cube.cube = 67697
  data.order = {}
    data.order.1 = "perfection"
    data.order.2 = "kingdom"
    data.order.3 = "mercy"


Then later, just call the first thing in the list with data.enchantments[data.order[1]] and use table.insert and table.remove to add and remove data to the order list. You can even make it a priority queue by inserting the new enchantment before certain other enchantments.

It is much easier to fight for one's ideals than to live up to them.
[Go to top] top

Posted by Simimi   (40 posts)  [Biography] bio
Date Reply #4 on Sat 01 Sep 2007 11:58 PM (UTC)  quote  ]
Message
Ahh ok, that helps a lot! I didn't even think of table.sort and .remove . Thanks once again, Mr. Biggs
[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,857 views.

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[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]    [Web site powered by FutureQuest.Net]