|
Post by kennn on Jan 6, 2020 16:58:19 GMT -6
Some advanced RCBasic users sometimes need to know width(in pixel), height(in pixel) of gamer's desktop and frequency of gamer's monitor.
There is not such command in RCBasic manual for users to do the above things. Actually, it is also a feature request.
|
|
|
Post by johnno56 on Jan 6, 2020 22:05:47 GMT -6
If memory serves correctly, sdlbasic is the same, in that the user defines the size of the display. This would imply that the user already knows the specs of the monitor in use.
Not knowing the max resolutions of 'other' users monitors can make it difficult to determine the settings for width and height. This is probably why most 'Basic' programmers will either choose 640x480 or 800x600 or 1024x768. Pretty much all Desktops and Laptops can handle those sizes.
Admin might be able to tell you if RC has the ability to check hardware specs or not... Sorry I couldn't be of much help...\
J.
|
|
|
Post by n00b on Jan 7, 2020 9:24:14 GMT -6
That would be a pretty useful function. I will try to get it in the next release. It probably won't be for a few months. I don't have much time to work on it right now.
But there is technically already a way of doing this in both rcbasic and sdlbasic. I will post an example later today when I get back home.
|
|
|
Post by kennn on Jan 7, 2020 15:40:38 GMT -6
johnno56, Thanks for your detailed feedback!
n00b, Next release.Thanks a lot!
An example later. Nice!
|
|
|
Post by johnno56 on Jan 7, 2020 16:40:37 GMT -6
Cool...
|
|
|
Post by n00b on Jan 7, 2020 19:43:34 GMT -6
Ok, here is a function that polls the operating system to get the screen resolution. It actually wouldn't take that much work to port this to sdlBasic if you want.
Note: On Windows this will only return the primary screen resolution
Function GetScreenResolution$(screen_num) Dim f_line$[20] Dim f_line_count: f_line_count=0 For i = 0 to 19 f_line$[i] = "" Next Select Case OS$ Case "WINDOWS" f = FreeFile s$ = "" temp_file1$ = Env("Temp") + "\\rc_tmp_scr_res_w.txt" temp_file2$ = Env("Temp") + "\\rc_tmp_scr_res_h.txt" System("wmic desktopmonitor get screenwidth /format:value > " + temp_file1$) System("wmic desktopmonitor get screenheight /format:value > " + temp_file2$) FileOpen(f, temp_file1$, TEXT_INPUT) tmp_str$ = "" While Not EOF(f) tmp_str$ = tmp_str$ + ReadLine$(f) Wend FileClose(f) w$ = "" eq_flag=false For i = 0 to Len(tmp_str$)-1 Select Case Mid(tmp_str$, i, 1) Case "1","2","3","4","5","6","7","8","9","0" w$ = w$ + Mid(tmp_str$, i, 1) Case "=" If eq_flag Then Exit For Else eq_flag = True End If End Select Next FileOpen(f, temp_file2$, TEXT_INPUT) tmp_str$ = "" While Not EOF(f) tmp_str$ = tmp_str$ + ReadLine$(f) Wend FileClose(f) h$ = "" eq_flag=False For i = 0 to Len(tmp_str$)-1 Select Case Mid(tmp_str$, i, 1) Case "1","2","3","4","5","6","7","8","9","0" h$ = h$ + Mid(tmp_str$, i, 1) Case "=" If eq_flag Then Exit For Else eq_flag = True End If End Select Next Return w$+"x"+h$ Case "LINUX" f=FreeFile s$ = "" temp_file$ = "/tmp/rc_tmp_scr_res.txt" System("xrandr > " + temp_file) FileOpen(f, temp_file$, TEXT_INPUT) While Not EOF(f) s$ = ReadLine$(f) n = InStr(lcase$(s$), " connected") If n >= 0 Then tmp_str$ = Mid(s$, n+10, Len(s$)) For i = 0 to Len(tmp_str)-1 Select Case Mid$(tmp_str$, i, 1) Case ".","0","1","2","3","4","5","6","7","8","9" For j = i to Len(tmp_str$)-1 Select Case Mid$(tmp_str$, j, 1) Case ".","0","1","2","3","4","5","6","7","8","9","x" f_line$[f_line_count] = f_line$[f_line_count] + Mid$(tmp_str$, j, 1) Default Exit For End Select Next Exit For End Select Next f_line_count = f_line_count + 1 End If Wend FileClose(f) If screen_num < 20 Then Return f_line$[screen_num] End If Case "MAC" f=FreeFile s$ = "" temp_file$ = "/tmp/rc_tmp_scr_res.txt" System("system_profiler SPDisplaysDataType | grep Resolution > " + temp_file) FileOpen(f, temp_file$, TEXT_INPUT) While Not EOF(f) s$ = ReadLine(f) n = InStr(s$, ":") If n >= 0 Then tmp_str$ = Mid$(s$, n+1, Len(s$)) For i = 0 to Len(tmp_str$)-1 Select Case Mid$(tmp_str$, i, 1) Case ".","0","1","2","3","4","5","6","7","8","9" For j = i to Len(tmp_str$)-1 Select Case Mid$(tmp_str$, j, 1) Case ".","0","1","2","3","4","5","6","7","8","9","x"," " f_line$[f_line_count] = f_line$[f_line_count] + Mid$(tmp_str$, j, 1) Default Exit For End Select Next Exit For End Select Next f_line_count = f_line_count + 1 End If Wend FileClose(f) If screen_num < 20 Then Return ReplaceSubstr(f_line$[screen_num], " ", "") End If End Select
End Function
Print "Resolution = "; GetScreenResolution$(0)
|
|
|
Post by johnno56 on Jan 8, 2020 0:41:24 GMT -6
Ran without error and reported correctly. Cool...
|
|
|
Post by sdlbasic on Jan 8, 2020 3:11:25 GMT -6
In sdlbasic we have :
prints(systemwidth()) prints(systemheight()) waitkey()
|
|
|
Post by n00b on Jan 8, 2020 7:10:19 GMT -6
In sdlbasic we have : prints(systemwidth()) prints(systemheight()) waitkey()
Awesome. I totally looked over that in the manual.
|
|
|
Post by tbird on Jan 8, 2020 7:52:21 GMT -6
I am happy I did not have to figure that out on my own.....much appreciated n00b.
|
|
|
Post by n00b on Jan 8, 2020 8:09:06 GMT -6
I am happy I did not have to figure that out on my own.....much appreciated n00b. I am glad this might be of use. I will add a built-in function in the next release but I just wanted to show a workaround for it until then.
|
|
|
Post by johnno56 on Jan 8, 2020 13:50:40 GMT -6
I've gone through the sdlbasic manual more times than I care to mention... But, for the life of me, I didn't even notice 'systemwidth' or 'systemheight'... Many thanks.
Great job with the 'work-a-round'!
J
|
|
|
Post by kennn on Jan 8, 2020 16:09:21 GMT -6
n00b,
Excellent!!! Thanks a lot!
The code looks complex. Ha....it really scares me. It may be hard for me to understand this code thoroughly. That's why some people say that programming is not for everybody. If I am working in game industry, I want to be a game designer. The code may also scare some novices, so an internal function in RCBasic will make them not so afraid of programming.
sdlbasic,
You were very quiet in the forum. I encourage you to give us expert opinions at any time.
|
|
|
Post by sdlbasic on Jan 9, 2020 2:58:37 GMT -6
In sdlbasic we have : prints(systemwidth()) prints(systemheight()) waitkey()
Awesome. I totally looked over that in the manual.
This is not in the manual, it's a new functions in the latest release.
|
|
|
Post by n00b on Jan 9, 2020 13:43:07 GMT -6
n00b, Excellent!!! Thanks a lot! The code looks complex. Ha....it really scares me. It may be hard for me to understand this code thoroughly. That's why some people say that programming is not for everybody. If I am working in game industry, I want to be a game designer. The code may also scare some novices, so an internal function in RCBasic will make them not so afraid of programming. Don't worry if you don't understand what I did. This code is doing some stuff that many modern computer science students wouldn't understand. Modern programming is all based on Libraries and API's that abstract OS specific stuff from the developer. But if you understand how to use the command line you could go beyond what a library is capable of by going straight to the OS. If you are learning python, javascript, or many other streamlined languages then you would just find a library that does everything you want and you would never have to worry about this. The same thing with BASIC as most BASIC languages will have a built in command for the specific stuff you want to do. But as you get more into programming you will be able to come up with solutions that are not immediately obvious. No matter how expansive a API or library is, it won't always do everything for you.
|
|