Register forum user name Search FAQ

Gammon Forum

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 ➜ Making Use of Serialised Variables?

Making Use of Serialised Variables?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Simimi   (40 posts)  Bio
Date Sat 01 Sep 2007 09:10 AM (UTC)
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
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 01 Sep 2007 10:40 AM (UTC)
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
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #2 on Sat 01 Sep 2007 12:41 PM (UTC)
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...
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #3 on Sat 01 Sep 2007 05:02 PM (UTC)
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.
Top

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


17,154 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.