Learn2Program PB outdated?

Everything else that doesn't fall into one of the other PB categories.
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

Learn2Program PB outdated?

Post by TwoCatsYelling »

Hello,

I'm going through the "Programming 2D Scrolling Games" book. The free PDF download.

I'm noticing that for the past several example programs, it's opening with:

Code: Select all

If InitSprite()=0 Or InitKeyboard()=0 Or OpenScreen(640,480,16,"Input Test")=0
    MessageRequester("Error!", "Unable to Initialize Environment", #PB_MessageRequester_OK)
End
EndIf
In each case, the code sample is - presumably - intended to demonstrate a specific use. Such as For Next loops in the example I'm up to now (page 51).

Problem is, every time I run the provided code, it gives me the pop up window saying "Unable to Initialize Environment" because one or more of the conditions hasn't been met. For sure, I know sprites haven't been initialized. At first, I thought maybe the point wasn't that the code work, but that I get to see an example of the subject. But, seeing that it's the same situation with every example code provided, I'm thinking something's off somewhere. Every other programming book, tutorial or video I've ever seen, you're encouraged to type out the code to get you used to the process, and seeing the results. In this case, the results would always be "Unable to Initialize...", defeating the purpose of the lesson.

Is this something that PB is more strict about in more recent versions, but was permissible when the book was written?

I don't know how useful this book is going to be to me (or anyone, really) if the code samples don't work.

Can someone shed some light on this? Should I not be using this book at this point?

Thanks
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Learn2Program PB outdated?

Post by Paul »

If you look at the first page of the book you see it was written for PureBasic version 4.61 and updated for 5.0
There have been over 20 versions of PureBasic since then so you will certainly find syntax changes as well as new commands since then.

If you want to follow the book exactly, you can download those specific versions of PureBasic from the PureBasic archive. Otherwise you can look at the history section in the PureBasic help file to see the various changes that have been made from version to version and modify examples from the book accordingly.
Image Image
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

Re: Learn2Program PB outdated?

Post by TwoCatsYelling »

Paul wrote:If you look at the first page of the book you see it was written for PureBasic version 4.61 and updated for 5.0
There have been over 20 versions of PureBasic since then so you will certainly find syntax changes as well as new commands since then.

If you want to follow the book exactly, you can download those specific versions of PureBasic from the PureBasic archive. Otherwise you can look at the history section in the PureBasic help file to see the various changes that have been made from version to version and modify examples from the book accordingly.

So it is a matter of the examples in the book being outdated. Okay. I just started following it on the advice of another forum poster. I'm brand new to the language, so I had no idea about the language changes, etc.

I'll try to find newer examples/lessons to work from, then, that are compatible with the current version.

Thanks
BarryG
Addict
Addict
Posts: 3294
Joined: Thu Apr 18, 2019 8:17 am

Re: Learn2Program PB outdated?

Post by BarryG »

TwoCatsYelling wrote:So it is a matter of the examples in the book being outdated.
Any published physical book about anything computer-related will be obsolete/outdated after one year. The computer industry moves and changes too fast.

The best way for you to get help is to post questions here in these forums, along with example code that you've tried. People will generally assist if you do.
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: Learn2Program PB outdated?

Post by Rinzwind »

Change 16 to 32 (color depth) and it works. For some reason 16 bit color is unsupported? It changes display mode.. don't like it when example code uses that but ok.

Just compare with the help file Sprite.pb example . Would use OpenWindowedScreen btw.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Learn2Program PB outdated?

Post by Shardik »

I had bought the paperback book "Programming 2D Scrolling Games" just after its release and all examples worked without problems with the then current PureBasic version and hardware.

I have just tested the posted example on my iMac from 2019 and it indeed displays the error message on my modern hardware. The culprit seems to be the screen mode depth in the initialization example. I have tried the example from the PureBasic help for the NextScreenMode:

Code: Select all

InitSprite()

If ExamineScreenModes()
  While NextScreenMode()
    Debug Str(ScreenModeWidth())+"x"+Str(ScreenModeHeight())+"x"+Str(ScreenModeDepth())+"@"+Str(ScreenModeRefreshRate())+"Hz"
  Wend
EndIf
This example lists all possible screen modes for my Radeon Pro 570X 4 GB graphics card and although the list contains 31 screen modes, all screen modes only support a ScreenModeDepth of 32 bits. After changing the screen mode depth in the OpenScreen() function from 16 (unsupported by my graphics card) to 32, the example doesn't display the error message anymore.
Axolotl
Enthusiast
Enthusiast
Posts: 435
Joined: Wed Dec 31, 2008 3:36 pm

Re: Learn2Program PB outdated?

Post by Axolotl »

Hi TwoCatsYelling,

don't give up.

From my point of view you have the possibilities, which also depend on your previous knowledge:
a. try to run the examples in the current version of PB (you will learn a lot)
b. install the corresponding (old) version of PB*) and work through the examples, after success go to a. and repeat the steps.

