Author Topic: newbie asking for help  (Read 21943 times)

jofadda

  • Newcomer
  • Posts: 38
  • Karma: +0/-0
    • View Profile
newbie asking for help
« on: October 01, 2011, 06:34:46 AM »
i want to create a roguelike as i have a few ideas for one(and a complete theoreticall "near freeform" spell system for said roguelike), i decided on using python and libtcod and as i have no programming skills, i am using this tutorial
http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod but this tutorial doesnt seem explanitory enough, and it just makes me feel like im copying and pasting code, is there a better tutorial, or could someone explain some of the lines of code, and what they do in more detail,
im just in the first part, just finished character movement, but an explaination from start would be better, thanks in advance for either a better tutorial, or a better explination of this one

RogueMaster

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Re: newbie asking for help
« Reply #1 on: October 01, 2011, 08:04:39 AM »
i want to create a roguelike as i have a few ideas for one(and a complete theoreticall "near freeform" spell system for said roguelike), i decided on using python and libtcod and as i have no programming skills, i am using this tutorial
http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod but this tutorial doesnt seem explanitory enough, and it just makes me feel like im copying and pasting code, is there a better tutorial, or could someone explain some of the lines of code, and what they do in more detail,
im just in the first part, just finished character movement, but an explaination from start would be better, thanks in advance for either a better tutorial, or a better explination of this one


Something that may help you:
http://roguebasin.roguelikedevelopment.org/index.php/How_to_Write_a_Roguelike_in_15_Steps

jofadda

  • Newcomer
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: newbie asking for help
« Reply #2 on: October 01, 2011, 08:22:03 AM »
sorry, that didnt help, i have almost no coding knowledge, i was hoping for more of an explanitory coding tutorial

RogueMaster

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Re: newbie asking for help
« Reply #3 on: October 01, 2011, 05:57:29 PM »
sorry, that didnt help, i have almost no coding knowledge, i was hoping for more of an explanitory coding tutorial

Then what you need is to do is to read a beginner tutorial of the programming language you want to use.

For python, you can find various manuals here: http://www.awaretek.com/tutorials.html

Enjoy.

jofadda

  • Newcomer
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: newbie asking for help
« Reply #4 on: October 01, 2011, 11:16:04 PM »
ok, im currently reading python for dummies, and, i was really hoping for code explination of the tutorial, rather than python tutorials, thanks anyway

jofadda

  • Newcomer
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: newbie asking for help
« Reply #5 on: October 02, 2011, 12:54:01 AM »
http://www.mediafire.com/?i2aqh3cohp6fj99
this is what ive got so far, currently im just messing around with the tutorial i mentioned earlier, but i seem to have an error to do with movement that i cant find within the code, could someone please find said error, tell me what it is, what ive done wrong, and what i should have done?
thanks in advance, and sorry for the double post

TheExpert

  • Newcomer
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Email
Re: newbie asking for help
« Reply #6 on: October 02, 2011, 01:23:38 AM »
line 85 of your code.

Code: [Select]
libtcod.console_print_left(0, playerx, playery, libtcod.BKGND_NONE, ' ')
should be

Code: [Select]
libtcod.console_print_left(0, player.x, player.y, libtcod.BKGND_NONE, ' ')
you left out the period between player.x and player.y, so instead of looking at the the x and y attributes of the Object Instance known as 'player', the program was looking for variables named playerx and playery, variables that don't exist. Since those variables don't exist, the program crashes when it is told to use them.

jofadda

  • Newcomer
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: newbie asking for help
« Reply #7 on: October 02, 2011, 05:03:48 AM »
ok, thanks, you probly think its a really noobie mistake, ::) but that helps me alot
also another one here,
where is the error in this?


import libtcodpy as libtcod


SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50

MAP_WIDTH = 80
MAP_HEIGHT = 45

color_dark_wall = libtcod.Color(0, 0, 100)
color_dark_ground = libtcod.Color(50, 50, 150)


class Tile:
    #a tile of the map and its properties
    def __init__(self, blocked, block_sight = None):
        self.blocked = blocked
 
        #by default, if a tile is blocked, it also blocks sight
        if block_sight is None: block_sight = blocked
        self.block_sight = block_sight

class Object:
    #this is a generic object: the player, a monster, an item, the stairs...
    #it's always represented by a character on screen.
    def __init__(self, x, y, char, color):
        self.x = x
        self.y = y
        self.char = char
        self.color = color
 
    def move(self, dx, dy):
        if not map[self.x + dx][self.y + dy].blocked:
        self.x += dx
        self.y += dy
 
    def draw(self):
        libtcod.console_set_foreground_color(con, self.color)
        libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
 
    def clear(self):
        libtcod.console_put_char(con, self.x, self.y, ' ', libtcod.BKGND_NONE)

def make_map():
    global map
 
    #fill map with "unblocked" tiles
    map = [[ Tile(False)
        for y in range(MAP_HEIGHT) ]
            for x in range(MAP_WIDTH) ]

    map[30][22].blocked = True
    map[30][22].block_sight = True
    map[50][22].blocked = True
    map[50][22].block_sight = True

