getCurrentRoomID() - keeping track of current room

Share your scripts and packages with other Mudlet users.
Post Reply
chrio
Posts: 73
Joined: Mon Aug 22, 2016 11:34 am

getCurrentRoomID() - keeping track of current room

Post by chrio »

Ok, so before an easy way to find the current room is implemented, we can do it ourself as a script in lua. It's not perfect, so if a room is deleted after we have centerviewed it, the currentRoomID will still be valid even if the room is gone.
Code: [show] | [select all] lua
-- getCurrentRoomID()
-- returns last RoomID that was used with centerview()
--         or 0 if centerview() failed.
-------------------------------------------------------

if not getCurrentRoomID then
	getCurrentRoomID = function ()
		currentRoomID = currentRoomID or 0
		return currentRoomID
	end

	oldCenterView = oldCenterView or centerview
	centerview = function(id)
		local retval = oldCenterView(id)
		if retval then
			currentRoomID = id
		else
			currentRoomID = 0
		end
		return retval
	end
end
After using this script, a global variable (currentRoomID) is always set when using centerview(). You can read it by calling the function getCurrentRoomID(). You could also read it directly as a variable, but then you have to be careful so you don't change its value by mistake.

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: getCurrentRoomID() - keeping track of current room

Post by SlySven »

Yeah, this will help until I (or some other coder) can get a command into the system to retrieve it...

Post Reply