Sign in to follow this  
sharpe

Seeking Beginner Advice for Text-Only Dungeon Game in C# and Python

Recommended Posts

Greetings and thanks for taking the time to read my first post here on GameDev.net.

Straight to the point: I'm 30 years old and have no programming experience other than basic HTML in notepad back in the late-90's, early-2000's. I'm seeking to make a [url="http://en.wikipedia.org/wiki/Roguelike"]Rogue-like[/url] single player dungeon exploration game. I'm much less concerned about implementing 2D graphics than I am about making my own turn-based combat engine and random dungeon room generator. The first version of the game could be text-only or ASCII.

I've ran part way through one [url="http://learn-to-program.net/index.html"]online tutorial[/url] for Python and have enjoyed the experience so far.

In reply to the question posed in the FAQ: "[Do] you want to [i]make games[/i] or [i]learn to program,[/i]" the answer is that I want to learn to program. I thoroughly enjoyed programming in either C++, C, or C# -- whatever programming class it was that I took in school some 10 years ago and never used again -- just as I enjoyed coding basic Web pages back in the day. I don't recall [i]anything [/i]I learned from the class other than that I couldn't stand re-making the same business/accounting programs again that we made in all the other languages, such as Visual Basic. Instead, I used the text book to help me figure out how to use the random number generator to make a gladiator-like text-only game. Once I started going off in my own direction, the class became excruciatingly tedious in its slow pace and focus on repetition.

Now, I didn't come lightly to the conclusion that I wanted to program rather than just make games. Some time ago, I started making simple games with RPG Maker VX, which is a front end for a form of Ruby. Long story short, I felt confined by it. I didn't want to learn Ruby just to make games with RPG Maker. Instead, I decided I wanted to learn to program using a language that would support my designs in the long term. So, I chose Python.

To be honest, though, I actually am the type of person who rarely finishes what he starts. I have a short attention span. I'm not very intelligent and math is my weakest subject. I'm unmotivated and I procrastinate. I am more of the creative type, which, as I understand it, is the opposite of the type who do well at programming.

But, I digress.

Programming is fun, in my opinion, so even if I quit before finishing a full-fledged game -- as I probably will -- I'll have fun while I learn and work on my project.

Enough about boring ol' me and on to my request for advice.

So far, after a quick [url="http://forums.devarticles.com/general-programming-help-4/random-number-generator-in-python-57735.html"]Google search[/url], I learned that the following code will allow my game to generate random numbers in Python 2.7.2:

[code]from random import randint
a = randint (0,0)[/code]

