Page 1 of 1

Which Open Does What & In What Order?

Posted: Wed Sep 09, 2015 9:11 pm
by oldefoxx
Since Help's Search feature is so limited, I can't group the Opens together to easuly do this myself. So I will simply ask:

What's the purpose of each of the following. Why do I need more than one in a program, and in what order should they be called?

OpenScreen()
OpenWindow()
OpenWindowScreen()
OpenWindowedScreen()
OpenWindow3D()

Did I miss any? I got a response on another thread that indicated I need to InitKeyboard() and InitSprite() before any if these, and InitSprite() comes before all.

Most programs don't seem to close anything. They just reach an end and boom! It all stops. But you have CloseScreen(), CloseWindow(), CloseWindow3D(), and CloseProgram() options. Why aren't these used, and if needed, when? There seems to be no CloseWindowScreen() or CloseWindowedScreen(), so I guess these are somehow "lumped" together

The Search tool on these forums has just proved its worth. It is not case sensitive, and it gives you a contraction of what appears in each matched post. It shows order of things as others apply them. You can log into the forums more than once on different threads, do different searches, and uncover a surprising amount of undesclosed detail this way. For instance,by searching for initsprite(), I got over 3100 matches, and began to look down them:

. #PB_3DArchive_FileSystem) Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem) Parse3DScripts() InitSprite() InitKeyboard() InitMouse() OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0) CreateCamera(#camera, 0, 0, ...

... works without the debugger: Enumeration #material #camera #plane #cube1 #cylinder EndEnumeration #CameraSpeed = 0.1 InitEngine3D() InitSprite() InitKeyboard() InitMouse() ExamineDesktops() OpenWindow(0,0,0,DesktopWidth(0), DesktopHeight(0)," ..",#PB_Window_ScreenCentered) ...

.. #PB_3DArchive_FileSystem) Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem) Parse3DScripts() InitSprite() InitKeyboard() InitMouse() OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0) CreateCamera(#camera, 0, 0, ...

... #PB_3DArchive_FileSystem) Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem) Parse3DScripts() InitSprite() InitKeyboard() InitMouse() OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0) CreateMaterial(0, LoadTexture(0, ...

... values of x, y or z change. - Press space bar for a pulse - Esc for exit. Enumeration #Mainform EndEnumeration InitEngine3D() : InitKeyboard() : InitSprite() : InitMouse() OpenWindow(#Mainform,0,0, 1024, 768, "[PB 5.40 - ApplyEntityTorque", #PB_Window_SystemMenu) OpenWindowedScreen(WindowID(#Mainform),0,0,1024,768,0, ...

These are all interesting, but for different reasons. Several show where something can preceed InitSprite(), but the last one shows InitKeyboard() coming before InitSprite(), which is contrary to what I was told. Now just because it was coded that way, doesn't mean that it compiled and ran. This is just included code in a post somewhere. But the forum Search provides you a link back to the source (the title is actually a link), where you can do a Select All, copy the source code to the clipboard, open the PureBasic IDE (or actually any text editor), paste it, save it as a text file (with .pb extension) or compile it and test it.

What you have here is the perfect way of getting details about program construction you won't find anywhere else. Nothing is explained, but it is prepackaged example code. In most cases it should compile and run as-is, so you can see what it does. You can group it by the folders where you place it, for later reference or use. If it doesn't compile and run properly, because it was posted as problem code, the provided link takes you to the thread where it was likely solved.

Rather than search for the post and thread again. make a point of copying the link provided into the first (or last) line as a comment, behind a ";". while you are in the IDE or Editor. You can go back to the discussion or source anytime you want to by simply using the added link in the source code.

The problem with this is, it is simply not efficient. Here are the steps required:

Code: Select all

