Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 49 50 [51] 52 53 ... 72

Author Topic: The Roguelike Development Megathread  (Read 245593 times)

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: The Roguelike Development Megathread
« Reply #750 on: October 15, 2012, 08:48:35 pm »

The biggest barrier to learning many skills is simply that there is no starting point or spring board anyway.

There are plenty and plenty of free tutorials on the internet. Hello World is a tranditional starting point in programming. Programming is a skill, and it does need to be practiced, however. I have seen quite a few people that think rote-learning function names and arguments is all they need to program effectively.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #751 on: October 15, 2012, 08:51:16 pm »

I've actually found Python's importing to be credibly easy.  Put it in the same folder and "import module" and then it's working!

On that note though, is there any particular way to making a new module?  I'm trying to define all my tiletypes into a separate document, but do I need to do anything special for Python to recognize it as a module or anything?

I will say this though - the vast majority of programming tutorials have been written by people who have decades of experience.  You can tell because they'll write a guide "C++ game design from scratch" and they start with, "First, import this.  Now, do this..." and the truly 'from scratch' people are like "Wait, how do you import?"  Most tutorials fail to come down to the bottom bottom superbottom base level knowledge - like opening IDLE and hitting 'ctrl-n' to start.  Most tutorials are like "now put this in and run it" and I'm like "put it where?!"

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: The Roguelike Development Megathread
« Reply #752 on: October 15, 2012, 09:07:24 pm »

I've actually found Python's importing to be credibly easy.  Put it in the same folder and "import module" and then it's working!

On that note though, is there any particular way to making a new module?  I'm trying to define all my tiletypes into a separate document, but do I need to do anything special for Python to recognize it as a module or anything?

I will say this though - the vast majority of programming tutorials have been written by people who have decades of experience.  You can tell because they'll write a guide "C++ game design from scratch" and they start with, "First, import this.  Now, do this..." and the truly 'from scratch' people are like "Wait, how do you import?"  Most tutorials fail to come down to the bottom bottom superbottom base level knowledge - like opening IDLE and hitting 'ctrl-n' to start.  Most tutorials are like "now put this in and run it" and I'm like "put it where?!"

If you have something like "tiles.py", you can just

Quote
import tiles

If you want to have a folder full of files and import that, then you need to give the folder a __init__.py file. When you import the folder name, you will actually be importing that file.

If you had a folder called tiles, with files rock.py, tree.py etc, you could write your __init__.py to be something like

Code: (__init__.py) [Select]
import rock
import tree

Then when you imported the folder tiles like this

Code: (A py file outside of the tiles folder) [Select]
import tiles

you can use it like

Code: [Select]
tiles.rock.some_function_or_class_in_rock_py()

There is one thing to be careful of when using Python's import. If module A imports B and B imports A, then I find that all sorts of strange things start happening.

I agree with what you say about tutorials. Most C++ tutorials give you
Quote
include <iostream>
using namespace std;
int main(int argc, char** argv){
    cout << "Hello World" << endl;
}

And just leave you with questions like "what is iostream", "What to the <> mean", "what is using namespace std; mean" "what is argc/argv" etc etc. This is why I think something like Python is much nicer to start of with, since

Code: [Select]
print("Hello World")

is much less overwhelming. And being overwhelmed is a large demotivator.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #753 on: October 15, 2012, 09:14:40 pm »

Yeah, I'll try not to have self-including modules.  So then the only question is, how do I define multiple types of tiles that are all of the same class?  Like, if I want 'tree' and 'grass' and 'dirt' to all be of the same "class Tile:" how would I nest them in with pre-defined values for each?

Neonivek

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #754 on: October 15, 2012, 09:39:57 pm »

The biggest barrier to learning many skills is simply that there is no starting point or spring board anyway.

There are plenty and plenty of free tutorials on the internet. Hello World is a tranditional starting point in programming. Programming is a skill, and it does need to be practiced, however. I have seen quite a few people that think rote-learning function names and arguments is all they need to program effectively.

I'll keep at it.

Right now I am trying to pixil art for the games I keep trying to hopelessly make :P
Logged

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #755 on: October 15, 2012, 10:22:28 pm »

A new issue arises!  How do I print unicode in a Python terminal?  It doesn't like trying to handle 3 bytes of data when it expects 1.

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: The Roguelike Development Megathread
« Reply #756 on: October 15, 2012, 10:38:49 pm »

Yeah, I'll try not to have self-including modules.  So then the only question is, how do I define multiple types of tiles that are all of the same class?  Like, if I want 'tree' and 'grass' and 'dirt' to all be of the same "class Tile:" how would I nest them in with pre-defined values for each?

You would have a Tile base class, and inherit it

Code: (tile.py) [Select]
class Tile:
    tile = '^'
    isSolid = False
    # Add some more variables/functions here if required, that is all tiles require

Code: (tree.py) [Select]
import tile
class Tree(tile.Tile):
    tile = '*"  # Whatever you want your tree tile to be
    isSolid = True
    # Addsome more variables/functions here that either override Tile's things (For example the 2 variables above), or is unique to a Tree tile.


A new issue arises!  How do I print unicode in a Python terminal?  It doesn't like trying to handle 3 bytes of data when it expects 1.

