Nether_1 0 Light Poster

Hi everybody,

I'm doing some programming in Flask, and as part of the program I'm doing a basic system of logging in, but that's not where my problem resides. During my programming, the page that is supposed to verify a login absolutely refuses to go past a specific line of code, regardless of what's past that line or what that line is doing. Here's the code:

@app.route('/loginConfirm')
def loginConfirm(): 
    try:

        username = request.args.get('usernameField')
        password = request.args.get('passwordField')

        for user in usersList:
            if(username == user.username):
                print(user.hashedPassword == sha256(password.encode('utf-8')).hexdigest())
                if(user.hashedPassword == sha256(password.encode('utf-8')).hexdigest()):
                    session.pop('uuid')
                    session['uuid'] = user.uuid
                    return redirect('/')

        return redirect('/login')

    except:

        return redirect('/login')

In this example, it will get to the print statement where I print whether or not the password is equivalent to the other (this returns True when its supposed to and is working correctly.). The problem lies in the fact that if I were to add another print statement directly after that, or any other type of statement including the if statement that is already there, then it won't execute, but it also won't throw an error. What confuses me is that the fact that it occurs only on this line makes me think it's something to do with an indentation error or a problem with the fact that its in a try statement, but if either of those are true then I can't find the result. Any help is greatly appreciated.

Nether_1 0 Light Poster

From my understanding, LED monitors turn each pixel on sequentially at such a high speed that the human eye can't observe it, but how does it make the necessary connections? For example, for a monitor made with a single color of LED across a standard HD resolution (say 1940 x 1080) there would have to be 3020 connections assuming its built in a grid.

I'm assuming I'm missing something.

Nether_1 0 Light Poster

Thanks to @deceptikon, I was able to use this code to successfully write the text from the text box to a text file:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
    {
        std::ofstream settings("settings.txt");
        String ^ buttonText1 = textBox1->Text;
        std::string buttonText1std = msclr::interop::marshal_as<std::string>(buttonText1);
        settings << buttonText1std << std::endl;
        settings.close();
    }

Thank you for your help!

Nether_1 0 Light Poster

I'm writing a code that will save the username of a user when a button (in this case button1) gets pressed. I save it to a file called info.txt, and i use fstream in order to save it. Currently I'm running into the issue that, while i can open up the file fine, I can't save the data from
textBox1 because it uses the data type String ^, while fstream doesn't support writing in that type. Here is my relevant code:

    private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e)
    {

    }
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
    {
        std::ofstream settings("settings.txt");
        settings >> textBox1->Text >> std::endl
    }

Obviously I can't use this because textBox1->Text returns the wrong type. Anybody have any solutions?

Nether_1 0 Light Poster

Since OpenGL uses the strange system of 1s and 0s to represent location on the screen, I'm trying to figure out how to switch it to standard x, y coordinates like those that are used on a graph. And so far, my searches on the rest of the internet have turned out nothing. So, to clarify:

How do I make it so that the bottom left corner is the starting place of 0,0 instead of the center of the screen, which is where OpenGL Defaults it too?

Here is my code for reference:

#include <iostream>
#include <SDL2/SDL.h>
#include <string>
#include <GL/glew.h>
#include <GL/GLU.h>

std::string projectName = "Testing The System";

SDL_Window *mainWindow;
SDL_GLContext mainContext;

bool init(int height, int width, std::string programName); //Creates Window and prepares program.
bool SetOpenGLAttributes();
void CheckSDLError(int line); //Finds errors in SDL Initialization
bool RunGame(); //Mainly used for event handling
void Cleanup(); //Shuts down windows, etc.
void Background();

int x, y;

bool init(int height, int width, std::string programName)
{
    //Checks SDL Loading.  If it fails, cancels program.
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        std::cout << "Critical Error #001: Failed To Initialize SDL.";
        return false;
    }

    mainWindow = SDL_CreateWindow(programName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);

    if (!mainWindow)
    {
        std::cout << "Critical Error #002: Failed To Properly Initialize Window" << std::endl;
        CheckSDLError(__LINE__);
        return false;
    }

    mainContext = SDL_GL_CreateContext(mainWindow);

    SetOpenGLAttributes();

    SDL_GL_SetSwapInterval(1);

    glEnable(GL_TEXTURE_2D);

    return true;
}

bool SetOpenGLAttributes()
{
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    return true;
}

