ID:903858
 
Ok so this gave me some trouble before so I decided to make this tutorial on how to get the screen resolution. I am going to do this in steps.

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)

This is helpful. I want to set 64x64 icon size OR 32x32 for computers which cannot handle a modern resolution. I can now check to see whether some idiot is using an 800x600 res and still allow them to play the game.
In response to DvK87
Glad that I helped =)
That's very cool! I never really thought of using winget() to obtain the client's "resolution". It does seem like a complex setup, but it's worth it to obtain the resolution. I had thought you would have to use client-side javascript, like HDK Mouse and Keys, but apparently not!

However, does the height value include the width of the Windows Taskbar or not? It just seems like it wouldn't unless the "label" you are stretching out makes use of the full screen hack. In other words, does this give you the client's actual screen resolution (like in display settings), or is it just the normal "usable area" of the screen?
Well if you use the is-maximized=true with the title bar and the other options like that disabled then yes it would retrieve the full resolution as it is in the display settings.
If you do not want a game to use the full screen option but still would like to get the resolution of the players computer for skin or hud purposes then I be happy to tell ya that I found a work around for this.

1. You would need to make another window with titlebar,statusbar,close,minimize and resize disabled.

2.Place a label in the window and stretch it across the window. Set the anchors like it was in the tutorial.

3. You would use the winset command to make sure that the window is not visible like so

winset(usr,"default1","is-visible=false")


4. Then you would have to make the window with the label maximized like so :

winset(usr,"default1","is-maximized=true")


5. Then use the screen resolution code.

Basically this would get the full resolution without you actually needing to utilise the full screen in your game(well your players would never know). This method is actually move preferable by me because I dont have to use the label in the main window so when editing the skin its easier. Also sorry for the dumbing this down but I intended this comment for everyone else who reads the tutorial if they ask a question like yours.
There are some errors in what you've written. The main is that there's no need to make a label within the window. Every window has a size variable. Please refer to the skin reference.

http://www.byond.com/docs/ref/skinparams.html

Also, I just wrote a set of functions that would help shorten what you're trying to do.

http://www.byond.com/forum/?post=909426

I think you had a good start but this tutorial needs more work. What you were/are teaching at the point of this message isn't what we want people to learn so I think I kind of speak on behalf of some of the people too lazy to correct you when I say please fix the tutorial. I would say it's beneficial to use the processes I provided as well but that's really your choice. Remember that you wouldn't have to explain text2List, just as you don't explain the long list of what copytext() is actually doing.

In response to Red Hall Dev
Oh yeah, and I would imagine your snippit causes the user's window to flash for a short moment while it gets the resolution. If that's happening, my challenge to you is to make a system that gets it without causing a flash!

I've just designed it so I know it's possible, please ask me if you can't do and I'll explain. It's just that so long as the screen is flashing, you're not giving the correct tutorial.
In response to Red Hall Dev
Red Hall Dev wrote:
There are some errors in what you've written. The main is that there's no need to make a label within the window. Every window has a size variable. Please refer to the skin reference.

http://www.byond.com/docs/ref/skinparams.html

Windows don't show the right size when a window is maximised. It shows the size it was before it was maximised. The current work around is to use an element like a label to get the actual size.

Okay, I kind of did two replies and I deleted them both. That's because I tried to create a system that works without using a label because that seems like unnecessary complication. My method was equally as hackish but it meant the users wouldn't notice. It was however wrong and now I'm back to thinking I got it.

What a roller coaster. Hopefully I can drop my solution under this message sometime tonight or tomorrow. It's one of those "seeing the forest through the trees" type problems.
In response to Cbgames
Okay, I wrote my own getResolution() function which solves all these issues.

http://www.byond.com/forum/?post=909579

I think that makes this tutorial nulled and bad practise to follow but that's not my decision. Just saying. Was such a fun problem to solve, thanks DJ Dovis as well.
Well in my way I do not see any flashing as you said. Also just a question. Even though my way might flash a bit your way isnt perfect. How come I can see the window quickly stretch to one side of my screen and then go back to normal? How can you make a work around for that ? (Well actually I have a way to work around it but thats a question for you). Also I did not use deadron text2list function so that made the tutorial longer. Either way it was a tutorial and not a library which I made. This basically shows how to get started. I can make a total plugin which wouldnt require a person to do anything much as just use variables. By the way nice idea on making the windows size = 2000x2000 so it would stretch out to the borders of the screen and then using winget to get the size.
In response to Dj dovis
He already said how to prevent flashing; make a transparent window. It's in the tutorial, if you read it.
Wouldnt it be alot more simple to just use winset to make the window not visible by using is-visible property and setting it to false and then perform the other stuff? Seems that he wanted to prevent non-necessary steps in the setup.
In response to Dj dovis
Oh yeah, sorry that was ambiguous of me to state that when I said 'flash' I really meant to describe the rapid expansion where you see the window go out and back in. Like Albro said it's just at the end of what I wrote. You need to use a transparent background color. Simply editing transparency and setting to 0 isn't the same thing.

Thanks for the props on getting those windows to fit the screen. Probably took me quite a while to find all the puzzle pieces and put it together.
In response to Dj dovis
Dj dovis wrote:
Wouldnt it be alot more simple to just use winset to make the window not visible by using is-visible property and setting it to false and then perform the other stuff? Seems that he wanted to prevent non-necessary steps in the setup.

I thought is-visble was something quite different to transparency. If I'm correct the moment you edit the size of a non visible window it comes to the forefront of the screen.