So, with that knowledge in mind, I made my first "game" (please don't laugh):

[code]loop = 1

while loop != 0:
print "Guess a number between 1 and 10 or guess 0 to end program."

number = input()

from random import randint
target = randint (1,10)

if number <= 0:
print "End of line."
loop = 0
break

if number == target:
print "You guessed correctly!"

else:
print "You guessed wrong. The correct number was", target[/code]

Even as simple as that is, I'm sure it's full of problems or aspects that that can be improved.

I've not yet learned anything about functions or classes; I made it half way through the Loop section of the [url="http://learn-to-program.net/loops.htm"]tutorial[/url] I'm following.

After I make it through the tutorial, I would like to learn:

[list=1][*]How to go about the process of making a save file for a game;[*]How to make my game in Python, but save it so that it can be played on a Windows-based PC;[*]How I should go about structuring a simple text-only dungeon game with monsters and rooms and treasure;[*]How I should go about coding a Rogue-like random dungeon room generator.[/list]
To save my little game above, I tried using [url="http://www.py2exe.org/"]py2exe[/url] but my understanding of Python isn't great enough yet to be able to follow the [url="http://logix4u.net/Python/Tutorials/How_to_create_Windows_executable_exe_from_Python_script.html"]instructions[/url]. This is the part I had trouble with:

[quote]Importing setup and py2exe to setup.py and call setup() function with the name of entry point script as argument. Now it is time to run the script and create the executable. To build the executable, run "python setup.py py2exe" on the command prompt. You can see lots of output on the console. In the end you can see the output as in the picture below. [/quote]

As I didn't try very hard, I'll probably figure it out myself. For that matter, I've not searched for an answer to my first question either, and the third and fourth are too advanced for me to tackle right now.

However, for the random dungeon generation, for now, I'm considering a text-only game where the size of the room isn't important; it's abstract.

Instead, I am considering a five-by-five-room (or larger) dungeon grid something like this:

[code] -- -- -- -- --
| 1| 2| 2| 2| 3|
-- -- -- -- --
| 4| 5| 5| 5| 6|
-- -- -- -- --
| 4| 5| 5| 5| 6|
-- -- -- -- --
| 4| 5| 5| 5| 6|
-- -- -- -- --
| 7| 8| 8| 8| 9|
-- -- -- -- --

1 = May have doors going right and down.
2 = May have doors going left, down, right.
3 = May have doors going left and down.
4 = May have doors going up, right, and down.
5 = May have doors going in all directions.
6 = May have doors going up, left, and down.
7 = May have doors going up and right.
8 = May have doors going left, up, and right.
9 = May have doors going left and up.[/code]

Not all of the rooms should to be accessible, but there must be a path from the entrance to the exit. I guess I should have the game first decide how many rooms there are, then what the path of doors is from the entrance to the exit (up, left, left, left, down, etc), and lastly have it branch off any other possible rooms from existing rooms with doors. I dunno.

After the game decides where the entrance and exits are and what rooms exist, it populates the rooms with doors, monsters, treasure, traps, etc.

I have a long and detailed plan for the game, but here is neither the time nor the place...


Well, thanks again for taking the time to read this. It was really more of an introduction post than a search for advice or answers, but if you feel like giving a complete newbie some help, know that it will be appreciated!

-Sharpe

Share this post


Link to post
Share on other sites
Python is superb for game development, particular for games that don't require precision timing (for that you need to go the C route).

I am myself creating a graphical RPG game at the moment and finding development in Python so fast, it's a bit scary.

My advice would be to learn the data structures in Python: lists, tuples, sets and also dictionaries. These are SO useful in game programming. Also learn a bit of OOP concepts, how to create classes and inherit from classes etc. Learn the scope of variables because this can be a little tricky for those coming from statically typed programming backgrounds. Python is strongly typed, though, so you shouldn't face the issue of accidental implicit data-type conversions which might lead to weird bugs.

Another specific bit of advice: avoid [code] from ... import ....[/code] because this can lead to inadverdant namespace pollution. Python recommends always import ....

If you find it too long to type the modulename.method etc., you can do this

[code]import module as M[/code]

where module is the module and M is the short form you choose.

Python is a great language, though people find the forced indentation a little strange or even painful at first.

Share this post


Link to post
Share on other sites
Thanks for the advice, Vharis!

I haven't made it to the lists an tuples section of the tut yet, but I'll pay close attention there. I'm sorry I don't yet understand your advice against "from ... import ..." and importing modules, but I'm sure I will when the time comes.

Good luck on your game, BTW. It looks great!

Also, I found this blog and it looks like it will be of great use to me (and maybe you too, VH) when I become more advanced: [url="http://breinygames.blogspot.com/"]http://breinygames.blogspot.com/[/url]

It has a Rogue-like 2D random dungeon generator for Python that looks really, really good.

Share this post


Link to post
Share on other sites
Greetings Sharpe! Welcome to the forums!

I am also a -to certain extent- aged hobbyist developer, from the other side of the Atlantic, liking RPGs and Python.

Old-timer RPGs rock! Nice that there are people trying to reimplement those games even nowadays! I haven't played with an exact roguelike, but similar ones I enjoyed from the 80s. Perhaps you remember [url="http://www.bardstaleonline.com/BT1/"]The Bard's Tale series[/url] from those times, I think these may be called the next stage of pure ASCII roguelikes, or am I wrong? Even today I have a savegame from this series, and sometimes I do some progress through the dark dungeons of Skara Brae.:)

Unfortunately not having any technical advice to you in thy RPG game programming endeavour as I have only created a simple platformer - a [url="http://en.wikipedia.org/wiki/Lode_Runner"]Lode Runner[/url] clone - in Python. Pygame is very good for arcade games, too, so I would consider using some graphics instead of ASCII in your game.

However I would suggest some Python books, which I found most entertaining and useful in learning, both are available as free pdf downloads:
[url="http://inventwithpython.com/"]Invent your own computer games with Python[/url] and
[url="http://greenteapress.com/thinkpython/thinkpython.html"]Think like a computer scientist[/url]

