Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


I have got am if-statement problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Ironmaggot   Members   -  Reputation: 214

Like
0Likes
Like

Posted 07 December 2013 - 09:13 PM

I have got a problem with my click detection.

 

Here is the code that manages that:

if click != []:

            for i in range(len(stars[0])):

                if (((click[0][0] >= (int(stars[0][i]) - 8)) and (click[0][0] <= (int(stars[0][i]) + 8))) and ((click[0][1] >= (int(stars[1][i]) - 8)) and (click[0][1] <= (int(stars[1][i]) + 8)))) and click[1][0] == 1:
                    stars[2][i] = 2
                    print("left")

                elif (((click[0][0] >= (int(stars[0][i]) - 8)) and (click[0][0] <= (int(stars[0][i]) + 8))) and ((click[0][1] >= (int(stars[1][i]) - 8)) and (click[0][1] <= (int(stars[1][i]) + 8)))) and click[1][2] == 1:

                    for j in range(len(stars[0])):

                        if stars[2][j] == 2 and j != i:
                            setUpStart = []
                            setUpStart.append(int(stars[0][j]))
                            setUpStart.append(int(stars[1][j]))
                            setUpEnd = []
                            setUpEnd.append(int(stars[0][i]))
                            setUpEnd.append(int(stars[1][i]))
                            setUpLine = []
                            setUpLine.append(setUpStart)
                            setUpLine.append(setUpEnd)
                            fleets.append(setUpLine)

                        stars[2][j] = 1
                    stars[2][i] = 1
                            
                    print("right")

                else:
                    stars[2][i] = 1

It should basically allowe me to select a star with a left click and then select another star with right click, whose coordinates are then stored for later. Clicks that do not land on stars, Just deselect any star that happens to be active.

 

But the problem is, that some stars some times just do nothing when I right click on them even though I have another star selected. I cannot find the reason that is causing it. Can anyone else find it?


Edited by Ironmaggot, 07 December 2013 - 09:14 PM.


Sponsor:

#2 superman3275   Crossbones+   -  Reputation: 2061

Like
1Likes
Like

Posted 07 December 2013 - 11:37 PM

As one of the few members on here who uses Python for games:

What library are you using?

What does the Stars array do?

How does the click array work?

Some of these can be fixed if you *post full source code*. Then I can help you.

Cheers ;)!

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!


#3 Ironmaggot   Members   -  Reputation: 214

Like
0Likes
Like

Posted 08 December 2013 - 12:15 AM

As one of the few members on here who uses Python for games:

What library are you using?

What does the Stars array do?

How does the click array work?

Some of these can be fixed if you *post full source code*. Then I can help you.

Cheers ;)!

 

I am using pygame library.

 

Stars array is just an array that stores information about stars that are on the map. Coordinates, resource value, garrison size, etc.

 

Click array when mouse is clicked returns: ((mousePosX, mousePosY), (1, 2, 3)). Numbers 1,2,3 represent mouse buttons. If left button is clicked, slot 1 will be "1" and all the other slots will be 0. Right click gives 1 in the slot 3 and 0 in the others.

 

How should I post the source code? It is quite long?

 

------------------------------

 

It seems that I have fixed the problem. I don't know what was the problem, but its gone now.


Edited by Ironmaggot, 08 December 2013 - 02:48 AM.


#4 rip-off   Moderators   -  Reputation: 8532

Like
2Likes
Like

Posted 08 December 2013 - 06:02 AM

for j in range(len(stars[0]))

Should this be stars[2]?

 

Your code is difficult to read because there are logs of magic numbers and repeated expressions. I'd recommend using named constants and pulling important expressions into a variable with a good name.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS