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.
Example
mob
Login()
getResolution()
src << "Player's Resolution : [currentResX] , [currentResY]."
// Prints "1366 , 768" for me.
The Code
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.
mob
var
currentResX = 0
currentResY = 0
proc
getResolution(window) // Can use any window.
if(!window) return
var
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,"menu=false")
winset(src,window,"titlebar=false")
winset(src,window,"statusbar=false")
winset(src,window,"can-resize=false")
winset(src,window,"size = 2000x2000")
currentResX = getWinX(window)
currentResY = getWinY(window)
winset(src,window,"menu=[winMenu]")
winset(src,window,"titlebar=[winTitle]")
winset(src,window,"statusbar=[winStatus]")
winset(src,window,"can-resize=[winResize]")
winset(src,window,"size = [winResX]x[winResY]")
return
getWinX(window)
var/res = getWinRes(window)
if(res)
return res[1]
else return
getWinY(window)
var/res = getWinRes(window)
if(res)
return res[2]
else return
getWinRes(window)
if(!window) return
var/size = winget(src,"[window]","size")
if(size) return text2List(size,"x")
else return
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/buggyText
var/loopForever = 1
while(loopForever)
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.
return numList
else
if (searchPosition > textLength) // Found separator at very end of string.
numList += "" // So add empty element.
return numList
there is also no reason for text2list, when there is only two values. it is probably easier, and more efficient to just parse it yourself.