Happy coding, learning!
Keep us / me informed about your project.

Share this post


Link to post
Share on other sites
[quote name='Sharpe' timestamp='1317509928' post='4868107']
Thanks for the advice, Vharis!

I haven't made it to the lists an tuples section of the tut yet, but I'll pay close attention there. I'm sorry I don't yet understand your advice against "from ... import ..." and importing modules, but I'm sure I will when the time comes.

Good luck on your game, BTW. It looks great!

Also, I found this blog and it looks like it will be of great use to me (and maybe you too, VH) when I become more advanced: [url="http://breinygames.blogspot.com/"]http://breinygames.blogspot.com/[/url]

It has a Rogue-like 2D random dungeon generator for Python that looks really, really good.
[/quote]

Namespace is an important concept in programming because it defines the "Scope" of variables. Some basic intro can be found in wikipedia:

http://en.wikipedia.org/wiki/Namespace
http://en.wikipedia.org/wiki/Global_variable
http://en.wikipedia.org/wiki/Scope_%28programming%29

Lot of technical jargon there, but once you grasp the basic concept, it's really easy to figure out.

Share this post


Link to post
Share on other sites
Thanks, guys, for the replies! :)

Elodman, I'm picking up what you're putting down!

Unfortunately, I didn't get a computer until 1995, a Packard Bell P75. My friend, who had a 486 DX2, didn't have the Internet yet (of course) and we were too young to have the money to buy games. We had the shareware version of Doom and we played the heck out of that until we went together and bought Doom 2 (I had a screaming-fast non-MMX P166 32MB RAM by then). We weren't much for RPGs on the computer, though I loved NES classics like Dragon Warrior and Final Fantasy and Crystalis, etc. So, I missed most of those great classics that I'm sure I would have loved.

We played a lot of table-top role playing, a.k.a, Dungeons and Dragons, though, then moved to GURPS when I was in the eighth grade.

I actually picked up that book first and liked it, but I liked the tutorial I liked a little better. Plus, I started to get worried about the whole 3.2 Vs. 2.7 thing. I went with 2.7 after a fair bit of reading.

Share this post


Link to post
Share on other sites
For an in-depth tutorial making a roguelike game using Python, you can look try here: [url="http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod"]http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod[/url]

I have not done much with Python, and I've only glanced at the above tutorial, but it seems to go through just about everything for a simple roguelike game, including dungeon generation, items, exploration, monsters, etc.

Share this post


Link to post
Share on other sites
[size="1"][i][b]EDIT: Found it!!! I needed "global roll" without quotes in my roll functions!!![/b] Man, I've been working on that for an hour. I'll edit my code for other newbies like me. :) The game appears to work. [/i][/size]



I guess I'm missing something when dealing with variables and functions.

I define the variable "roll" as 747 right up front. I'm not [i]exactly [/i]sure why I have to do that, but I know I do. Otherwise, when I run the program, it says "roll" isn't "global."

That's not my concern.

My concern is that it keeps reverting back to 747 after I have a function change it. I guess functions can only change the global variable inside themselves?

After the user chooses which monster to fight, the game calls the combat() function.

The combat() function calls the 20-sided dice rolling function called roll_1d20.

The roll_1d20 function sets the roll variable to a number between 1 and 20 and prints it. It works.

However, for the combat function the roll function is still 747 no matter what the roll_1d20 function says.

Help, please?

[code]from random import randint

roll = 747

def roll_1d20():
global roll
roll = randint (1,20)
print "You rolled", roll, "on a 20-sided dice.\n"

def roll_1d10():
global roll
roll = randint (1,10)
print "You rolled", roll, "on a 10-sided dice.\n"

def combat():
roll_1d20()
if roll <= 9:
print "You missed!\n"
print "The monster strikes and kills you!"
elif roll >= 10:
print "You struck!\n"
roll_1d10()
print "You rolled a", roll, "for damage.\n"
print "You win!"

print "\n\nWelcome to the Sorcerer's Arena!"
game = 1
while game != 0:

print "\nWhich monster would you like to fight?\n"
print "1. Goblin"
print "2. Orc\n"
print "Enter 0 to quit.\n"

