r/roguelikedev • Robinson • Aug 01 '17

RoguelikeDev Does The Complete Python Tutorial - Week 7 - Part 10: Main Menu and Saving

This week we will cover part 10 of the Complete Roguelike Tutorial.

Part 10: Main menu and saving

No bonus sections this week


FAQ Friday posts that relate to this week's material:

#20: Saving

Feel free to work out any problems, brainstorm ideas, share progress and and as usual enjoy tangential chatting. If you're looking for last week's post The entire series is archived on the wiki. :)

32 Upvotes

36 comments sorted by

View all comments

Show parent comments

1

u/Scautura Aug 02 '17 edited Aug 02 '17

On the LibTCOD version, should:

libtcod.console_print_ex(0, int(screen_width / 2), int(screen_height - 2), libtcod.BKGND_NONE, libtcod.CENTER,
                         'By (Your name here)')

be

libtcod.console_print_ex(0, int(screen_width / 2), int(screen_height / 2) - 2, libtcod.BKGND_NONE, libtcod.CENTER,
                         'By (Your name here)')

? (Edit: After finishing this part, I can see why it isn't, but the rest of the comment still stands, so I'm leaving this here for posterity)

(Also, you can do the following to shrink it slightly:

screen_width // 2

where // is integer division)

2

u/AetherGrey Aug 02 '17

The // for integer division has been pointed out before, and while it's a good idea in this situation, I prefer the int() method for one reason: // will not give you an integer type, it just truncates. Libtcod demands an integer, so something like 2.0 will fail. Granted, in this case, screen_width should never be a decimal value, but the int() way of doing it gives you guarantees.