[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?



It doesn't work... I can't quite figure it out. Am I missing a part? It says my syntax is correct...

At the very top of the file right after the import statements, I added a line that reads:

moving = 0

After that, I changed this:

    def keyin(self, key):
        if key == self.text[self.current_string][self.pos] and moving == 0:

And I changed the bottom part to:

        for event in pygame.event.get ():
            if event.type == QUIT:
                return
            elif event.type == KEYUP:
                if event.key == K_TAB:
                    moving = 0
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    return
                elif event.key == K_TAB:
                    moving = 1
                else:
                    textsprite.keyin(event.unicode )

It didn't work. I tried using the words "True" and "False" without the quotes. It didn't work. I tried using moving is True instead of moving == 1 and it still didn't work.  I tried moving the statement moving = 0 into my main(), and it didn't work. Argh. I think I'm missing something really simple, but I can't place my finger on it...

On 1/22/07, Charles Christie <sonicbhoc@xxxxxxxxx> wrote:
Genius! Why didn't I think of that? I'll make a variable that will
react to the state of the TAB key called "moving". Pressing TAB makes
moving = 1 and releasing it changes it back to 0. Now, when moving =
1, keypresses won't register to the typing thinggy, and when moving =
0, the next part of the code I'm going to write (the basic shoot-em-up
part) the character doesn't move.

You guys are so helpful! Thanks!

On 1/22/07, Luke Paireepinart <rabidpoobear@xxxxxxxxx> wrote:
> Charles Christie wrote:
> > Sorry for spamming your email inboxes so much guys... I'm bad at this
> > whole email list thing... I'm better with forums, because I can edit
> > messages I post and stuff. Eh... Sorry.
> >
> > Anyway, now I want the Textsprite class to not accept input while the
> > K_TAB button is pressed.
> >
> > What would I have to code in this situation? I know that the program,
> > upon pressing TAB, should not negatively effect score (I've already
> > coded that part) but I don't know how to get it to actually stop
> > advancing the pointer as long as the TAB button is held down. I think
> > its because the advice I got was for an older version of pygame and
> > its not working.
> Not sure what you mean about the old version...
> I am using a dvorak keyboard, therefore my typing speed is quite
> hampered while my mind learns the new layout.
> So my reply will be short.  Didn't want you to think I was being
> disrespectful.
>
> Okay, basically the problem you have is that you want to do something
> when the tab key's state is raised, and something else when its state is
> depressed.
> This suggests an if/else structure, because the key can only be in two
> states: depressed or not.
>
> now how do we determine the state of the key? like this:
>
> tab_pressed = False#set this once, outside your game loop, not on each
> iteration
> for event in pygame.event.get():
>   if event.type == KEYDOWN:
>     if event.key == K_TAB:
>       tab_pressed = True
>     else:
>       #call your function here
>   elif event.type == K_UP:
>     if event.key == K_TAB:
>       tab_pressed = False
>
> you'd probably want to add tab_pressed to your argument list for your
> keyin function.
> -Luke
>
>