monster_choice = input()

if monster_choice == 0:
break

else:
print "\nYou enter the arena, sword in one hand, shield in the other.\n"

if monster_choice == 1:
print "The goblin stands before you, clutching a spear in both hands.\n"

elif monster_choice == 2:
print "The towering orc stands before you, battle axe raised above its head.\n"

combat()




[/code]

Share this post


Link to post
Share on other sites
Crap. I hate bumping my topic, but I don't want a completely different question to get lost in a super long post. Plus, I'm afraid I'll figure it out like last time right after I post... But, I've been at this for nearly a half hour.

Now I'm having problems seeding a random number -- for player damage, in this case, but I need to know for generating numbers for other things too.

[code]
import random

playerST = 14 #The player's strength (ST)
playerWeapon = "sword" #The player's weapon

if playerST == 14:
playerDam = random.randint(2,12) #The basic "damage roll" for player strength of 14.
if playerWeapon == "sword":
playerWeaponDam = 3 #The sword adds 3 points to the basic damage roll.
playerSwDamType = "cut" #Ignore. Not yet used.
playerThDamType = "imp" #Ignore. Not yet used.

def player_dam():
a = playerDam + playerWeaponDam #The player's damage roll is the basic damage plus the weapon damage.
print playerDam #Printed to see what's going on.
print playerWeaponDam #Printed to see what's going on.
print a #Printed to show the actual damage inflicted.

player_dam()
player_dam()
player_dam()
[/code]

Each time the program runs the player_dam() function, it outputs the same numbers.

The weapon damage is 3, which is meant to be added to the player's strength (playerST variable). The playerST variable is meant to reseed for a different number (between 2 and 12) every time. So, the damage with the sword should be 5-15.

I Googled it and found someone who said to use "random.seed(); random.randint()" just like that. But, IDLE doesn't like it.

[code]
import random

playerST = 14
playerWeapon = "sword"

if playerST == 14:
playerDam = random.seed(); random.randint(2,12)
if playerWeapon == "sword":
playerWeaponDam = 3
playerSwDamType = "cut"
playerThDamType = "imp"

def player_dam():
a = playerDam + playerWeaponDam
print playerDam
print playerWeaponDam
print a

player_dam()
player_dam()
player_dam()
[/code]

This is the error I get:

[code]
Traceback (most recent call last):
File "C:\Python27\testing.py", line 19, in <module>
player_dam()
File "C:\Python27\testing.py", line 14, in player_dam
a = playerDam + playerWeaponDam
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
[/code]

random.seed() does seem to work and I've tried putting it in every place I can think to do, but I can't seem to get it to re-seed with a new number every time...

So, I either get the exact same damage every time, or it doesn't work at all... :(

Share this post


Link to post
Share on other sites
This should be as such
[code]if playerST == 14:
random.seed ()
playerDam = random.randint(2,12)
[/code]

Since random.seed () returns None. You actually set the variable to none. There is no need to use random.seed () every time you call random function. You need to use it just once in your program..

Another problem in your code is that you put the initial value of playerWeaponDam in a if block; that variable is not actually initialized unless the if condition succeeds. If the if condition fails for some reason, you'l get another error. Always initialize variables OUTSIDE if blocks.

So always do this kind of thing:

[code]
# initial value for damage. Set to 0
playerWeaponDamn = 0
if playerWeapon == "sword":
playerWeaponDam = 3
playerSwDamType = "cut"
playerThDamType = "imp"
[/code]

I once again suggest you learn variable scoping a bit more, before you proceed further otherwise you'll get confused as to why you get errors when you've apparently initialized a variable and the interpreter says you haven't.

Share this post


Link to post
Share on other sites
Man, thanks sooo much for answering, but I did try putting random.seed() there.

Here is the results:

[img]http://img705.imageshack.us/img705/4385/randomm.png[/img]

You'll notice the damage roll is the same every time for all three times I call the function. :( I need the damage roll to be different every time there is a roll.

Here is the code shown in the screen shot:

[code]
import random

playerSwST = 14 #The Player's swing (Sw) strength (ST).
playerThrST = 14 #The player's thrust (Thr) strength (ST).
playerWeapon = "sword" #The character's weapon.

