What to do now?

Started by
17 comments, last by Anri 7 years, 5 months ago

Assuming that nothing happens until the user has entered some input, your game is a 'while' loop with an 'input' statement and code to process that input.

Usually, you also want to print something before asking the next input, so the user knows what happened too.

You could try hangman as first text-based game, as there is very little processing to do there.

As for best way to write code, the opinions vary :) In fact, as you get more experienced you'll find new and better ways to express the same thing. Thus even the same person changes opinion over time.

In my experience, the best strategy is to start small, and slowly make it bigger. When you realize things get too large, or cannot be handled easily, stop adding and think of a better solution. Likely this will happen a few times before you get it right (and this is normal, I have programmed for 30 years, and still have this problem), but every time you find it went wrong, you learn a little so you can avoid the same mistake the next time.

As for fixing, you can either fix the code that you have at that point in time, or you can go back to an earlier version (if you have that), or you can start from scratch again. Every option has different advantages and disadvantages, as you'll find out.

Last but not least, let others read your code (the technical term is "code review" although that is a bit more formal), and read code of others. While it is scary at first, and getting comments on your work may feel awkward, it is generally given in positive spirit, as points where you can improve.

The more important part however is the explanation how to improve those points. That's the real gold, knowledge how to get better real quickly.

You can ask for a code review right here, just post the code (use the "<>" symbol for the code, as that makes it look good). You can also post code fragments that way if you have a question about some particular part.

@Anri: Python does not have a "switch" statement, you code it as a "if ..: ... elif .. : ... elif ... : ... else: ..." sequence.

Does it not have a switch statement? OMG, thats a nightmare! :blink:

Quite surprised at that, Alberth. Any idea as to why its not got a switch?

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

Advertisement

Assuming that nothing happens until the user has entered some input, your game is a 'while' loop with an 'input' statement and code to process that input.

Usually, you also want to print something before asking the next input, so the user knows what happened too.

You could try hangman as first text-based game, as there is very little processing to do there.

As for best way to write code, the opinions vary :) In fact, as you get more experienced you'll find new and better ways to express the same thing. Thus even the same person changes opinion over time.

In my experience, the best strategy is to start small, and slowly make it bigger. When you realize things get too large, or cannot be handled easily, stop adding and think of a better solution. Likely this will happen a few times before you get it right (and this is normal, I have programmed for 30 years, and still have this problem), but every time you find it went wrong, you learn a little so you can avoid the same mistake the next time.

As for fixing, you can either fix the code that you have at that point in time, or you can go back to an earlier version (if you have that), or you can start from scratch again. Every option has different advantages and disadvantages, as you'll find out.

Last but not least, let others read your code (the technical term is "code review" although that is a bit more formal), and read code of others. While it is scary at first, and getting comments on your work may feel awkward, it is generally given in positive spirit, as points where you can improve.

The more important part however is the explanation how to improve those points. That's the real gold, knowledge how to get better real quickly.

You can ask for a code review right here, just post the code (use the "<>" symbol for the code, as that makes it look good). You can also post code fragments that way if you have a question about some particular part.

@Anri: Python does not have a "switch" statement, you code it as a "if ..: ... elif .. : ... elif ... : ... else: ..." sequence.

GabrielJim, my copy is the third edition(2010), and covers Python 3.1.1.

You should be alright.

Thank you both, a lot, i really appreciate the help

Alberth, about the code review, do threads in Gamedev get deleted? If they do, where should i post the code review? Because if they don't i think it'd be a good idea to post it right here as i progress.

Anri, is this one the book you have?

http://kvspgtcs.org/wp-content/uploads/2013/08/Python-Programming-for-the-Absolute-Beginner.pdf

I'm sorry about not buying it, i'm not from USA, so my dollar situation it's not really great, but i'm gonna read it from there anyways (if it's the one you're talking about).