def render_all():
    global color_light_wall
    global color_light_ground

    #go through all tiles, and set their background color
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            wall = map
  • [y].block_sight

            if wall:
                libtcod.console_set_back(con, x, y, color_dark_wall, libtcod.BKGND_SET )
            else:
                libtcod.console_set_back(con, x, y, color_dark_ground, libtcod.BKGND_SET )


    #draw all objects in the list
    for object in objects:
        object.draw()

    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

def handle_keys():
    key = libtcod.console_wait_for_keypress(True)  #turn-based
 
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
 
    elif key.vk == libtcod.KEY_ESCAPE:
        return True  #exit game
 
    #movement keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        player.move(0, -1)
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        player.move(0, 1)
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        player.move(-1, 0)
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        player.move(1, 0)

 
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'test', False)
con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)


player = Object(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, '@', libtcod.white)
 

npc = Object(SCREEN_WIDTH/2 - 5, SCREEN_HEIGHT/2, '@', libtcod.yellow)
 

objects = [npc, player]

make_map()

 
while not libtcod.console_is_window_closed():

    #render the screen
    render_all()

    libtcod.console_flush()

    #erase all objects at their old locations, before they move
    for object in objects:
        object.clear()

 
    #handle keys and exit game if needed
    exit = handle_keys()
    libtcod.console_print_left(0, player.x, player.y, libtcod.BKGND_NONE, ' ')
    if exit:
        break
« Last Edit: October 02, 2011, 06:38:18 AM by jofadda »

guest509

  • Guest
Re: newbie asking for help
« Reply #8 on: October 02, 2011, 09:16:39 AM »
  Wow man what's the error message? What's the behavior problem? I have never used this language before but these 2 locations look wacky.
 
for x in range(MAP_WIDTH):
            wall = map

    [y].block_sight      //there is a weird dot at the beginning of this line.

AND HERE

libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
  //That '|' symbol seems a bit out of place...

  Sorry I cannot be of more help. But I tell you man. If you want to write in python you need to know what the code is saying. You don't have to be an expert. But a few weeks hitting a python tutorial will do you wonders. You need to know what a programming language is to be able to even edit someone else's code.
  Many many people write a Roguelike as a way to learn a language. I highly recommend it.

guest509

  • Guest
Re: newbie asking for help
« Reply #9 on: October 02, 2011, 09:27:22 AM »
  Crap please ignore the '|' suggestion. I went through the python code you are copying and they are using it as an operator there. Unless it is also an error there. I dunno.
  As far as explaining the code. The guy is doing a pretty good job in that tutorial. I don't know how I could explain it better without starting from the beginning and telling you how programming languages work. And there are PLENTY of better resources than me for that. I don't even know python.

jofadda

  • Newcomer
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: newbie asking for help
« Reply #10 on: October 02, 2011, 09:43:18 AM »
  Wow man what's the error message? What's the behavior problem? I have never used this language before but these 2 locations look wacky.
 
for x in range(MAP_WIDTH):
            wall = map

    [y].block_sight      //there is a weird dot at the beginning of this line.

AND HERE

libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
  //That '|' symbol seems a bit out of place...

  Sorry I cannot be of more help. But I tell you man. If you want to write in python you need to know what the code is saying. You don't have to be an expert. But a few weeks hitting a python tutorial will do you wonders. You need to know what a programming language is to be able to even edit someone else's code.
  Many many people write a Roguelike as a way to learn a language. I highly recommend it.
the wierd dot is an x within square brackets [] and i still have not found the error

7h30n

  • Newcomer
  • Posts: 33
  • Karma: +0/-0
    • View Profile
Re: newbie asking for help
« Reply #11 on: October 02, 2011, 09:47:28 AM »
In render_all function:

Code: [Select]
   for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            wall = map[x][y].block_sight

Shouldn't it be like that (though I haven't started on Python yet...)?

Edit: Nvm, it seems the forum displays a dot when you have [letter] [letter] without spaces in between them.
Current project: Into the Dungeon++

jofadda

  • Newcomer
  • Posts: 38
  • Karma: +0/-0
    • View Profile
Re: newbie asking for help
« Reply #12 on: October 02, 2011, 09:54:04 AM »
also if this helps, when i exicute the code, i get no error, it just opens a  command line with no text, then closes

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: newbie asking for help
« Reply #13 on: October 02, 2011, 01:24:04 PM »
is there a better tutorial

Yeah, it's called "learn programming". That's the tutorial you want to do first.

guest509

  • Guest
Re: newbie asking for help
« Reply #14 on: October 03, 2011, 08:17:59 AM »
is there a better tutorial

Yeah, it's called "learn programming". That's the tutorial you want to do first.

  Agreed. Even if you are using a drag and drop program like Gamemaker or RPG Maker you'll want to learn the scripting languages. You'll not need to get advanced. Basic stuff cannot be avoided though.
  When I was learning I really liked the 'Learn to Use XYZ in 21 Days' line of books. Quick and dirty.