if playerSwST == 14:
random.seed()
playerSwDam = random.randint(2,12) #The basic damage roll for a swinging attack.
if playerThrST == 14:
random.seed()
playerThrDam = random.randint(2,12) #The basic damage roll for a thrusting attack.

if playerWeapon == "sword":
playerWeaponSwDam = 3 #The sword adds 3 points to the basic swing damage roll.
playerWeaponThrDam = 3 #The sword adds 3 points to the basic thrust damage roll.
playerSwDamType = "cut" #Ignore. Not yet used.
playerThrDamType = "imp" #Ignore. Not yet used.
hands = 1 #Ignore. Not yet used. Can be 0, 1 or 2. Can't use shield if 2.
elif playerWeapon == "none":
playerWeaponSwDam = 0 #With no weapon, no damage is added to swing attacks.
playerWeaponThrDam = 0 #With no weapon, no damage is added to thrust attacks.
playerSwDamType = "cr" #Ignore. Not yet used.
playerThrDamType = "cr" #Ignore. Not yet used.
hands = 0 #Ignore. Not yet used. Can be 0, 1 or 2. Can't use shield if 2.

def player_dam():
swDam = playerSwDam + playerWeaponSwDam
thrDam = playerThrDam + playerWeaponThrDam
print "Base swing damage: ", playerSwDam
print "Base thrust damage: ", playerThrDam, "\n"
print "Weapon swing damage bonus: +", playerWeaponSwDam
print "Weapon thrust damage bonus: +", playerWeaponThrDam, "\n"
print "Actual swing damage: ", swDam
print "Actual thrust damage: ", thrDam, "\n"
print "*" * 25

player_dam()
player_dam()
player_dam()
[/code]

[quote name='vharishankar' timestamp='1317720292' post='4868914']
This should be as such
[code]if playerST == 14:
random.seed ()
playerDam = random.randint(2,12)
[/code]

Since random.seed () returns None. You actually set the variable to none. There is no need to use random.seed () every time you call random function. You need to use it just once in your program..

Another problem in your code is that you put the initial value of playerWeaponDam in a if block; that variable is not actually initialized unless the if condition succeeds. If the if condition fails for some reason, you'l get another error. Always initialize variables OUTSIDE if blocks.

So always do this kind of thing:

[code]
# initial value for damage. Set to 0
playerWeaponDamn = 0
if playerWeapon == "sword":
playerWeaponDam = 3
playerSwDamType = "cut"
playerThDamType = "imp"
[/code]

I once again suggest you learn variable scoping a bit more, before you proceed further otherwise you'll get confused as to why you get errors when you've apparently initialized a variable and the interpreter says you haven't.
[/quote]

I'll initialize them outside of the if blocks. Thanks, man.

I'm trying. I'm trying hard. I spent hours and hours today working on this.

You may have noticed that I finally got what you said about the module and putting "random.randint()" instead of putting "randint()" and from random up at the top. It takes me a bit to even understand your advice due to the fact that I'm such a complete newbie and the fact that I'm only slightly more intelligent than a rock.

Thanks again! I really appreciate the help a lot.

Share this post


Link to post
Share on other sites
That's not the fault of the random.seed () function ;)

You've only called the random.randint () once in the whole program if you notice. That's why you got a random number once, but the same value is used every time you call the function.

The function player_dam() uses the same value every time it is called. The block of code which does the random.randint is outside the function and is executed only once in the program. That's why you get the same number.

Note that random.seed () is used to initialize the random number generator and need be called only once.

Share this post


Link to post
Share on other sites
[quote name='vharishankar' timestamp='1317723868' post='4868923']
You've only called the random.randint once in the whole game.

The function uses the same values every time. The block of code which does the random.randint is outside the function and is executed only once.

That's why you get the same number.
[/quote]
I thought it was something like that, but... Hmmm... I'm not sure how to proceed, then. Should I... I'm not even sure what to ask, now.

My combat() function calls a bunch of other functions, like player_skill() and monster_damage(), etc...

