1. Place a label in the background of the skin and stretch across the whole window. Anchor it so its achors are(Anchor 1 : Top Left : X = 0, Y = 0) and (Anchor 2 : Bottom Right : X = 100,Y = 100). Set the labels name to screenlabel.
2. Now we will start the proc. Lets start by declaring the proc like so :
mob
proc
getscreenresolution()
set hidden = 1
3. Now lets start getting the resolution. First lets declare the variables needed like this :
var/totalsize
var/width
var/height
Just to make sure that we are getting the resolution lets include this piece of code which will maximize the window and make sure that the label is covering the screen.(I will sleep after the winset command to make sure that the window is maximized when I am getting the actual resolution)
winset(usr,"default","is-maximized=true")
sleep(1)
4.Now to actually get the resolution we will use a winget command and set it to the totalsize variable like this :
totalsize = winget(usr,"default.label1","size")
This gets the resolution in the format of numberXnumber. So some beginners would think that we are done and there is no need to go further. Well you are wrong. Check the next step for whats needed next.
5. Since the totalsize variable now equals the size of the screen we need to retrieve the individual values for width and height of the screen. We will do it by using a combination of copytext and findtext like this :
width = copytext(totalsize,1,findtext(totalsize,"x"))
height = copytext(totalsize,findtext(totalsize,"x")+1,lentext(totalsize))
Now to explain the code. For getting the width we copy the text from total size starting at the beginning and we go until the x so this will get the width of the screen. For the height we start past the x so that why I used +1 to move ahead 1 space. After that I use the lentext procedure to get the total length of the totalsize and use this as the end point. Now most people would probably think that this is the end of the tutorial. Go ahead and try using this code to retrieve the values. It will work but try using the values you got to set a value like a position to the values you got. It should throw an error. A way to fix this error is explained in the next step.
6. To fix the error we need to make use of the text2num procedure. All this procedure does really is convert a string(text) to a number. The procedure in this case would be used like this :
width = text2num(copytext(totalsize,1,findtext(totalsize,"x")))
Possible uses of getting the screen resolution :
Well the possibilities of the getscreenresolution I can think of are setting positions of skin elements. Since alot of people have different resolutions you could set the skin element positions to be in perfect places for everyone and not only your own computer. Another use I can think of is so you could set the client.view perfectly for everyone.
Well hope this help anyone.(Also I did proof read the tutorial so if there is any flaws please do tell me)