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 ➜ General ➜ Alias Help

Alias Help

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


Posted by Rynok   USA  (25 posts)  Bio
Date Fri 14 Jul 2006 02:50 AM (UTC)

Amended on Fri 14 Jul 2006 04:34 AM (UTC) by Rynok

Message
Alright, my original goal has been accomplished by changing my alias up a bit. I really like it now that I got it working, and it works great.

I was trying to use the file accessing with Lua so that I can read and write to a file for my different variables (to avoid read/write to MushClient variables).

Error:
[string "Script file"]:120: attempt to index global `io' (a nil value)
stack traceback:
[string "Script file"]:120: in function `ReadFile'
[string "Command line"]:1: in main chunk

Code: (I copyed it from another place, forgot where now)
function ReadFile()
do
local f = assert (io.open ("test.txt", "r"))
local t = f:read ("*all") -- read file in
f:close ()
Send (t) -- send to MUD
end
end
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 14 Jul 2006 06:16 AM (UTC)
Message
In the global preferences there is a Lua "sandbox" which is designed to stop dangerous operations. Misuse of the io library could be used to introduce viruses and other nasty things.

However if you trust the scripts that run you can find the line:


io = nil -- no disk IO


and comment it out like this:


-- io = nil -- no disk IO



Another approach to saving data is to use a plugin which saves its state. Then you simply put data into a MUSHclient variable and those variables will be automatically saved and loaded next time you run that plugin. See:

http://www.gammon.com.au/scripts/doc.php?function=GetVariable

http://www.gammon.com.au/scripts/doc.php?function=SetVariable

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Rynok   USA  (25 posts)  Bio
Date Reply #2 on Fri 14 Jul 2006 11:58 AM (UTC)
Message
Thanks for the help. I'll take a look and try to comment it out and see if that works. The reason I opted for the "io" stuff instead of the GetVariable was so I wouldn't have to save the Mud everytime I played (due to changing variables during play). With the IO it would be saved and the script would never change and the "world" file itself would never change so it would be a little bit less of a hassle I was thinking.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 14 Jul 2006 11:26 PM (UTC)
Message
If you shift the stuff into a plugin you don't save the world either, the plugin quietly saves its state when it is closed, and reloads it next time.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tsunami   USA  (204 posts)  Bio
Date Reply #4 on Wed 26 Jul 2006 11:37 PM (UTC)
Message
A quick and dirty serialization function I use in my plugins to save arrays in MUSHclient variables. Simply use a la:

world.SetVariable('Test',serialize(this_is_a_table))

and

this_is_a_table = unserialize(world.GetVariable('Test'))

function serialize(var)
	if(type(var) == 'table') then
		local output = 't{'
		for index,value in pairs(var) do
			output = output .. serialize(index) .. '|' .. serialize(value) .. ';'
		end
		return output .. '}'
	elseif(type(var) == 'number') then
		return 'n{' .. var .. '}'
	elseif(type(var) == 'string') then
		return 's{' .. var .. '}'
	elseif(type(var) == 'boolean') then
		return 'b{' .. (var and 'true' or 'false') .. '}'
	end
	
	return ''
end
function unserialize(var)
	if(var == nil or var == '') then
		return nil
	end
	
	local var_type = string.sub(var,1,1)
	if(var_type == 'b') then
		return (string.sub(var,3,-2) == 'true')
	elseif(var_type == 's') then
		return string.sub(var,3,-2)
	elseif(var_type == 'n') then
		return tonumber(string.sub(var,3,-2))
	elseif(var_type == 't') then
		local table = {}
		local t = utils.split(string.sub(var,3,-2),';')
		for _,tmp in pairs(t) do
			local p = utils.split(tmp,'|',2)
			if(p[1] and p[2]) then
				table[unserialize(p[1])] = unserialize(p[2])
			end
		end
		return table
	end
	
	return nil
end


Hope that helps you if you decide to use a plugin.
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.


21,498 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.