According to this do something like

Code: [Select]
MyUnicodeString = MyString.encode("iso-8859-1")
print(MyUnicodeString)


Right now I am trying to pixil art for the games I keep trying to hopelessly make :P

I am also trying to teach myself pixel art. I am failing quite badly at it too. It's much more fustrating than programming, since programming you eventually solve a problem. But pixel art, its always just never looking right. LOOK RIGHT, DAMNIT! *Gives up*.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #757 on: October 15, 2012, 10:43:52 pm »

1: I've decided it's easier to define each tile as a different class with the same name of variables.
2: Turns out libtcod doesn't play nice with unicode, so it's a no-go. 

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: The Roguelike Development Megathread
« Reply #758 on: October 15, 2012, 10:49:59 pm »

libtcod's basic print functions use ascii as far as I know as default. To use unicode, I believe you have to override libtcod's usual font via a new unicode image for its custom font importer, and then map all the new characters using its font mapping functions. It MIGHT work at that point, but you might have to create your own custom print function. It's been a long while since I tried.
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: The Roguelike Development Megathread
« Reply #759 on: October 15, 2012, 11:00:48 pm »

1: I've decided it's easier to define each tile as a different class with the same name of variables.

For very simple classes this is okay (but it's only really reasonably doable in duck-typed languages like Python. It is not really doable in most OO languages eg C#, Java etc). But for more complex classes, this is bad design. OO people will punch you for doing this.
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #760 on: October 16, 2012, 10:09:17 pm »

I've hit a snag.  The main game file imports libtcod for things.  I've decided to put tile types in a separate file for readability.  The "tiles" file also imports libtcod, because it needs to handle the colors.  But, when I try to run the main file, it claims that tiles hasn't imported libtcod.  Or rather, the first place it calls a function from libtcod it claims that it's not a global variable.  Am I missing something obvious?

da dwarf lord

  • Bay Watcher
    • View Profile
Re: The Roguelike Development Megathread
« Reply #761 on: October 16, 2012, 11:07:28 pm »

I've hit a snag.  The main game file imports libtcod for things.  I've decided to put tile types in a separate file for readability.  The "tiles" file also imports libtcod, because it needs to handle the colors.  But, when I try to run the main file, it claims that tiles hasn't imported libtcod.  Or rather, the first place it calls a function from libtcod it claims that it's not a global variable.  Am I missing something obvious?

Could you post each file? Because it sounds like it could be several things, each hard to explain.
Logged

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #762 on: October 16, 2012, 11:14:43 pm »

Code: [Select]
Traceback (most recent call last):
  File "C:\Users\E\Desktop\Pyhton\Testy\testy", line 175, in <module>
    make_map()
  File "C:\Users\E\Desktop\Pyhton\Testy\testy", line 56, in make_map
    for x in range(MAP_WIDTH)]
  File "C:\Users\E\Desktop\Pyhton\Testy\tiles.py", line 8, in __init__
    self.lit_color=libtcod.light_green
NameError: global name 'libtcod' is not defined
The error in question... and... main file along with tiles file.  All the relevant files are in the same folder, it shouldn't be a directory issue.

SethCreiyd

  • Bay Watcher
  • [VESPERTINE]
    • View Profile
Re: The Roguelike Development Megathread
« Reply #763 on: October 17, 2012, 02:33:49 am »

Code: [Select]
Traceback (most recent call last):
  File "C:\Users\E\Desktop\Pyhton\Testy\testy", line 175, in <module>
    make_map()
  File "C:\Users\E\Desktop\Pyhton\Testy\testy", line 56, in make_map
    for x in range(MAP_WIDTH)]
  File "C:\Users\E\Desktop\Pyhton\Testy\tiles.py", line 8, in __init__
    self.lit_color=libtcod.light_green
NameError: global name 'libtcod' is not defined
The error in question... and... main file along with tiles file.  All the relevant files are in the same folder, it shouldn't be a directory issue.

If tiles.py tried and was unable to import libtcod, it would give you an ImportError instead of a NameError, something like this:

Code: [Select]
Traceback (most recent call last):
  File "C:/Python26/test.py", line 1, in <module>
    import tiles
  File "C:/Python26\tiles.py", line 1, in <module>
    import libtcodpy as libtcod
ImportError: No module named libtcodpy

The NameError means that the indicated variable doesn't exist in the current namespace, and suggests that the import statement either has a typo, or it is missing.

However, the two scripts you uploaded seem to run without a problem, so I'm guessing at a discrepancy somewhere.
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: The Roguelike Development Megathread
« Reply #764 on: October 17, 2012, 03:23:09 am »

It runs just fine for me. Weird. What version of Python are you running?

All I can think of is try flipping the first files import lines from
Code: [Select]
import tiles
import libtcodpy as libtcod

to

Code: [Select]
import libtcodpy as libtcod
import tiles

EDIT: General advice:

Be cautious about how you tab your code. your "keypress()" function is tabbed differently to the rest of the program. Python generally does not like that.

Also, I don't know about using map as a variable, since it is the name of a builtin function.
« Last Edit: October 17, 2012, 03:32:25 am by alexandertnt »
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!
Pages: 1 ... 49 50 [51] 52 53 ... 72