Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Gr3yling

Pages: [1] 2 3 ... 12
Wow, you were right. This is turning into an enjoyable discussion. So what does the interpreter say after you fix that line?

(i.e. when you change object.Hostile_AI.take_turn() to ?)

I found the problem.  There were a number of errors, but the main one was that Hostile_AI was the name of the class itself, not of an instance of the class.  I had forgotten to instantiate it at all. 

There are a number of bugs still left, but I think I can probably fix them.  I actually had a successful program and was at the step of implementing an inventory system when I decided that the roguelike tutorial's way of making almost all in game objects (the PC, monsters, items, etc) members of the same multifunctional class was better than my way of having a separate item and actor class.  And then when I tried to implement that, there were a bunch of errors that popped up from the changes I made.

Anyway, thanks for the help turoturo.

Yes.  There is a specific problem.  It's kind of hard for me to know exactly what code to post (I'm so lost It's really hard to be sure).  Also, my code is really ugly.   The code is based on the complete roguelike tutorial code, but I've tried to come up with my own way to do as many things as I can, which is probably why it doesn't work now. Anyway, maybe this is a decent start.

the monster AI module is supposed to be called after the player has moved, and this is my attempt to do that:

Code: [Select]
def monster_act():       
    if player_action != False:   
        if game_state == 'playing':
            for object in objects:
                if == Hostile_AI:
                    if object.alive:

Problem is, I get an exception saying that my object class (of which monsters are a member), doesn't have an attribute "Hostile AI"

Well, here is my object class template:

Code: [Select]
class Object:
    def __init__(self, x, y, char, name, color, ai = None, item = None, status = None, equipment = None, inventory = None, alive = True, blocks = False):
        self.x = x
        self.y = y
        self.char = char = name
        self.color = color = ai
   = self
        self.item = item
        if self.item:
            self.item.owner = self
        self.status = status
        if self.status:
            self.status.owner = self
       = equipment
   = self
        self.inventory = inventory
        self.alive = alive
        self.blocks = blocks

There's more code for object, but this is already a ton, so I won't post it unless you tell me to.

And here's a specific instance of object:

Code: [Select]
monster = Object(x, y, 'R', 'Razor head ' + str(razorhead_no),, ai = Hostile_AI,
status = razorhead_status, alive = True, blocks = True)
razorhead_no = razorhead_no + 1

Hostile ai is there!  I don't see what the problem is.

The whole idea behind my question was that I thought if I knew how python handled attributes/variables, that I would be able to figure out myself what went wrong.

*Edited for clarity

I would also agree with chooseusername. You should ask questions like this on stackexchange or similar sites, if you must (where you will encounter appropriate criticism for them, I might add), or just google. Questions about the mechanics of id or python hashes or whatever else are both uninteresting and better addressed by people well versed in and interested in answering questions about such matters, rather than people who don't know but are eager to indulge your idle curiosity.

As best as I can determine from my examination of the programming forum, there have been no posts in topics other than this one since May the first.  No precious resources that should have been allocated to other concerns have been squandered.  No one is wasting your valuable time and alleged expertise. This post is not off topic.  It is about the  difficulties I have had programming a roguelike and it was posted in the programming forum.  If you feel that it violates any kind of rules, by all means, report it to the moderators.

I find it somewhat surprising that you chose to belittle me by saying that this topic satisfied my "idle" curiosity.  One wonders, do you find your own posts about video game development in an extremely niche genre to be somehow more productive to society?  Do you arrogantly find your own contributions to this forum to be somehow vital to its functioning? 

I also find it interesting that you state that others who have made contributions to this topic, like Xecutor, Aukustus, and Zireael "don't know" the answer to my question.  And I suppose you think you know far better than them?  I personally fail to see how you have distinguished yourself as being more knowledgeable to them.

Finally, I posted at least in part because of the desire to interact with other individuals on these forums who I like and respect.  We could have had an enjoyable discussion, if nothing else, had you and chooseusername not come along. 

I wish to do absolutely nothing on this forum other than enjoy exchanging ideas and support other people who are trying to develop a game just as I am doing.  I don't understand why you don't feel the same way.

Also, do not confuse Python variables and real memory blocks. In lower-level languages like C they are the same thing. In higher-level languages variable is more like a wrapper around some object and may have very complex relation to actual memory. There is no reason for some variable to point to another variable's data indirectly. Because variable and it's data are not the same here, both variables may just directly point to same data.

Darn.  I guess I am in over my head, then.  Trystan, you're right, I thought this was going to help my understand why I keep having problems with my variables, but I guess it won't after all.

Like I mentioned earlier, my python book should be here pretty soon.  I guess I just need to study more to understand where I'm going wrong.


I really appreciate you taking the time to make your most recent post and all the other ones in this topic.  I realize that you have been much more patient than most people would have been with the questions I have asked.

That said, please do not post in my topic again.  I realize I have no authority to compel you not to do so, but I would greatly appreciate it if you did not.  I am sorry if I offended you with something I have said previously, but I do not feel that you are making a good faith attempt to be helpful anymore.

Xecutor, if you, Trystan, Zireael, and Aukustus all feel that this topic is a waste of time as chooseusername does, I will be happy to close it.  Otherwise, I look forward to your continued input, as I think you are knowledgeable enough to help me with what I am trying to understand.

*Edited because I can't spell.

Ah, so it's a mutable/immutable thing.  Okay.  That makes sense, because tuples seem to behave the same way, based on my limited testing.

Lets walk through this just to makes sure I understand:

The first variable x gets bound to five.  This means 5 is used to generate a hash value (which is also 5, it seems based on testing), which python uses to decide what memory address to store the value '5' at.

