Gammon Forum
Entire forum
MUSHclient
Lua
Editing the script file with no hands
Editing the script file with no hands
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| ReallyCurious
USA (50 posts) bio
|
Date
| Wed 15 Apr 2009 01:24 PM (UTC) |
Message
| Is there a way to change/delete/add values in a table in the script file without having to open up the script file and manually make these changes. I'm trying to make a few plugins for friends that have started to use MC. The values in some of the tables in these plugins change daily and I want to make it as simple as possible to use so my friends don't have to worry about going into the plugin and editing the values themselves and then calling me a nerd which will hurt my feelings. | top |
|
Posted by
| Worstje
Netherlands (899 posts) bio
|
Date
| Reply #1 on Wed 15 Apr 2009 01:53 PM (UTC) |
Message
| You use both plugins and script file in the same sentence, so I'm not sure what you are trying to do. Plugins run in their own scripting space, completely seperate from your worlds script file.
The basic idea is simple: store the values that can change as MUSHclient variables so they can be reloaded when you reload the script, and provide aliases to manipulate these values.
That's about all the tips I can give you without knowing your problem in any detail. | top |
|
Posted by
| ReallyCurious
USA (50 posts) bio
|
Date
| Reply #2 on Wed 15 Apr 2009 02:58 PM (UTC) |
Message
| Oh I know they're two separate things but wouldn't it be the same procedure to edit the script file whether its in a plugin or not?
an example of what i mean:
in script file in plugin:
table = {a,b,c}
I want to add d e f to it now. Possible?
Can I add/change/remove values to this table by alias?
| top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #3 on Wed 15 Apr 2009 04:51 PM (UTC) Amended on Wed 15 Apr 2009 04:55 PM (UTC) by Twisol
|
Message
| You can just have an alias/trigger that Sends to Script, and put whatever you need in there. Within a plugin, to my knowledge, scripts in the file and scripts in the triggers/aliases run in the same space, so they have access to the same stuff. The script file is mostly a definitions file run when the plugin is installed, so it loads the definitions of required functions, and runs loose statements as well. After that, the scripting file should already be in memory. And triggers/aliases fire within that same memory space.
The point being, "changing something in a script file without opening it up myself" is a bit of a misnomer. The file is read in once, and everything else happens in memory.
Disclaimer: I don't know if this is true but it sure sounds right. Educated guess :D |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Worstje
Netherlands (899 posts) bio
|
Date
| Reply #4 on Wed 15 Apr 2009 07:09 PM (UTC) |
Message
| What Twisol says is correct. I'll point you back to my original post, which explains the basic process if you want to save the 'changes'.
Just to re-iterate the point clearly: you cannot literally change the code in your script file from your script - you will need to manipulate variables and make your script deal with some variables. | top |
|
Posted by
| ReallyCurious
USA (50 posts) bio
|
Date
| Reply #5 on Thu 16 Apr 2009 12:57 AM (UTC) Amended on Thu 16 Apr 2009 12:58 AM (UTC) by ReallyCurious
|
Message
|
Ah, okay. So I need to use variables.
The way I highlight character names for my mud is I put all the names I want for a certain color into the same table in my script file. Then I use an alias that creates the trigger for each value in the table. But, I'm always deleting values and adding values from the table. How would I do this with variables?
So this is what I've been doing:
in script file:
hlGreen = {"Worst","Jane","Twisol"}
and then use an alias to create triggers for each value.
But, what I to do is avoid having to open the script file, find the right table and then type in or delete values etc.
| top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #6 on Thu 16 Apr 2009 07:48 AM (UTC) |
Message
| Plugins are specifically designed to solve this problem, in particular with saving their "state" and reloading it next time you load the plugin.
The "state" is the variables the plugin owns. See this thread for how to serialize Lua variables into MUSHclient variables:
http://www.gammon.com.au/forum/?id=4960
Quote:
... so my friends don't have to worry about going into the plugin and editing the values themselves ...
Well the only things you need to change are variables and not the script itself, as your friends presumably don't want to muck around with your script.
Things like your example:
hlGreen = {"Worst","Jane","Twisol"}
... are crying out for serializing (as described above). Then you simply make an alias that adds to the table (eg. table.insert) or removes from the table (eg. table.remove).
In other words, don't hard-code table items into the plugin, start off with an empty table, and let the players add things themselves. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
18,096 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.