Quite surprised at that, Alberth. Any idea as to why its not got a switch?
Not exactly sure why, but it may have to do with the break versus fall-through, or with the double cases with the same value (CPython doesn't check beforehand, it;s all interpreted at runtime.)

It is possible to make a dispatch dictionary which emulates a switch, like


def f1():
    print("hello")

def f2():
    print("world")

d = { 'a': f1, 'b': f2 }
d['a']() # prints "hello"

You almost never see these however. In my experience, switches aren't that often needed, at least I don't really miss them in Python. Perhaps dicts and lists make up for it for a large part, ie it is trivial to store key/value pairs in a dictionary, like 'd' above. You'd use a switch for such things in other languages.

Alberth, about the code review, do threads in Gamedev get deleted? If they do, where should i post the code review? Because if they don't i think it'd be a good idea to post it right here as i progress.

Threads don't get deleted. As code gets larger, posting may become more problematic, but way before that people will not read your code any more.

A program like hangman is 50-100 lines or so, which is fine. Posts longer than about 500 lines have very little use. People read the forum, and do a code review in 5-10 minutes. That won't work with long code. 100 lines of say 40 characters / line, is a 4KB, you won't make a noticable impact on what everybody here posts, or at todays disk sizes (smallest is around 1TB! I have no idea how people manage to fill even that "small" amount of storage!)

Some people open a repository at a site like github or bitbucket for their code.

GabrielJim, thats the book, but a 2003 edition, using Python 2.2.3.

I'd say you'll find some differences between that version and Python 3, but just roll with it and look up what the Python 3 solution is through google searches. In other words, dont worry about it. I tried my hand at some Python 2.7(?) for Raspian(for the Raspberry Pi) a while ago, and came across some minor differences such as how I used the print() function.


Quite surprised at that, Alberth. Any idea as to why its not got a switch?
Not exactly sure why, but it may have to do with the break versus fall-through, or with the double cases with the same value (CPython doesn't check beforehand, it;s all interpreted at runtime.)

It is possible to make a dispatch dictionary which emulates a switch, like


def f1():
    print("hello")

def f2():
    print("world")

d = { 'a': f1, 'b': f2 }
d['a']() # prints "hello"

You almost never see these however. In my experience, switches aren't that often needed, at least I don't really miss them in Python. Perhaps dicts and lists make up for it for a large part, ie it is trivial to store key/value pairs in a dictionary, like 'd' above. You'd use a switch for such things in other languages.

Alberth, about the code review, do threads in Gamedev get deleted? If they do, where should i post the code review? Because if they don't i think it'd be a good idea to post it right here as i progress.

Threads don't get deleted. As code gets larger, posting may become more problematic, but way before that people will not read your code any more.

A program like hangman is 50-100 lines or so, which is fine. Posts longer than about 500 lines have very little use. People read the forum, and do a code review in 5-10 minutes. That won't work with long code. 100 lines of say 40 characters / line, is a 4KB, you won't make a noticable impact on what everybody here posts, or at todays disk sizes (smallest is around 1TB! I have no idea how people manage to fill even that "small" amount of storage!)

Some people open a repository at a site like github or bitbucket for their code.

Alberth, cheers for that! I'll definitely keep that in mind should I return to Python. :cool:

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

Python 2.2 is a LOT different from 2.7

Around Python 2.4, they started working on Python3, and at around 2.5, Python 3 was ready enough to push the switch from 2 to 3 to the general public. Versions 2.6 and 2.7 make a lot of changes to get the 2 and 3 versions closer together, easing the transition.

Python 2.2 is a LOT different from 2.7

Around Python 2.4, they started working on Python3, and at around 2.5, Python 3 was ready enough to push the switch from 2 to 3 to the general public. Versions 2.6 and 2.7 make a lot of changes to get the 2 and 3 versions closer together, easing the transition.

Uh, that's a real shame, the book seems pretty good, and i can't find the 2010 version.

But oh well.

GabrielJim, you can download the 3rd edition source code from this page...

http://www.delmarlearning.com/companions/content/1435455002/downloads/index.asp?isbn=1435455002

...just click on "book source code". Inside the zip file, navigate as follows...

\py3e_source\py3e_source\

...and you will find a list of chapter folders.

Use the pdf for now and the source code to overcome any problems. If you are already learning Python 3 from another source then you should be alright.

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

GabrielJim, you can download the 3rd edition source code from this page...

http://www.delmarlearning.com/companions/content/1435455002/downloads/index.asp?isbn=1435455002

...just click on "book source code". Inside the zip file, navigate as follows...

\py3e_source\py3e_source\

...and you will find a list of chapter folders.

Use the pdf for now and the source code to overcome any problems. If you are already learning Python 3 from another source then you should be alright.


Oh, I didn't think of this, thanks! Appreciate the help

You are welcome, GabrielJim.

Have fun! ^_^

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

This topic is closed to new replies.

Advertisement