This function is for anyone wanting to get the resolution of their player's screen with one simple function. It will only work for people who use an interface file (.DMF). Also it should be noted that this will work safely with any window at all in your interface file.
How It Works
This function works by preparing a window to be rapidly expanded. When it reaches the limit of the player's screen it will stop and record how far it got in two player variables (mob/var).
Namely : currentResX & currentResY
After the process is done it will return the window back to the way it was. Now, you can use any window you like. If you choose to use any non-transparent windows then please not that there will be a 'visual flash'. You can personally stop this from happening by adding a transparent window to your interface file and calling the function on that window. For example getResolution("transparent").
To make a transparent window for this purpose, set the window's background color to something unique such as bright cyan. Then set the transparent color property of that window to the same color. It will become invisible and you're done. Now just switch your call to that window and you won't experience a flash.
src << "Player's Resolution : [currentResX] , [currentResY]."
// Prints "1366 , 768" for me.
Simply copy paste this code into your project, it won't clash with anything you have. Now you can use it like in the example above.
Also, please note that the player's resolution variables will only update when this function is called.
currentResX = 0
currentResY = 0
getResolution(window) // Can use any window.
winResX = getWinX(window)
winResY = getWinX(window)
winMenu = winget(src,window,"menu")
winTitle = winget(src,window,"titlebar")
winStatus = winget(src,window,"statusbar")
winResize = winget(src,window,"can-resize")
winset(src,window,"size = 2000x2000")
currentResX = getWinX(window)
currentResY = getWinY(window)
winset(src,window,"size = [winResX]x[winResY]")
var/res = getWinRes(window)
var/res = getWinRes(window)
var/size = winget(src,"[window]","size")
if(size) return text2List(size,"x")
text2List(text, separator) // Written By Deadron | Modified By Red Hall Dev
if(!text || !separator) return
var/textLength = lentext(text)
var/separatorLength = lentext(separator)
var/list/numList = new /list()
var/searchPosition = 1
var/findPosition = 1
var/loopForever = 1
findPosition = findtextEx(text, separator, searchPosition, 0)
buggyText = text2num(copytext(text, searchPosition, findPosition)) // Everything from searchPosition to findPosition goes into a list element.
numList += buggyText // Working around weird problem where "text" != "text" after this copytext().
searchPosition = findPosition + separatorLength // Skip over separator.
if (findPosition == 0) // Didn't find anything at end of string so stop here.
if (searchPosition > textLength) // Found separator at very end of string.
numList += "" // So add empty element.