Second variable x gets bound to five.  Now, I though that with a pointer, a new hash value was generated for a new memory address, and that address just stored the location of the first memory address and told the computer to look there next.

But is the following happening instead for the second x?: python generates an identical hash for the second x, linking both x's back to the same memory address containing the 5 value.

See the distinction I'm trying to understand?  With what I understand a pointer to be (and I may be totally wrong) is one address that just contains instructions which 'point' the program to another different address, but with what seems like it is happening in python, there is only one address that both variables refer to.

And you guys are saying that the process is different with mutables/immutables?  Which, if either, of the scenarios I described previously happens with each of those?

I know theses seem like odd questions, but I think about things in an odd way, and this really does help me.

Thanks for taking the time to answer my question, Xecutor.   I do believe that you know what you are talking about (and I actually suspected you would be someone who could help me) but it is confusing to hear some sources say that python does not use pointers, and then in this topic multiple people have said it does.  What is the cause of this discrepancy?

And just to be clear, the code I posted is not something I would use in my roguelike, I'm just trying to understand local/global variables so that I can get past where I am stuck right now.

The fact is that id() is not something you should really ever use, and getting stuck on understanding it, is like getting stuck on why grass is pointed when you're mowing the lawn.  You can forget about the points on the blades of grass and keep mowing,  much the same as you can forget id() and learn and write top level Python code.  In fact, I suspect that most anyone who used id() would be writing low quality Python code.

Dood, I write the *LOWEST* quality python code right now.  I have been trained most of my life for something vastly different than understanding computer science, and the reason that I'm posting here is so that I want to write just barely less low quality code than that which you are referring to. 

Look, I know it seems weird, but the best way I seem to understand things is in a bottom-up sort of way, where there slightly less complicated concepts build on the most complicated concepts. 

tl:dr (even though I do read all of what *you* post when you say tl:dr) I'm trying to learn about computer science coming from a completely different dimension than most of those who study it.  Please be patient with me.

I thought Python didn't use pointers:

This topic starts with the statement: " I know python doesn't have pointers, but..."

So what gives?  Your answers are leaving me with more questions than solutions.

Sorry, I really do appreciate you (and the others who replied) taking the time to answer my question.  I just wish I understood enough to write the game I want to make.  I'm not trying to be difficult, it just seems that python can be very inconsistent sometimes. 

But I still don't understand how the two x's are independent if they but refer to the same memory address, presumably storing the same value.  Like I said, I thought that in the most fundamental way, the memory address *was* the identity of a variable. 

Okay, I have no idea how this got posted.  The forum interface was acting wonky so I decided to give up and post my question later.  Sorry.  I didn't realize it actually got submitted.

Suffice to say I've been having a lot of trouble with understanding how variables are bound in Python.  Before you link me to the python documentation, let me just say that I have definitely looked there extensively (and a lot of other tutorials).

There are a number of things I'm having a hard time getting, but lets start with this one:

x = 5

def test_function():
    x = 5
    return id(x)

print test_function()

print id(x)

Output: 31292720  and 31292720

WAAAAAT?  Aren't id's in CPYTHON memory addresses?  So, why do both x's have the same memory address?  I thought the whole point of all this crazy global and local variable stuff was that even though a variable might have the same name inside and outside of a function, it was NOT really the same variable unless global was called.  And my understanding is that if two variables have identical memory addresses, they meet the strictest quality for being identical (i.e. x(1) IS x(2), not just x(1) == x(2)).

I've got a lot of other questions but this is the one that's bugging me most right now.

I bought "Python in a Nutshell", and it's a bit over my head.  "Introduction to Python" (by O'Reily) should be here soon, so maybe I'll do better once I get started on it.

Programming / Oh boy, adventures in rebinding variables!!! (Python)
« on: May 17, 2014, 02:51:41 AM »
That sounds like a fantastic name for a roguelike, incidentally.

So, I'm having a number of problems, and I suspect they are related to my limited understanding of how variables are bound and re-bound.  I don't understand why the following code:

count = 0

def increment(x):
    global x

Early Dev / Re: The Veins of the Earth development feedback beta 5)
« on: May 01, 2014, 12:57:08 AM »
What is your roguelike going to be about?

Oh, just a weird story I've had in my mind for a decade or so.  I'm really terrible at pitching things, but when I finish it I'll show it to you.

And, by the way, working on my own game really makes me appreciate how much work you (and all the other game authors out there) put into your projects.  Don't get me wrong, I've always known that making games was really, really, tough, and had a respect for game developers, but my recent experiences just made me want to say thanks.

Early Dev / Re: The Veins of the Earth development feedback beta 5)
« on: April 27, 2014, 12:40:22 AM »
Looking good, Zireael.  Looking forward to playing the update.

Just out of curiousity, do you have any goals to ever implement an overworld?  I realize you're busy with other parts of the game right now, but I was wondering if it was in your long term plans.

Oh, and I thought you might be proud of me because I've been sticking with learning python/libtcod and have some very rudimentary beginnings of a roguelike in place.

Programming / Re: Generating a list of unique random numbers
« on: April 18, 2014, 02:20:17 AM »
This is what I was trying to do (I think), in pretty much the way I was trying to do it:

from random import randint

random_list = []

while len(random_list) <= 20:
    random_no = randint(0,20)
    Unique = True
    for entry in random_list:
        if random_no == entry:
            Unique = False
    if Unique == True:

print random_list


Yes, there are better ways to do it which have already been mentioned, but this one fits my weird criteria.  Sorry if someone already posted something essentially the same as this and I missed it.

Pages: [1] 2 3 ... 12