[i][b]EDIT:[/b][/i] Oh, if I put all my playerST things (sorry, don't know what to call them :unsure:) in the player_dam() function, then will it re-seed the number every time? I'll try that, anyways.

playerST values will go from like 1 to 30 or so, so that's going to be a lot.

[i][b]EDIT x2:[/b][/i] OH THAT WORKED!!! THANKS SO MUCH, MAN!!! :D

Thanks for donating your time and patients with me, and for all the advice and help. You're very kind. :)

Share this post


Link to post
Share on other sites
It's really simple. Every time you need a random number, you call the random.randint () function.

In this case, you would call the random.randint () inside the function which computes the damage.

Also forget the "seed" part. random.seed () needs to be called only [b]once[/b] in the whole program - it is merely to initalize the random number generator in the module random.

Share this post


Link to post
Share on other sites
[quote name='vharishankar' timestamp='1317724331' post='4868925']
It's really simple. Every time you need a random number, you call the random.randint () function.

In this case, you would call the random.randint () inside the function which computes the damage.

Also forget the "seed" part. random.seed () needs to be called only [b]once[/b] in the whole program - it is merely to initalize the random number generator in the module random.
[/quote]
Will do. Thanks again. :)

Share this post


Link to post
Share on other sites
[size="1"][b]EDIT: [/b]I think it's actually pretty painfully obvious to me why it doesn't work now, but I'm not sure how to proceed with my actual game code now. I've been doing a lot of reading and I think I understand that mainly functions (and classes?) can reference variables with "global variableName". I really don't know anything about classes yet...[/size]


Why doesn't this work? :(

I've been wrestling with this for some time and I'm sure the problem is along the lines of me not fully understanding namespace or variable scope...

[code]enemy = "none"

if enemy == "orc":
enemyName = "orc"
else:
enemyName = "goblin"

fight = "none"

print "An orc draws near!"
fight = raw_input("Fight (F) or Run (R)?: ").lower()
if fight == "f":
print "You fight the orc!"
enemy = "orc"
print enemyName, "attacks you!"
elif fight == "r":
enemy = "orc"
print "You run from", enemyName
else:
print "Not a valid option."
[/code]

It will use "goblin" as the enemyName, as I'm sure those who actually know something about programming will immediately see though I can not...

My if block can't change the variable outside of it. I get that. But, how do I make it? When I put global enemy it just locks up.

In my actual game code, I thin I can get this to work if I make enemy a number instead of a word, it seems. But, maybe something's up there too.

Help, please?

Share this post


Link to post
Share on other sites
You're not changing enemyName again.
[code]
print "An orc draws near!"
fight = raw_input("Fight (F) or Run (R)?: ").lower()
if fight == "f":
print "You fight the orc!"
enemy = "orc"
print enemyName, "attacks you!"[/code]

See, you change the enemy variable, yes, but the enemyName is still goblin.

Changing the variable enemy does not automatically change enemyName every time.

I am not sure whether I understood your problem right though!

Share this post


Link to post
Share on other sites
You understood me correctly. I'm just that stupid!

The program doesn't re-run the if/else every time you change the variable it's dealing with. I see now.

I guess I'll have to write a function that selects which monster you fight in my game.

Thanks again! Even though you were only stating the blatantly, in-your-face-obvious, I still wasn't understanding that the if/else wouldn't automatically update. :rolleyes:

Share this post


Link to post
Share on other sites
[quote name='Sharpe' timestamp='1317704952' post='4868857']
[size="1"][i][b]EDIT: Found it!!! I needed "global roll" without quotes in my roll functions!!![/b] Man, I've been working on that for an hour. I'll edit my code for other newbies like me. :) The game appears to work. [/i][/size]
[/quote]

I'm afraid you've missed the point. The standard way to communicate information between functions is to pass it in via parameters, and pass it out via the return value.

Share this post


Link to post
Share on other sites
[quote name='Zahlman' timestamp='1317819569' post='4869380']
[quote name='Sharpe' timestamp='1317704952' post='4868857']
[size="1"][i][b]EDIT: Found it!!! I needed "global roll" without quotes in my roll functions!!![/b] Man, I've been working on that for an hour. I'll edit my code for other newbies like me. :) The game appears to work. [/i][/size]
[/quote]

I'm afraid you've missed the point. The standard way to communicate information between functions is to pass it in via parameters, and pass it out via the return value.
[/quote]
Example?

I've not used the "return value." "Parameters" just means everything in the function, right?

Share this post