(1)  Pick a term of interest.  In this case, InitSprite()
(2) Login to PureBasic,fr/english
(3)  Enter the term into the search box.  Use Advance Search if more than one term is involved.
(4)  Pick through the results,  Do the following as a means to an end:
      a.  Click on a link with either mouse button,  Open a new tab, or contunue the present tab. 
      b.  Left-click on Select All.  Right-click and copy or Ctrl+C key combo.
      c.  Open a text editor or PureBasic IDE.  If the IDE, start a new file.
      d.  Using right-click and paste or Ctrl+V key combo, paste the selected source code into the
           text editor or IDE file.
      e.  Going back to the original tab or using the Back button, or simply doing a copy of the URL
          on the address box of the present tab, copy the link (URL) to the clipboard.
      f.  Return to the text editor or IDE.  Paste the Link/URL into the source code, top or bottom.
     g.  Put a ";" (semi-colon in front to make it a comment line.    
     h.  Now save it with a name and .pb extension.  You have to pick or make a folder where you
         want it to go (I named mine PBforums for starters).  For name, I began with pb0001.pb.
     i.  Either now or later, you will probably want to compile and run it, first to see if it will compile,
        and second, to see what it does.
If you had a clipboard that allowed two test entries to be put in at once, then returned in order, or one just added to the other, you could consolidate the link and the source together. Maybe even add the ";" or whatever you preselected before the first one. It would cut down a lot of steps. Going a bit further, it could open a new file in the IDE and just copy it all into it. Or, from the Server side, send you a premade file that had the ";" $link "\n" $source as a download.

I tried my first program, one involving Torque. The link is http://www.purebasic.fr/english/viewtop ... te#p470501
When I tried to compile and run it, it failed to compile. It's complaint was that CreateEntityBody was not a function, array, list, map or micro. And though it is capitalized like a keyword, changing it to all lower case showed that it was indeed not a keyword, since it did not adjust back as it had been automatically.

Now my first step, after manually changing it to lower case, something the IDE could have helped with if it gave you three choices concerning keywords:
(1) Change all keywords to UPPERCASE
(2) Change all keywords to lowercase
(3) Change all keywords to MixedCase (default)

If you picked (1) or (2), then went back to (3), and the word/term did not flip, it would be recognized immediately as not being a keyword. This would be a nice feature to have in the IDE

Okay, so what is CreateEntityBody()? The starting place to find out is to go back to the thread. And I have the link added to the source file. But now there is a problem: Unlike most email clients (which it's not one), the IDE does not recognize embedded URLs as a link to call up a web browser and go there. You have to copy the line (minus the ";") to the clipboard, open the browser yourself, select the address box, clear it (pr select all the contents), and do a paste, then hit the Enter key to go there. The job is made a little simpler if you use the Slimjet browser, as it allows you to open a new tab with nothing in the address box, or if something there then just click it once to do a select all, then the paste can be an immediate GO to that place. It's all in the settings.

What might be even better is for the PureBasic IDE to recognize ";http://" or ";https://" in source code as a link, so that when you right-click on it, it calls the default (or designated) browser and take you right there. But maybe that is just my opinion.

I went back to the forums, searched on createentitybody(, and the links indicate that it is related to beta tests for PB 5.40. In other words, it will be a feature add-in with a forthcoming release of the compiler. I didn't have to ask anybody, I just used Search and my noggin to unearth an answer.

Can't do that so well when picking among the possibilities with the Open* and Init* statements though. You can find what works, but as to why these choices and for what purpose, that has to either be in the documentation(?) or asked of experts (anybody that knows more than I do).

Re: Which Open Does What & In What Order?

Posted: Wed Sep 09, 2015 9:37 pm
by infratec
Hi,

too many things which you are mixing in one post.

In general:

If you program only window GUI stuff, you only need OpenWindow()
CloseWindow() is also needed if you open a second window wich you have to close after some actions.

If you want to use sprites you need a faster solution.
So you have to use OpenScreen().
Then you need (in most cases) also InitSprite(), InitKeyboard() and InitMouse()
But if you don't want a fullscreen program, you need the combination of
OpenWindow() and OpenWindowedScreen()
The order of the Init..() is not fixed. You can use them in any order.

If you want to write a 3D programm, than you need OpenWindow3D()

So the Open.. stuff depends on your application.

OpenWindowScreen() is not available.


Since PB is an active developed language, some commands are changing from time to time.
You can read the changes in the Changelogs
http://www.purebasic.com/news.php

Bernd

Re: Which Open Does What & In What Order?

Posted: Thu Sep 10, 2015 4:52 am
by TI-994A
oldefoxx wrote:What's the purpose of each of the following. Why do I need more than one in a program, and in what order should they be called?

OpenScreen()
OpenWindow()
OpenWindowScreen()
OpenWindowedScreen()
OpenWindow3D()

Did I miss any?
It appears that you might have; namely, the manual.

PureBasic Reference Manual

Among the categories found on the index page, are the General Libraries and the 2D & 3D Games & Multimedia Libraries. And as infratec has mentioned, unless you're targeting graphics-intensive applications, you needn't bother with the latter two.

For basic drawing and graphics purposes, the functions in the 2D Drawing library (top item under the General Libraries) would suffice nicely.

If this is indeed the case for you, it would greatly narrow down and simplify your required scope of study.

Re: Which Open Does What & In What Order?

Posted: Thu Sep 10, 2015 12:30 pm
by Vera
Bernd wrote:You can read the changes in the Changelogs
http://www.purebasic.com/news.php
Good hint :-)

Though if one doesn't know in which version a change took place it's easier to search within the full history. Either within the help itself or again choose the single paged full online-purebasic-history.

greets ~ Vera

Re: Which Open Does What & In What Order?

Posted: Thu Sep 10, 2015 4:57 pm
by chris_b
oldefoxx wrote:Since Help's Search feature is so limited
On this point: remember you can search the online documentation with Google, just add site:http://www.purebasic.com/documentation/ before your search query.

Re: Which Open Does What & In What Order?

Posted: Fri Sep 11, 2015 7:47 pm
by oldefoxx
Thanks for the ready responses. I just discovered what a bonus the forum Search tool is, and plan to make good use of it. It can take me right to related example code. I tried all night to finish up my bash script for searching *.pb* files on my hard drive, but discovered the extract=${string#substring} extraction feature in bash is not working. The other choice of copy=${string:location[:length]} seems to require constants for location and length, which makes it ineffectual in most cases, unless dealing with fixed length fields in the string in question.

Brings to mind that in the early days of computing, there was strong interest in code that would modify and adapt itself on the fly. The entire CDC 1604A operating system in the Fleet Operationa; Control Centers relied on this capability, so when we heard the industry was moving to ROM as the housing for the OS, we weren't sure how that would work. Well, only the BIOS really moved, the rest was just loaded into RAM from external storage media, but self-modifying code seems to have slipped away for the most part.

An exception was script files that would write and call subordinate script files. You could tailor the child processes to accept the contents of variables as inline constants,one line at a time, so while the scripting language might be somewhat lacking, you could narrow the gap here and there. The other course was to write programs in other languages and have their executables available for calling from scripts or other programs. Brick on brick was the trick.

An advantage of higher level languages is that they have far superior ways of handling numbers and strings than bash has. It's really very limited in many regards. It makes no real distinction between numeric and string variables, has its own rules for assigning or testing variables, poorly understood behavior when it comes to use of regex or eval, depends on many other utilities such as find, grep, awk, sed, echo, printf, and much more, and these don't all share the same syntax.

Where they do agree, the resulting behavior may differ. To avoid problems, some things have to be enclosed in single or double quotes, parenthesis, two sets of parenthesis, square brackets, double sets of square brackets, or some combination of any or all of these. Spacing can be a big factor, and the best rule is to find an example to go by when putting your own efforts together, or find a place online where you can ppse a question and get some decent answers.

Like with this forum. Now here you have a single language and syntax. Your biggest challenge in that regard might be learning how to translate code in a different language or syntax over to PureBasic. Or learning about libraries and API calls. Or just tailoring the steps and process you want your own program(s) to go through as you approach some new task or applicarion.

Think of it like getting to the store. Detail the actual steps involved in making this happen. Make an outline in brief. You might start off with a list like this:
Purpose in going: Get bread and milk
What's need to start: car, truck, motorcycle, bike
What's needed first: Make plan known, just in case
Next: dress to go out
Next: get keys, money [shopping list?]
Next: leave house [turn off anything/everything? lock door?]
Next: get in/on vehicle [tires okay? Any leaks?]
Next: get started [engine okay, enough gas?]
Next: check traffic. Drive [which store, what direction?]
next: obey traffic laws [speed, side of road, intersections, distance between vehicles]
next: follow route to store [do you know how to get there?]
next: find entry point to parking lot [is the lot full?]
next: find vacant parking spot. Pull in [if no empty spot, keep circling or go elsewhere?]
next: turn off engine [unless on a bike]
next: walk to store entrance [grab buggy on way?]
next: enter store [grab empty buggy if not already in hand]
next: start looking [head to right section, look as you go]
next: place selected items in cart [estimate total so as not to exceed buying limit]
next: got everything? or money run out? Go to checkout [pick shortest line]
next: place item(s) on belt for cashier [plastic or paper?]
next: pay amount due [or use credit/debit card, personal check, and/or food stamps]

You get the gist. This is the nature of programming. It's got to all be planned out, because a computer does not have the advantage of having done it all so many times before so that it is all second nature to it now. It doesn't observe and learn as living things do. It doesn't see the world in terms of what works for it and what doesn't. It computes, but not think or feel. It doesn't reason (though many humans act like they don't either). It simply isn't alive.

How much detail we humans and aspiring programmers have to explore and then code for depends greatly on what others have already achieved with regards to the capabilities of the programming language, the available libraries and what they offer, the example code (which can come from anywhere), and the documentation for all of this.