Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Problem w/ Assigning Variables another Variable when Initializing them

Author
Message
danctodd
14
Years of Service
User Offline
Joined: 31st Jul 2010
Location:
Posted: 1st Aug 2010 12:28
First off, sorry if this has been asked. Did the routine search, but it's 3:30 am in the morning, so I might be a little dazed.

I bought the DarkBasic Pro Game Programming 2nd Edition by Jonathan Harbour awhile back. I know it's dated but figured it'd help. Also, it was 5 bucks at a yard sale(who couldn't say no to that).

The material is great, but I've noticed a problem early into the book.

He mentions you must initialize a variable on a separate line before you can assign another variable to it. I tried it to check and it worked just the same. Is there another reason to not do it or am I safe doing something like:
aName as string = "Daniel"
name as string = aName
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Aug 2010 15:02
The rules have changed slightly over time, so lines like that are normally OK - you can't use functions, but you can use constant values and variables (I haven't found any exceptions to that, but do test each time).

One other limitation is that the flow of execution has to run through the line of code.

For instance, this won't work:


but this will:


Basically, variables are created during the compilation of your code, and their type is set in stone at that point, but values aren't assigned until they are executed at runtime.

danctodd
14
Years of Service
User Offline
Joined: 31st Jul 2010
Location:
Posted: 1st Aug 2010 15:18
Thanks for the help again. Explained that pretty well

I'm thinking of abandoning this book. A lot of the code doesn't seem to work right. The example pong program has a chaotic ball in the middle of the screen(shakes a lot and slowly heads to the bottom of the screen) and the pong paddles move at a extremely slow pace. I'm sure that could be fixed easily but that isn't the only problem.
The function to make a circle on the screen

I'm sure some of this could be changed pretty easily but I'm new and it seems highly confusing to me. And when I briefly worked with C++, one of the authors I was reading mentioned you should not start out on bad habits. Learning from a dated book might be one of those.

Any insight onto what I should do? Like, what would help me the most to understand and work with this language because I've been having a really hard time getting into all of this. Like any tricks to memorizing commands, tips to understanding, books to read to relate even in the closest sense to how to work with this?

Sorry, I'm a little frustrated and stressed right now so I'm writing an awful lot.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Aug 2010 16:53
I haven't read the book or any of the free PDF chapter/previews, so I can't comment on the book directly.

However, I can comment on that piece of code, and I will tell you that looping almost 21,000 times on a circle of less than 21,000 pixels in diameter is wasteful in the extreme. Hopefully that isn't a standard followed in the rest of the book.

Anyhow, to try and answer your question...

You'll find that almost everyone has habits that others don't like (and this is all MY opinion, which doesn't mean I'm right or they are wrong!):
- Zaibatsu has written a fairly easy to follow game tutorial (see the tutorial thread), but he types all keywords in uppercase, and doesn't indent.
- Pluto's text adventure tutorial is entirely built of global variables.
- Then there's Mr Kohlenstoff's 'Jump 'n' Run Game' tutorial, whose style is like mine and is fairly easy to read and understand (IMO, naturally).

I'd suggest you read a lot of the tutorials, especially the game tutorials, no matter how good/bad/indifferent they are. At best, you might see a style you like, and at worse, you'll know what styles you don't like and can avoid them.

Or you may come up with a combination of your own that you find most readable, and that's the most important thing - it's you that has to read your code.

danctodd
14
Years of Service
User Offline
Joined: 31st Jul 2010
Location:
Posted: 1st Aug 2010 17:17
I like your style to be honest. Looks like the style used in many c programming books I tried to do the capitals thing and it just seems to slow me down. I also wanted to learn with the intellisense but it seems bugged and will try throwing me a word totally different from what I am typing.

I'll look into those tutorials and try picking at others like you suggested.

Login to post a reply

Server time is: 2024-11-16 16:05:41
Your offset time is: 2024-11-16 16:05:41