void DrawPixel(int x, int y, int r, int g, int b)
{
    x = …
Nether_1 0 Light Poster

I'm coding a program to learn OpenGL in C++ (based off of The Benny Boxes tutorials) and I've run into a snag where I don't get any errors, but my shaders refuse to apply to the triangle that I'm rendering.

I'm going to give you all the relevant code but its going to be a lot because, after all, it's OpenGL in C++.

display.cpp

#include "display.h"
#include <GL/glew.h>
#include <iostream>

Display::Display(int width, int height, const std::string& title)
{
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    m_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
    m_glContext = SDL_GL_CreateContext(m_window);

    GLenum status = glewInit();

    if (status != GLEW_OK)
    {
        std::cout << "Glew failed to initialize!" << std::endl;
    }
    m_isClosed = false;
};

Display:: ~Display()
{
    SDL_GL_DeleteContext(m_glContext);
    SDL_DestroyWindow(m_window);
    SDL_Quit();
};

bool Display::isClosed()
{
    return m_isClosed;
}

void Display::Clear(float r, float g, float b, float a)
{
    glClearColor(r, g, b, a);
    glClear(GL_COLOR_BUFFER_BIT);
}

void Display::Update()
{
    SDL_GL_SwapWindow(m_window);

    SDL_Event e;

    while (SDL_PollEvent(&e))
    {
        if (e.type == SDL_QUIT)
        {
            m_isClosed = true;
        }
    }

};

display.h

#ifndef DISPLAY_H
#define DISPLAY_H

#include <SDL2/SDL.h>
#include <string>

class Display
{
public:
    Display(int width, int height, const std::string& title);
    void Clear(float r, float g, float b, float a);

    void Update();

    virtual ~Display();
    bool isClosed();
protected:
private:
    Display(const Display& other) {}
    Display& operator=(const Display& other) {}

    SDL_Window* m_window;
    SDL_GLContext m_glContext;
    bool m_isClosed;
};

#endif // Display_H

shader.cpp

#include "shader.h"
#include <fstream>
#include <iostream>

static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage);
static std::string LoadShader(const …
Nether_1 0 Light Poster

I'm attempting to write a code in which the user can add as many of a certain object as needed, and blit it on to a pygame window. Essentially a game engine of sorts. I need to make it so that they can add as many of these objects as they need, so that they can create a game world. The only problem I'm encountering is that I cannot create enough names for all of this by hard-coding it, and even then it would not be enough. So is there a way for me to make it so that they can name each class, or so that it would be procedurally generated names for each class? Here is my class:

##My Class
class objectMesh():
    def __init__(self, objectType, color, width, dimensions):   ##Send dimensions depending on what is required for each pygame.draw command. Polygons are
        self.objectType, self.color, self.width, self.dimensions = objectType, color, width, dimensions ##list of vertices, circles are center + radius, etc.
    def drawObject(self):
        if self.objectType == 0:
            drawRect(self.dimensions, self.color, self.width)
Nether_1 0 Light Poster

I'm writing a python program that will search for a password that is the first piece in a string. I'm using raw_input() to do it, and here's what the code is like

list = ['Nether\n']
password = list[0]
print password
if raw_input('Please Enter Password: ') == password:
    print "Successful"

This code will print 'Nether' with a line after it (it's supposed to be like that), but when I put it into the raw_input() statement, it doesn't accept the password. Please note this is a simplified version of the code but it is the area where the bug is originating, I can post the whole thing if necessary.

Nether_1 0 Light Poster

Heres the error:

Traceback (most recent call last):
    File "C:...", line 106, in <module>
        tempobject.editVertice((100, 100))
    File "C:...", line 94, in editVertice
        if vertice in self.vertice:
AttributeError: Object instance has no attribute 'vertice'

Thanks for the explanation of what raise does, I always wondered yet never looked it up.

Nether_1 0 Light Poster

Firstly, I would like to apologize for the massive number of nooby crap questions that come out of my account. I'm an emerging programmer that doesn't always know what he's doing, so I'm sorry.

Secondly, the problem. I'm writing this code:

class Object():
    def __init_(self, vertices, color, name):
        self.color = color
        self.name = name
        self.vertices = vertices ##Vertices is in list form

    def editVertice(self, vertice):
        if vertice in self.vertices:
            self.vertices.index(vertice)
        else:
            print "ERROR: VERTICE NOT RECOGNIZED.  INSERT VALID VERTICE"

The problem I'm having is that when I run this, it gives an error saying that the term 'vertice' in the function editVertice is not recognized, even though its clearly being called in the function. (Yes, I am calling the class and function later in the code, but seeing as its over a 180 lines I thought it might be a good idea just to leave it be). I have no idea why. Any help would be appreciated. I would prefer not to scrap the code, but I can if need be. Thanks in advance!

Nether_1 0 Light Poster

I always forget about range loops, I think this would work. Thank you!

Nether_1 0 Light Poster

Well the list would contain every possible combination of all the numbers 1-10 in a tuple, so basically this:

(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0), (8, 0), (9, 0), (10, 0)
(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (9, 1), (10, 1)
(0, 2), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2)
etc. etc.

Nether_1 0 Light Poster

Hey everybody.
I'm currently working on making a simple 2D "engine" of sorts in which I can assign certain objects to certain coordinates and it will render them out there. It's mainly to be about 2D animation and the like, but that's besides the point.
I'm working on a coordinate grid (possibly called array) which will be invisible but will be the coordinate system used to identify where objects are going to be rendered. It uses an x and y axis and I'm trying to make it so that you can choose the size of the grid so it's not misceallaneously rendering out blank space.
Heres the code I have:

import math
calculatingcoords = True
coordinates = []
xlength = 10
ylength = 10
while calculatingcoords == True:
    if xlength != 0:
        calculatingcoords.append((xlength - 1, ylength))
    if ylength != 0:
        coordinates.append((xlength, ylengt - 1))
    if ylength == 0:
        if xlength == 0:
            calculatingcoords == False

The problem I get here is that an memory error on line 10. I know a memory error is when your program runs out of RAM to run off of, but even when I replaced the xlength and ylength values with 1's, making it so that there would only be about 4 in the list, it still gets the error. I'm not sure why.
I'm willing to scrap the program as it is if there is a simpler solution, so is there a way to fix it? Or should I start all over. Thanks in advance, everybody!

Nether_1 0 Light Poster

I'm writing a code that requires me to import multiple python files that are similiar to that of a .obj file, in the sense that they will create a 3D figure using vertices and lines, etc. The problem is, the files will have the same name for a list (called vertices) in each of the files. For example:

vertices = [(1, 0, 2), (1, 1, 1), (...)]
lines = [(...), (...), (...)]

The problem is, every file will have this, with the same name. Is there a way to make it so that when I import the files, each can be treated seperately?

To help clarify: I'm using the above format in a .py file repeatedly, which requires me to use the same name. Is there a way to use the string vertices and reference it by file?

Nether_1 0 Light Poster

I used another version of the code and was able to fix it, I'm posting the code for future use:

import socket

host = ''
port = 50000
slots = 10
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(slots)

I'm not exactly sure why this fixed it but it works so I'm not going to complain :D

Nether_1 0 Light Poster

I'm writing a simple server allowing me and my friends to send information to each other.
Currently I've got the client down easy enough, it's all set up and I can communicate with servers. The problem is I can't get the server to work for some reason, I use working examples offline and it just refuses to function. Here's the code:

import socket
HOST = ''
PORT = 8888
SLOTS = 10

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
     s.bind((HOST, PORT))
except:
     print "Failure To BInd"
s.listen(SLOTS)

conn, addr = s.accept()

I get an error saying that in the s.listen(SLOTS) line, an argument wasn't provided.
Any ideas what is happening?

Nether_1 0 Light Poster

As the title suggests, I'm attempting to build a first-person view game. I could do this on my own, but the way I'm thinking of doing it is completely impractical (involves coordinates and thousands of if statement for every possible view, which like I said is impossible). I can pretty easily make it so that the surroundings are loaded in using classes called things like block class and such, but the one problem I'm having is I can't figure out how to make it so the 'camera' so to speak allows you to know what you're looking at without a bunch of if statements.

What I'm hoping is that there is some way to make it so the camera (with some code in the background) will be able to recognize what it should be looking at, without all the if statements. Is this even possible in python? If not, what's the best language to learn to help allow me to do this? Any help is appreciated.

Nether_1 0 Light Poster

I have a simple pygame code that doesn't seem to be functioning correctly, check it out:

import pygame, time

active = True
screen_size = (1052, 700)

pygame.init()
DISPLAY = pygame.display.set_mode(screen_size)
firstimg = pygame.image.load('firstimage.png')
secondimg = pygame.image.load('secondimage.png')
clock = pygame.time.Clock()

def WHITESCREEN:
    DISPLAY.fill(255, 255, 255)
def DisplayFirstImg():
    DISPLAY.blit(firstimg, (1, 1))
def DisplaySecondImg():
    DISPLAY.blit(secondimg, (1, 1))
WHITESCREEN()
DisplayFirstImg()
time.sleep(3)
DisplaySecondImg()

while active:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
    pygame.display.update()
    clock.tick(15)

So this should display 'firstimage.png', wait three seconds, and then display 'secondimage.png'. However it skips the first two steps, going straight to the delay and then displays the second img. Obviously it shouldn't be doing this, so do you guys have any ideas? I would really appreciate it, and thank you in advance!

Nether_1 0 Light Poster

Sorry Gribouillis, I should have been more specific.
Alright what I'm attempting to do is host a server on python. Like I said, it could be any type of server (I included sftp in that) and the reason I wanted to host it using Python is because the convenience of having it hosted that way. If you can recommend a better form of hosting besides FileZilla (it doesn't work on my OS for some reason) I would be happy to use it that way. What I meant by third party content is an outside program besides python.
Hope this helped, if you have any more questions feel free to ask.

Nether_1 0 Light Poster

So this is more work onto the project I've been working on with the browser and search database stuff, so here goes. I'm attempting to have a large amount of .txt documents stored on an ftp server, and then allow these files to be downloaded, edited, and so on so forth by an ftp client on my pc. I attempted to use FileZilla to host it, but kept getting an error saying the server intentionally refused connection (if you know why it did that feel free to let me know)

So this leads me to my question: Is there a way to host an ftp server using Python itself? I would prefer it be FTP but HTTP or other forms of servers would be fine, as long as I can upload and download files using it.

To help clarify:
-I want to write a code that would allow me to host the aforementioned server types using python itself, no third party content involved. If there isn't a way to do this, then I would be happy to accept any help from anybody. Thanks in advance!

Nether_1 0 Light Poster

I'm attempting to write a simple search engine (which you might know if you read my previous question) that runs off of tags combined in a list. Currently it's just in a basic ASCII output, with things like print functions and the like.

def main():
     active = True
     done = False
     results = []
     OTags = ['Hi', 'hi', ... #Continues onward]
     OResult = ["Type 'Hello' to access this page!"]
     BTags = ['Bye', 'see ya', ...]
     BResult = ["Type 'Goodbye' to access this page!"]

     while active:
          searchPrompt = raw_input('Https://')
          if searchPrompt in Otags:
               results.append(OResult)
          if searchPrompt in BTags:
               results.append(BResult)
          done = True
          while done == True:
               print results
               done = False

Now what this should do is if the user input is in either or both of those tags, it should print the results, which contain instructions on how to access the page you may be looking for. Now besides a lot of polishing I plan on doing at a later date, this should essentially cover the entire 'search' component. However, it only accepts the OTags or the BTags seperately, if I were to type 'Hi Goodbye', it would print a blank set of brackets. I think this is because of the fact that they're if statements, but the same thing happens if I use elif statements. So I was thinking, is there a sort of ANIF statement, something that would allow both of the inputs to be picked up? Any help is appreciated.

Nether_1 0 Light Poster

I'm creating a program that allows you to do a whole ton of stuff, basically just built to make my life a little easier on my pc. However, the idea I had was that I could have a form of 'settings bar' where I could edit the settings (duh) of my program. The only problem I've ran into is that whenever I try to run the program all the variables will reset to their original positions. Now I could go through the painful and laborious process of changing a variable every time I wanted to change my settings, but is there a way I could edit another python file containing some variables and then change and save those variables?

Nether_1 0 Light Poster

Okay so I'm writing a code for a game and the way its currently programmed is the main menu is contained within a large function that references another function, and so on. Not too complicated. But (as you'll see with the code below) I have all the essential variables set before the functions even happen, at the very beginning of the code.

import pygame, sys, time, math

##This is where the variables are set
pygame.init()
DISPLAY = pygame.display.set_mode((1023, 647))
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
clock = pygame.time.Clock()
active = True
started = False
mainScreen = True
coordsX = 0
coordsY = 0
coordsZ = 0
coordsW = 0

def backMain(fps):
    ##Loads main menu
    mainscreendisplayimg = pygame.image.load('mainScreen.png')
    def mainscreen(x, y):
        DISPLAY.blit(mainscreendisplayimg, (x, y))
    mainscreen(1, 1)

    while active:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_p:
                    if started == False:
                        if mainScreen == True:
                            started = True
                            mainScreen = False

        if started == True:
            forwardMain(15)
            started = False
        pygame.display.update()
        clock.tick(fps)

def ultCoords():
    def c0_0_0_0():
        pygame.draw.rect(DISPLAY, GREEN, (507, 333, 8, 8), 0)

def forwardMain(fps):
    ultCoords()
    c0_0_0_0()

backmain(15)

This should display a rectangle on the screen and so on so forth, but instead it gives me an error saying that the variable 'started' is referenced before assignment

This means (I think) that the variable is being used before it's assigned, but it's clearly assigned up at the top, well before any of the …

Nether_1 0 Light Poster

This may not work for the kind of program you're writing (I rarely use Tkinter, more often Pygame) but one thing you could do is use random.randint() and then convert the numbers gained from that into a variable, like so:

import tkinter
import random

leftcoords = random.randint(1000)
topcoords = random.randint(1000)

Obviously you would have to edit this to fit it into your program and Tkinter itself ( like I said, not a master) but this should give you a general idea.

Nether_1 0 Light Poster

Recently I started using my first attempt at Python multithreading. The purpose of the code is to run multiple WHILE loops at the same time, one of which searches for the change of a variable to TRUE caused by input picked up by the other. However, when i ran the program listed below, it gave me an error:

import thread, pygame, sys
def backMain(threadName, fps):
     ##Begins processing of essential info
     pygame.init()
     DISPLAY = pygame.display.set_mode((1023, 647))
     WHITE = (255, 255, 255)
     DISPLAY.fill(WHITE)
     clock = pygame.time.Clock()
     active = True
     started = False
     mainscreendisplayimg = pygmae.image.load('mainScreen.png')
     def mainscreen(x, y):
          DISPLAY.blit(mainscreendisplayimg, (x,y))
     mainscreen(1, 1)
     while active:
          for event in pygame.event.get():
               if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
         elif event.type == pygame.KEYDOWN:
              if event.key == pygame.K_p:
                   if started == False:
                        started = True
                        print 'Done'
        pygame.display.update()
        clock.tick(fps)

def forMain(threadname, fps):
     active = true
     while active:
          if started == True:
               print 'Starting Main Program'
          clock.tick(fps)

try:
    thread.start_new_thread( backMain, ("backwardMain", 15))
    thread.start_new_thread( forwardMain, ("forwardMain", 15))
except:
     print "Unable to start threads"

This should display 'mainScreen.png' on the screen with a white background, and when I press p, should start printing 'Good'. When I run it, however, the Pygame screen will remain completely black and I will get an error stating:

Unhandled exception in thread started by <function forwardMain at 0x02D38470>

Any help would be appreciated

Nether_1 0 Light Poster

Recently I started coding a simple Game Engine in Python, but for some reason I couldn't remember how to get Pygame to recognize you clicked on a certain area. No sample code (sorry) but I was wondering if anybody knew how to make it so Pygame will recognize that the user has clicked on certain x y coordinates.

Thanks!

Nether_1 0 Light Poster

Alright so I wrote a little program using Python 2.7 and the pygame module. For some reason, no matter what I do, the actual Pygame screen itself won't flip() or update() at all, no matter what I do. The code's pictured below(it's rather long):

import pygame
pygame.init()
DISPLAY = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Super Secret Game Name')
clock = pygame.time.Clock()
fps = 30

arrowimg = pygame.image.load('arrowlogo.png')

WHITE = (0, 0, 0)
BLACK = (255, 255, 255)
def arrowimg(x1, y1):
    DISPLAY.blit(arrowimg,(x1, y1))

x1 = 100
y1 = 100

active = False

while not active:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            active = True

    DISPLAY.fill(WHITE)
    pygame.display.flip()

It will open up a pygame window, but it will be completely black and nothing will happen, no matter what I do. Any idea's how to help?

Nether_1 0 Light Poster

Thanks Gribouillis i tried that and it worked.

Nether_1 0 Light Poster

Recently I attempted to install Pygame for Python 2.5 on my new computer. The computer runs Windows 10 32-bit, and I have installed a 32 bit copy of Pygame, so there shouldn't be problems there. Whenever I enter my Python shell to attempt to import, this error happens:

>>> import pygame
Traceback (most recent call last):
   File "<pyshell#0>", line 1, in <module>
      import pygame
   File "C:\Python25\DLLs\pygame\__init__.py", line 95, in <module>
      from pygame.base import *
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed      

I went back into the pygame folder to look at init.py and found out the file it was trying to load was an essential pygame file, it just refuses to load. Any ideas?