If that sounds rude, I apologize. It's not meant that way.
Nobody said that learning programming is easy.
Good luck.

*) Is available for registered users, right?
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

Re: Learn2Program PB outdated?

Post by TwoCatsYelling »

Axolotl wrote:Hi TwoCatsYelling,

don't give up.

From my point of view you have the possibilities, which also depend on your previous knowledge:
a. try to run the examples in the current version of PB (you will learn a lot)
b. install the corresponding (old) version of PB*) and work through the examples, after success go to a. and repeat the steps.

If that sounds rude, I apologize. It's not meant that way.
Nobody said that learning programming is easy.
Good luck.

*) Is available for registered users, right?

Didn't seem rude at all :).
Though I don't know if I'd put outdated code in the "learning programming is hard" category, since it wouldn't work for anyone.

I'm just glad I decided to ask early on.
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

Re: Learn2Program PB outdated?

Post by TwoCatsYelling »

Rinzwind wrote:Change 16 to 32 (color depth) and it works. For some reason 16 bit color is unsupported? It changes display mode.. don't like it when example code uses that but ok.

Just compare with the help file Sprite.pb example . Would use OpenWindowedScreen btw.
Ah okay. Just that simple, then. I guess 16-bit is completely obsolete.

Thanks!
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Learn2Program PB outdated?

Post by TI-994A »

TwoCatsYelling wrote:...I guess 16-bit is completely obsolete.
It's not. It's the colour depth.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Axolotl
Enthusiast
Enthusiast
Posts: 435
Joined: Wed Dec 31, 2008 3:36 pm

Re: Learn2Program PB outdated?

Post by Axolotl »

TwoCatsYelling wrote:Though I don't know if I'd put outdated code in the "learning programming is hard" category, since it wouldn't work for anyone.

Well, I agree with you for absolute beginners, but if you already know how to program and want to learn a new language, old program codes are also suitable. Especially when the compiler shows the incorrect sections and you can correct them with the help of the help texts. In addition to the syntax, the most difficult thing about the new language is the (still) unknown functions, macros, procedures and so on.
But that's just my opinion, because it works so well for me.

Take care, happy coding and stay healthy.
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Learn2Program PB outdated?

Post by Mijikai »

Here is the 2D Sidescrolling Book for PB 5.0: http://mycodeserver.com/games_books/
There is also a great reference book on the latest PB 5.73 but only in german afaik.
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Learn2Program PB outdated?

Post by Keya »

Axolotl wrote:but if you already know how to program and want to learn a new language, old program codes are also suitable. Especially when the compiler shows the incorrect sections and you can correct them with the help of the help texts.
I don't think anybody who's learning a new language wants to spend their time debugging examples though ... :)
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Learn2Program PB outdated?

Post by normeus »

@TwoCatsYelling

Please take a look at blueznl's "PureBasic Survival Guide" it's a nice tutorial:

PureBasic Survival Guide

also download the PureBasic Book from purebasic.com, it's a must read:

PureBasic.pdf

lastly, don't forget to use google search to search for content in this forum:

Search PB Forum

Thank you.
Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
TwoCatsYelling
User
User
Posts: 20
Joined: Thu Mar 18, 2021 6:26 pm

Re: Learn2Program PB outdated?

Post by TwoCatsYelling »

Axolotl wrote:
TwoCatsYelling wrote:Though I don't know if I'd put outdated code in the "learning programming is hard" category, since it wouldn't work for anyone.

Well, I agree with you for absolute beginners, but if you already know how to program and want to learn a new language, old program codes are also suitable. Especially when the compiler shows the incorrect sections and you can correct them with the help of the help texts. In addition to the syntax, the most difficult thing about the new language is the (still) unknown functions, macros, procedures and so on.
But that's just my opinion, because it works so well for me.

Take care, happy coding and stay healthy.

Weird flex, but okay.

I am an absolute beginner, so everything past you acknowledging that wouldn't apply to me (yet). No?

I don't know if it was the intent, but the rest of your reply comes across like gloating because you know more than me/a new person.

It's like someone new at basketball explaining how they have a difficult time with half-court shots, and a veteran telling them "Yeah, I agree that would be difficult for a new player. I'm a veteran with thousands of hours played. I know how to calculate those shots, so I don't have that problem".

Again, that may not have been the intent, but it just seems kind of "braggy".
Last edited by TwoCatsYelling on Tue Mar 23, 2021 12:02 am, edited 2 times in total.
Post Reply