Link to post
Share on other sites
[quote name='laztrezort' timestamp='1317535441' post='4868181']
For an in-depth tutorial making a roguelike game using Python, you can look try here: [url="http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod"]http://roguebasin.ro...ython%2Blibtcod[/url]

I have not done much with Python, and I've only glanced at the above tutorial, but it seems to go through just about everything for a simple roguelike game, including dungeon generation, items, exploration, monsters, etc.
[/quote]
Wow. I have tried and tried to import in Windows 7, Python 2.7 (c:\python27), and I cannot figure it out.

Generally, I just don't know how to import, really.


[quote]Now to create your project's folder. Create an empty file with a name of your choice, like [i]firstrl.py[/i]. The easiest way to use libtcod is to copy the following files to your project's folder: [list][*] [i]libtcodpy.py[/i][*] [i]libtcod-mingw.dll[/i] on Windows, [i]libtcod.so[/i] on Linux[*] [i]SDL.dll[/i] on Windows, [i]SDLlib.so[/i] on Linux[*] A font from the [i]fonts[/i] folder. We chose [i]arial10x10.png[/i].[/list][/quote]

This, I did.

This is the error:

[code]Traceback (most recent call last):
File "C:\Python27\test\firstrl.py", line 1, in <module>
import libtcodpy as libtcod
File "C:\Python27\test\libtcodpy.py", line 41, in <module>
_lib = ctypes.cdll['./libtcod-mingw.dll']
File "C:\Python27\lib\ctypes\__init__.py", line 428, in __getitem__
return getattr(self, name)
File "C:\Python27\lib\ctypes\__init__.py", line 423, in __getattr__
dll = self._dlltype(name)
File "C:\Python27\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 is not a valid Win32 application[/code]

This is the code:

[code]import libtcodpy as libtcod

#actual size of the window
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50

LIMIT_FPS = 20 #20 frames-per-second maximum


libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)

libtcod.sys_set_fps(LIMIT_FPS)

while not libtcod.console_is_window_closed():

libtcod.console_set_foreground_color(0, libtcod.white)

libtcod.console_print_left(0, 1, 1, libtcod.BKGND_NONE, '@')

libtcod.console_flush()[/code]

Share this post


Link to post
Share on other sites
[quote name='Sharpe' timestamp='1317868881' post='4869633']
[quote name='Zahlman' timestamp='1317819569' post='4869380']
[quote name='Sharpe' timestamp='1317704952' post='4868857']
[size="1"][i][b]EDIT: Found it!!! I needed "global roll" without quotes in my roll functions!!![/b] Man, I've been working on that for an hour. I'll edit my code for other newbies like me. :) The game appears to work. [/i][/size]
[/quote]

I'm afraid you've missed the point. The standard way to communicate information between functions is to pass it in via parameters, and pass it out via the return value.
[/quote]
Example?

I've not used the "return value." "Parameters" just means everything in the function, right?
[/quote]

In programming, a function receives input and returns output.
Yes, its the old in-out scheme.


Actually you have used both function parameters (input) and return value (output) in your program.
Example:
[i]target = randint (1,10)[/i]
[i]
[/i]
In this case the function is [i]randint[/i], the input parameters is 1 and 10, and the return value is a random number between 1 and 10.
The return value produced by the function is in this case stored in the variable [i]target.[/i]

Share this post


Link to post
Share on other sites
[quote name='Sharpe' timestamp='1317873770' post='4869641']
[code]
WindowsError: [Error 193] %1 is not a valid Win32 application
[/code]
[/quote]

I don't know python very well, but this error message makes we wonder if there is a 32/64 bit incompatibility issue. From the tutorial link:

[quote]
(Note for Windows 7 64-bits users: install the 32-bits version, since the 64-bits version of Python seems to cause problems with libtcod.)
[/quote]

It looks like libtcod is not compatible with 64 bit Python, maybe this is the problem?

Share this post


Link to post
Share on other sites
[quote name='Sharpe' timestamp='1317873770' post='4869641']
[quote name='laztrezort' timestamp='1317535441' post='4868181']
...
[/quote]
[/quote]

The tutorial says that you have to use a 32 bit version of python. Are you sure you didn't install the 64 bit version?

Besides, I think you are jumping ahead here. You should consider leaving that tutorial for later as it is counterproductive for a beginner

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this