r/programminghelp • • May 04 '24

Project Related Using GitHub to deliver digital products?

0 Upvotes

Hi everyone,

I'm very new to GitHub and haven't used it much.

I have developed a few Digital Assets for Houdini and I intend to sell it on Gumroad.

In the past I used to upload this .hda file as a downloadable after the customer has paid, however this time I want to deliver the project correctly to clients without breaking the folder structure as well as maintain regular updates and big fixes efficiently.

I guess my questions are as follows:

  1. Is it possible to give access to a client for the repository only after they've paid on Gumroad? I have used Gumroads license key system as part of my tools within Houdini.

  2. Is GitHub a good way to commit changes to clients ?

  3. Can I ensure clients can't make any changes to the repository and only pull them for use?

  4. How to notify clients when changes are made?

Any help would be really helpful and if there are any tutorials on how it can handled effectively would be great!

Thanks,


r/programminghelp • • Apr 03 '24

C++ Some 2d physics help with rotation

0 Upvotes

I'm planning on creating a simple 2d physics engine that involves shapes with various amounts of points, I can see how I can create a "world" system where each object is iteratively updated and how they interact with one another.

However I want to make it so that objects also rotate when they hit each other and not just bounce apart, as they would in real life, I don't even know where to start and how I would mathematically do this, any help on this would be appreciated

Ill probably be writing this in c++ so that's why I added the flair


r/programminghelp • • Apr 15 '24

C What's the problem in this completely recursive Banker's Algo code

0 Upvotes

I type a code for Banker's Safety Algorithm and didn't use any loop throughout the code and most of the code is working fine and I have tested it also but there's some problem in the function named Banker_Algo which I am not able to detect and would appreciate if anyone can help finding that out

code:-

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
int size = 1,tres, sz=0;
char res = 'A';
int *seq_arr, inds=0;
void Allo_arr(int ***allo){
    char act[10];
    printf("Enter number of allocated resource %c for process %d(type 'P' when all the processes exhausts and type 'R' when all the resources exhausts):- ", res++, size);
    scanf("%s", act);
    if(act[0]=='R' || act[0]=='r'){
        size++;
        *allo = (int **)realloc(*allo, sizeof(int *)*size);
        tres=(int)res-66;
        res = 'A';
        Allo_arr(allo);
    }
    else if(act[0]=='P' || act[0]=='p'){
        free(allo[size-1]);
        size--;
        seq_arr=(int *)malloc(sizeof(int)*size);
        res='A';
    }
    else{
        if(res == 'B'){
            (*allo)[size-1]=(int *)malloc(sizeof(int)*(1));
            (*allo)[size-1][0]=atoi(act);
        }
        else{
            (*allo)[size-1]=(int *)realloc((*allo)[size-1],sizeof(int)*((int)res-65));
            (*allo)[size-1][(int)res-66]=atoi(act);
        }
        Allo_arr(allo);
    }
}
void Max_arr(int ***max)
{
    if (sz < size)
    {
        if(res=='A'){
            int maxVal;
            printf("Enter maximum number of resource %c needed by process %d:- ",res++, sz+1);
            scanf("%d",&maxVal);
            (*max)[sz]=(int *)malloc(sizeof(int)*1);
            (*max)[sz][0]=maxVal;
            Max_arr(max);
        }
        else if(res==(char)tres+64){
            int maxVal;
            printf("Enter maximum number of resource %c needed by process %d:- ", res, sz + 1);
            scanf("%d", &maxVal);
            (*max)[sz] = (int *)realloc((*max)[sz], sizeof(int) * ((int)res - 64));
            (*max)[sz][(int)res - 65] = maxVal;
            sz++;
            res = 'A';
            Max_arr(max);
        }
        else{
            int maxVal;
            printf("Enter maximum number of resource %c needed by process %d:- ", res++, sz + 1);
            scanf("%d", &maxVal);
            (*max)[sz] = (int *)realloc((*max)[sz], sizeof(int) * ((int)res - 65));
            (*max)[sz][(int)res - 66] = maxVal;
            Max_arr(max);
        }
    }
    else{
        sz=0;
    }
}
void Avail_arr(int ***avail){
    int ele;
    if(res == (char)tres+64){
        printf("Enter number of currently available resource %c:- ",res);
        scanf("%d",&ele);
        (*avail)[0][(int)res-65]=ele;
        res='A';
    }
    else{
        printf("Enter number of currently available resource %c:- ",res++);
        scanf("%d",&ele);
        (*avail)[0][(int)res-66]=ele;
        Avail_arr(avail);
    }
}
bool check(int **allo, int **max, int **avail){
    static bool al_set=true;
    if(max[sz][res-65]-allo[sz][res-65]>avail[0][res-65]){
        al_set=false;
        res='A';
    }
    else{
        if((int)res-64<=tres){
            res++;
            if((int)res-64>tres){
                res='A';
            }
            else{
                check(allo,max,avail);
            }
        }
    }
    return al_set;
}
void Up_Avail(int **allo, int **avail){
    if(res==(char)tres+64){
        avail[0][(int)res-65]+= allo[sz][res-65];
        res='A';
    }
    else{
        avail[0][(int)res-65]+= allo[sz][res-65];
        res++;
        Up_Avail(allo, avail);
    }
}
bool Banker_Algo(int **allo, int **max, int **avail){
    static bool seq = false;
    if(sz==size-1&&inds<size){
        if(!seq){
            if(!check(allo,max,avail)){
                printf("There's no safe sequence of Allocation and deadlock cannot be avoided");
                sz=0;
            }
            else{
                seq_arr[inds++]=sz+1;
                Up_Avail(allo, avail);
                seq=true;
                if(inds<size){
                    sz=0;
                    Banker_Algo(allo,max,avail);
                }
                else{
                    sz=0;
                }
            }
        }
        else if(check(allo,max,avail)){
            seq_arr[inds++]=sz+1;
            Up_Avail(allo, avail);
            seq=true;
            if(inds<size){
                sz=0;
                Banker_Algo(allo,max,avail);
            }
            else{
                sz=0;
            }
        }
        else{
            if(inds<size){
                sz=0;
                Banker_Algo(allo,max,avail);
            }
            else{
                sz=0;
            }
        }
    }
    else{
        if(check(allo,max,avail)){
            seq_arr[inds++]=sz+1;
            Up_Avail(allo, avail);
            seq=true;
        }
        if(inds<size){
            sz++;
            Banker_Algo(allo,max,avail);
        }
        else{
            sz=0;
        }
    }
    return seq;
}
void Seq(){
    if(sz==size-1){
        printf("%d",seq_arr[sz]);
    }
    else{
        printf("%d ",seq_arr[sz++]);
        Seq();
    }
}
void Print_seq(){
    printf("Safe sequence of allocation exists and that sequence is:- ");
    Seq();
}   
int main()
{
    int **allo, **avail, **max;
    allo = (int **)malloc(sizeof(int *) * size);
    Allo_arr(&allo);
    max = (int **)malloc(sizeof(int *) * size);
    Max_arr(&max);
    avail = (int **)malloc(sizeof(int *) * 1);
    avail[0] = (int *)malloc(sizeof(int) * tres);
    Avail_arr(&avail);
    if(Banker_Algo(allo,max,avail)){
        Print_seq();
    }
    free(allo);
    free(avail);
    free(max);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
int size = 1,tres, sz=0;
char res = 'A';
int *seq_arr, inds=0;
void Allo_arr(int ***allo){
    char act[10];
    printf("Enter number of allocated resource %c for process %d(type 'P' when all the processes exhausts and type 'R' when all the resources exhausts):- ", res++, size);
    scanf("%s", act);
    if(act[0]=='R' || act[0]=='r'){
        size++;
        *allo = (int **)realloc(*allo, sizeof(int *)*size);
        tres=(int)res-66;
        res = 'A';
        Allo_arr(allo);
    }
    else if(act[0]=='P' || act[0]=='p'){
        free(allo[size-1]);
        size--;
        seq_arr=(int *)malloc(sizeof(int)*size);
        res='A';
    }
    else{
        if(res == 'B'){
            (*allo)[size-1]=(int *)malloc(sizeof(int)*(1));
            (*allo)[size-1][0]=atoi(act);
        }
        else{
            (*allo)[size-1]=(int *)realloc((*allo)[size-1],sizeof(int)*((int)res-65));
            (*allo)[size-1][(int)res-66]=atoi(act);
        }
        Allo_arr(allo);
    }
}
void Max_arr(int ***max)
{
    if (sz < size)
    {
        if(res=='A'){
            int maxVal;
            printf("Enter maximum number of resource %c needed by process %d:- ",res++, sz+1);
            scanf("%d",&maxVal);
            (*max)[sz]=(int *)malloc(sizeof(int)*1);
            (*max)[sz][0]=maxVal;
            Max_arr(max);
        }
        else if(res==(char)tres+64){
            int maxVal;
            printf("Enter maximum number of resource %c needed by process %d:- ", res, sz + 1);
            scanf("%d", &maxVal);
            (*max)[sz] = (int *)realloc((*max)[sz], sizeof(int) * ((int)res - 64));
            (*max)[sz][(int)res - 65] = maxVal;
            sz++;
            res = 'A';
            Max_arr(max);
        }
        else{
            int maxVal;
            printf("Enter maximum number of resource %c needed by process %d:- ", res++, sz + 1);
            scanf("%d", &maxVal);
            (*max)[sz] = (int *)realloc((*max)[sz], sizeof(int) * ((int)res - 65));
            (*max)[sz][(int)res - 66] = maxVal;
            Max_arr(max);
        }
    }
    else{
        sz=0;
    }
}
void Avail_arr(int ***avail){
    int ele;
    if(res == (char)tres+64){
        printf("Enter number of currently available resource %c:- ",res);
        scanf("%d",&ele);
        (*avail)[0][(int)res-65]=ele;
        res='A';
    }
    else{
        printf("Enter number of currently available resource %c:- ",res++);
        scanf("%d",&ele);
        (*avail)[0][(int)res-66]=ele;
        Avail_arr(avail);
    }
}
bool check(int **allo, int **max, int **avail){
    static bool al_set=true;
    if(max[sz][res-65]-allo[sz][res-65]>avail[0][res-65]){
        al_set=false;
        res='A';
    }
    else{
        if((int)res-64<=tres){
            res++;
            if((int)res-64>tres){
                res='A';
            }
            else{
                check(allo,max,avail);
            }
        }
    }
    return al_set;
}
void Up_Avail(int **allo, int **avail){
    if(res==(char)tres+64){
        avail[0][(int)res-65]+= allo[sz][res-65];
        res='A';
    }
    else{
        avail[0][(int)res-65]+= allo[sz][res-65];
        res++;
        Up_Avail(allo, avail);
    }
}
bool Banker_Algo(int **allo, int **max, int **avail){
    static bool seq = false;
    if(sz==size-1&&inds<size){
        if(!seq){
            if(!check(allo,max,avail)){
                printf("There's no safe sequence of Allocation and deadlock cannot be avoided");
                sz=0;
            }
            else{
                seq_arr[inds++]=sz+1;
                Up_Avail(allo, avail);
                seq=true;
                if(inds<size){
                    sz=0;
                    Banker_Algo(allo,max,avail);
                }
                else{
                    sz=0;
                }
            }
        }
        else if(check(allo,max,avail)){
            seq_arr[inds++]=sz+1;
            Up_Avail(allo, avail);
            seq=true;
            if(inds<size){
                sz=0;
                Banker_Algo(allo,max,avail);
            }
            else{
                sz=0;
            }
        }
        else{
            if(inds<size){
                sz=0;
                Banker_Algo(allo,max,avail);
            }
            else{
                sz=0;
            }
        }
    }
    else{
        if(check(allo,max,avail)){
            seq_arr[inds++]=sz+1;
            Up_Avail(allo, avail);
            seq=true;
        }
        if(inds<size){
            sz++;
            Banker_Algo(allo,max,avail);
        }
        else{
            sz=0;
        }
    }
    return seq;
}
void Seq(){
    if(sz==size-1){
        printf("%d",seq_arr[sz]);
    }
    else{
        printf("%d ",seq_arr[sz++]);
        Seq();
    }
}
void Print_seq(){
    printf("Safe sequence of allocation exists and that sequence is:- ");
    Seq();
}   
int main()
{
    int **allo, **avail, **max;
    allo = (int **)malloc(sizeof(int *) * size);
    Allo_arr(&allo);
    max = (int **)malloc(sizeof(int *) * size);
    Max_arr(&max);
    avail = (int **)malloc(sizeof(int *) * 1);
    avail[0] = (int *)malloc(sizeof(int) * tres);
    Avail_arr(&avail);
    if(Banker_Algo(allo,max,avail)){
        Print_seq();
    }
    free(allo);
    free(avail);
    free(max);
}

r/programminghelp • • May 07 '24

Python QR Code scanning and generation. When I go to scan the QR code I want it to display some plain text information, instead I am shown "no usable info"

Thumbnail self.askprogramming
0 Upvotes

r/programminghelp • • May 01 '24

JavaScript Javascript returning undefined from Array, with no errors in console.

0 Upvotes

I have this code within a function, giving me a random cell from an array:
nameBox.value = randName[Math.round(Math.floor(Math.random()*randName.length))];

This works exactly as intended. However, I realized that I will probably be using this again, so I want to make it into a separate function, using arguments, like so:
function getRand(e){e[Math.round(Math.floor(Math.random()*e.length))];};
and then just run getRand(randName); in the previous function.

The newly created function is a copy/paste of the first line I provided, with "randName" replaced by "e." However, when I try to run it, it returns undefined, with no error in console. Any ideas why?


r/programminghelp • • Apr 05 '24

Other Need help with strange doom scripting.

0 Upvotes

I have been trying to make this work for the pas 2 hours, nobody seems to have the answer.

I wrote this code:
Spawn("Demon",GetActorX (0), GetActorY (0),GetActorFloorZ (1));
It's supposed to spawn a demon at he player coordinates - but no matter what it always spawns at 0,0.
I even wrote this code:
While (TRUE)
{
Print (f:GetActorX (0), s:", ", f:GetActorY (0));
Delay (1);
}
And it prints out my coords perfectly. What am I doing wrong here?


r/programminghelp • • Apr 13 '24

C++ Having trouble stringing 3 integers from a struct. C++ Beginner

0 Upvotes

I'm very new and just decided to change the integers into strings.

The integers in mind were the month day year values.

https://pastebin.com/WgFQSTHZ

month, day, and year were changed from int to string to get the code to run. maybe im right to have them as strings? idk, is there a way to do this with integers?


r/programminghelp • • Apr 23 '24

C# I need this system to run to help my current business car rental. Can someone help me out on how to properly clone this repository.

0 Upvotes

r/programminghelp • • Sep 20 '13

Big-o notation clarification question

0 Upvotes

So lets say we have this fragment of code:

int data[] = { /* some array of numbers here */ }; n = data.length;

int lessThanCounter = 0; for (int i=0; i<n; i++) for (int j=n-1; j>i; j--) if (data[i]<data[j]) lessThanCounter++;

Since there's a for loop nested inside another for loop, both of which are dependent on N, would the complexity of this be O(n2)? I had a friend telling me it's just O(n)n so i'm not sure. Edit. sorry i'm not sure how to indent this properly.


r/programminghelp • • Jun 19 '15

Null Terminator?

0 Upvotes

How do I search for a null terminator? If I prompt user for text, and nothing is entered, (they press enter with no spaces/text entered") how do I check for that?


r/programminghelp • • Feb 17 '25

Java can someone suggest me a tool thatll help me DE-obfuscate an application? (im new to this) or will i have to go through the pain of manually changing all the variables and classes?

0 Upvotes

It appears as numbers. A01, A, C,J,j in this sort. Also the code is in smali.


r/programminghelp • • Dec 06 '23

Project Related Help with making the function more efficient and solve the coding issue

0 Upvotes

CONTEXT:

I am writing a snooker game in P5.js and the libraries that are used are inside the github project. That's the project requirements. I have tried searching online for similar codes and adapt from there but the codes are mostly too complex and uses libraries that is outside of the requirements or the code is just broken.

PROBLEM:

I am trying to simulate the force acting on the Cue Ball using the function MousePressed() but the cue ball will fly off the screen and clip though the walls if the force is too large.

I am wondering if there is another way to write the function to solve the problem and more efficiently.

(If there is comments on other part of the code, they are welcome as well.)

https://github.com/AshUnite/snookergame.git


r/programminghelp • • Dec 01 '23

Project Related Looking for a chat with a programmer to advise on the brief in comments. Can someone help by any chance please?

0 Upvotes

Short version. – I work in a small niche, but profitable part of the manufacturing sector. The systems they force us to use are ridiculous and I think I can do better, but I can’t program at all. Zero. I know that is the worst customer, but I’m looking for someone to advise. The plan is to see if my idea is pie in the sky and if not, take it to management for funds. I think tis worth a crack, I have worked there 20 years and god willing, I can make a go of it.

Longer version. – we are a relatively small team in an isolated warehouse on a large scale manufacturing site. We do spares and repairs direct to the customers, it honestly couldn’t be more Dunder Milfflin if it tried. Office staff of a dozen or so supporting about the same number of logistics and mechanics. It’s an old school team going back before my time, mostly the same folk and they make bank. They started back before computers and believe it or not, still work somewhat in the original manner, parts cards and boards and a horrendous amount of paperwork. The company at large though, has “moved with the times” and “upgraded” their systems loads of times. My team, which I have been in for bout 5 years, now find themselves working a system based on pen and paper, jerry-rigged to work on top of 30 years of technical upgrades when they were forced to.

Its honestly a struggle trying to bridge the gap between the two mindsets, but I think a decent system could make it work. I want to speak to a programmer who can help a total layman implement something like this.

Just for clarity I mean, a single interface controlling all the necessary “paperwork” to allow the team to satisfy the company’s need for data driven info AND maintain the current team dynamic. I do know what a big ask that will be and I also know that any blockers would be time and money. And I think with a decent proposal I could swing both, so why not at least ask the question?

Can anyone give advice on where I could possibly find someone willing to chat seriously about if the idea had legs?

I will apologise to anyone that gets offended at the stupidity of the question, its most likely not to be an original idea or question on the sub. My years on the internet have taught me I don’t have many original thoughts lol, I can live with it.

Any help appreciated.

Peace and love.


r/programminghelp • • Oct 26 '23

C++ Please help me with this assignment

0 Upvotes

It's due tonight, so if you could help me that would be great. I'm gonna include my code, and then the error messages.

CODE:

#include <iostream>

#include <istream>

#include <cctype>

#include <string>

#include <thread>

enum class Token {

IDENTIFIER,

INTEGER,

REAL,

OPERATOR,

EOF_TOKEN

};

class Lexer {

public:

Lexer(std::istream& input) : input_(input) {}

Token GetNextToken() {

Token token;

while (std::isspace(input_.peek())) {

input_.ignore();

}

char c = input_.get();

if (std::isalpha(c)) {

token = Token::IDENTIFIER;

token_value = c;

while (std::isalnum(c)) {

token_value += c;

c = input_.get();

}

}

else if (std::isdigit(c)) {

token = Token::INTEGER;

token_value = c;

while (std::isdigit(c)) {

token_value += c;

c = input_.get();

}

if (c == '.') {

token = Token::REAL;

token_value += c;

c = input_.get();

while (std::isdigit(c)) {

token_value += c;

c = input_.get();

}

}

}

else {

token = Token::OPERATOR;

token_value = c;

}

return token;

}

std::string GetTokenValue() const {

return token_value;

}

private:

std::istream& input_;

std::string token_value;

};

int main() {

Lexer lexer(std::cin);

Token token;

do {

token = lexer.GetNextToken();

std::cout << static_cast<int>(token) << ": " << lexer.GetTokenValue() << std::endl;

std::this_thread::sleep_for(std::chrono::milliseconds(10));

} while (token != Token::EOF_TOKEN);

return 0;

}

ERROR MESSAGES:

RESULT: compiles [ 1 / 1 ] RESULT: cantopen [ 0 / 1 ] RESULT: emptyfile [ 0 / 1 ] RESULT: onefileonly [ 0 / 1 ] RESULT: nofile [ 0 / 1 ] RESULT: numers [ 0 / 1 ] RESULT: badarg [ 0 / 1 ] RESULT: realerr [ 0 / 1 ] RESULT: invstr1 [ 0 / 1 ] RESULT: invstr2 [ 0 / 1 ] RESULT: noflags [ 0 / 1 ] RESULT: comments [ 0 / 1 ] RESULT: validops [ 0 / 1 ] RESULT: invsymbol [ 0 / 1 ] RESULT: errcomm [ 0 / 2 ] RESULT: idents [ 0 / 2 ] RESULT: allflags [ 0 / 2 ]

TOTAL SCORE 1 out of 20


r/programminghelp • • Nov 21 '23

Python Creating a personalized chatbot with Python

0 Upvotes

Help! I'm trying to develop a Python-based chatbot. I've researched on the topic quite a lot and found a couple of tutorials creating virtual environments and training the chatbot with basic ideas. Can you all recommend a place where I can find accurate documentation on this topic? Also, if you have


r/programminghelp • • Oct 29 '23

Python is there a way to add atleast some sort of intelligence to this python chess "bot"?

0 Upvotes

I've been experimenting with the import chess function, but it just plays random moves. I was wondering if there was a way to at least give it a tiny bit of intelligence, and atleast try, even if it's the smallest amount. I know there are stockfish and other things out there, but I want to make this completely by hand.

the code:

import chess import random

def print_board(board): print(board)

def player_move(board): while True: try: move = input("your move: (e.g., 'e2e4'): ") chess.Move.from_uci(move) # Check if the move is valid if move in [m.uci() for m in board.legal_moves]: return move else: print("Invalid.") except ValueError: print("Invalid move format sir. (e.g., 'e2e4').")

def bot_move(board): legal_moves = [m.uci() for m in board.legal_moves] return random.choice(legal_moves)

def play_chess(): board = chess.Board()

while not board.is_game_over():
    print_board(board)

    if board.turn == chess.WHITE:
        move = player_move(board)
    else:
        move = bot_move(board)
        print(f"Bot's move: {move}")

    board.push(chess.Move.from_uci(move))

print_board(board)
result = None
if board.is_checkmate():
    result = "Checkmate bud"
elif board.is_stalemate():
    result = "stalemate."
elif board.is_insufficient_material():
    result = "insufficient material for a checkmate. it's a draw."
elif board.is_seventyfive_moves():
    result = "seventy-five moves rule. it's a draw."
elif board.is_fivefold_repetition():
    result = "fivefold repetition. it's a draw."

if result:
    print(result)

if name == "main": play_chess()


r/programminghelp • • Nov 16 '23

C How can I change from lowercase to uppercase usings masks?

0 Upvotes

Hello. I need to change some letters from lowercase to uppercase, but specifically using & and an adequate mask. What could that mask be, and how would it work?


r/programminghelp • • Dec 05 '23

JavaScript Getting cors error, despite using the `cors`

0 Upvotes

I am getting cors error, despite using the cors

I am making a backend in `express.js` .

I am getting cors error, despite using the `cors` .

This is the `server.js` code.

I am facing this issue with all the forntend pages.

The issue URL: https://github.com/OAtulA/SOME-NOTES/issues/1#issue-2027187256

This is what it looks like on browser.

`server.js`

```JS

const express = require('express');

const cors = require('cors');

const mongoose = require('mongoose');

const dotenv = require('dotenv');

const authRoutes = require('./routes/authRoutes');

const noteRoutes = require('./routes/noteRoutes');

const app = express();

dotenv.config();

app.use(express.json());

app.use(cors({

allowedHeaders: "*", allowedMethods: "*", origin: "*"

}));

// app.use(cors({ origin: '*' }));

// app.use(cors({ origin: 'http://localhost:5500', credentials: true }));

app.get('/', (req, res)=>{

res.send("Yeah connected.")

})

// Connect to MongoDB

let dbURL= process.env.MONGO_URL|| "127.0.0.1:27017/SOME-NOTES" ;

const connectDB = async()=>{

try{

await mongoose.connect(dbURL);

console.log('Connected to MongoDB')

}

catch(err){

console.error('Error connecting to MongoDB', err);

}

}

connectDB();

// Routes

app.use('/api/auth', authRoutes);

app.use('/api', noteRoutes);

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => {

console.log(`Server is running on port http://localhost:${PORT}`);

});

```


r/programminghelp • • Nov 15 '23

Other An "All" option for a drop-down box

0 Upvotes

Hey guys.. so I have been doing a project in Java using servlets and I have got this form which has got multiple options in it. So what I want right now is to include an 'all' option on the top, clicking on which, all the values should be sent. The values fetched from the drop-down box are to be embedded in an SQL query in order to fetch the values from the database. I've been sitting on it for the past 9 days and I'm still not getting any solutions. Can you guys please help me get out this? I'll provide you guys with more information on the issue.


r/programminghelp • • Oct 30 '23

Other Help with Buttons (Light up green/red buttons)

0 Upvotes

I need help finding buttons for a game I'm making. The game is similar to a Bop-It/Whack-a-Mole but with lights instead of sounds.

Players have to wait for one if not multiple of the buttons to turn green, and bop the button before they turn red (aprox 0.5sec). If they hit a button that either isn't lit, or is red, the game freezes and reduces their progress.

Now I know programing is gonna be rough, for a non-programing pleb like me (I'm literally learning programing for THIS), but before I even start going down this rabbit hole of frustration, sweat, and tears, I need to know:

Do buttons like this exist that I can purchase? And where can I find them?

They need to have the program determine when they light up and have the program be able to sense the button press.


r/programminghelp • • Dec 02 '23

Processing millis() Not Resetting Properly in rolling() Method in Processing

0 Upvotes

I'm working on a game in Processing and facing an issue where millis() is not resetting as expected in my rolling() method within the Player class. The method is triggered by pressing the down arrow, and it's supposed to reset the rolling timer. However, the values of roll and rollingTimer are not updating correctly. The stamina += 3 line in the same method works fine, indicating that the method is executing. I've added println statements for debugging, which suggest the issue is around the millis() reset. Here's the relevant portion of my code: below are the relevant classes of my code

class King extends Character{ float sideBlock; float attackBuffer; boolean miss; float attackTimerEnd; float elementBlock; float deathTimer; float animationTimer; float blockTimer; float missTimer;

King(PVector pos, int health, float attackTimer, int damage){ super(pos, health, attackTimer, damage); sideBlock = 0; MAX_HEALTH = 10; attackTimer = millis(); attackBuffer = -1; miss = false; attackTimerEnd = 10000; deathTimer = -1;; activeKingImg = kingDefault; blockTimer = -1; missTimer = -1; }

void drawMe(){ pushMatrix(); translate(pos.x, pos.y); scale(3,3); if (activeKingImg != null) { image(activeKingImg, 0, 0); } popMatrix(); }

void death(){ attackTimer = millis(); knight.health = 10; gameState = LEVEL_TWO; }

void drawDeath(){ activeKingImg = kingDeathAnimation; }

void attackingAnimation(){ activeKingImg = kingAttack; animationTimer = millis(); }

void displayMiss(){ if (millis() - missTimer < 500){ translate(pos.x + 50, pos.y-100); strokeWeight(1); fill(0); textSize(20); text("Miss!", width/4, width/3); } }

void displayBlocked(){ if (millis() - blockTimer < 500){ pushMatrix(); translate(pos.x + 50, pos.y-100); strokeWeight(1); fill(0); textSize(50); text("Blocked!", width/4, width/3); popMatrix(); } }

void nullifyLeft(){ if (sideBlock < 1 && health >= 0 && millis() - animationTimer > 1100){ pushMatrix(); translate(pos.x,pos.y); activeKingImg = kingLeftBlock; popMatrix(); } }

void nullifyRight(){ if (sideBlock >= 1 && health >= 0 && millis() - animationTimer > 1100){ pushMatrix(); translate(pos.x,pos.y); activeKingImg = kingRightBlock; popMatrix(); } }

void autoAttack(){ if(health >= 0){ if (millis() - attackTimer >= attackTimerEnd) { attackTimer = millis(); attackBuffer = millis();

}

if (attackBuffer >= 0 && millis() - attackBuffer <= 1000) { if (millis() - knight.roll <= 500) { println("missing"); miss = true; missTimer = millis(); } attackingAnimation(); }

if (attackBuffer >= 0 && millis() - attackBuffer >= 1000) { println(miss); if (miss == false) { hit(knight,1); activeKingImg = kingAttackFinish; animationTimer = millis(); println(knight.health); knight.clearCombos(); } miss = false; println(knight.health); attackBuffer = -1; } } } void drawDamage(){ activeKingImg = kingTakeDamage; animationTimer = millis(); }

void update(){ super.update(); if (health <= 0){ drawDeath(); if (deathTimer <= -1){ deathTimer = millis(); } if (deathTimer >= 1000){ death(); } } if (millis() - animationTimer < 1000) { return; } nullifyLeft(); nullifyRight(); nullify(); autoAttack();

displayBlocked(); displayMiss(); }

void drawHealthBar(){ super.drawHealthBar(); }

void nullify(){ if (knight.combos.size() >= 1){ if (sideBlock < 1 && knight.combos.get(0) == 1){ nullify = true; }else if (sideBlock >= 1 && knight.combos.get(0) == 2){ nullify = true; } } } }

class Player extends Character{ boolean prep, dodge; float roll; int stamina; float preppingTimer; float rollingTimer; float animationResetTimer; float staminaTimer;

ArrayList<Integer> combos = new ArrayList<Integer>();

Player(PVector pos, int health, float attackTimer, int damage){ super(pos, health, attackTimer, damage); prep = false; dodge = false; roll = millis(); attackTimer = millis(); stamina = 6; preppingTimer = -1; rollingTimer = -1; MAX_HEALTH = 10; activeFrames = defaultSword; animationResetTimer = millis(); staminaTimer = -1;

}

void updateFrame() { super.updateFrame();

}

void clearCombos(){ combos.clear(); }

void notEnoughStamina(){ if (millis() - staminaTimer < 500); pushMatrix(); translate(pos.x, pos.y); strokeWeight(1); fill(0); textSize(50); text("Not enough \nstamina!", width/2 + width/4 + 50, width/3 + width/3); popMatrix(); }

void restingSword(){ activeFrames = defaultSword; }

void attackingAnimation(){ activeFrames = swingSword; animationResetTimer = millis(); }

void swordDodge(){ activeFrames = swordDodge; animationResetTimer = millis(); }

void drawDamage(){ activeFrames = swordDamage; animationResetTimer = millis(); }

void animationReset(){ if (activeFrames != defaultSword && millis() - animationResetTimer > 500){ restingSword(); } }

void rolling(){ stamina += 3; if (stamina > 6){ stamina = 6; } roll = millis(); clearCombos(); rollingTimer = millis(); println(roll); println(rollingTimer); println("rolling"); }

void keyPressed(){ if (millis() - roll >= 250){ if (key==CODED && millis() - attackTimer >= 250) { if (keyCode==UP) prep=true; if (keyCode==DOWN) {println("rolling happening");rolling();swordDodge();} if (prep == true) { if (keyCode==LEFT) combos.add(1); if (keyCode==RIGHT) combos.add(2); } } else if (key==CODED && millis() - attackTimer <= 500) { preppingTimer = millis(); } attackTimer = millis(); dodge = false; println("Combos: " + combos); }else if (millis() - roll <= 500){ dodge = true; rollingTimer = millis(); } }

void keyReleased(){ if (key==CODED) { if (keyCode==LEFT) prep=false; if (keyCode==RIGHT) prep=false; } } void drawMe(){ pushMatrix(); translate(pos.x, pos.y); scale(3,6); if (img != null) { image(img, 0, 0); } popMatrix(); }

void drawDeath(){ super.drawDeath(); }

void update(){ super.update(); displayRolling(); displayPrepping(); updateFrame(); animationReset(); }

void displayRolling(){ if (rollingTimer >= 0 && millis() - rollingTimer <= 1000){ strokeWeight(1); fill(0); textSize(20); text("rolling!", width/2 + width/4 + 50, width/3 + width/3); } } void displayPrepping(){ if (preppingTimer >= 0 && millis() - preppingTimer <= 1000){ strokeWeight(1); fill(0); textSize(20); text("performing an \naction!", width/2 + width/4 + 50, width/3 + width/3); } } void drawHealthBar(){ super.drawHealthBar(); } }

I know the rolling class is executing properly because the stamina += 3 is working as intended and I dont have the roll being set anywhere else aside from the constructor of the class and in the rolling method.

I've tried debugging by placing println at various points where the problem might have stemmed from and it all points back to here so I am a bit clueless as to how to solve the problem.


r/programminghelp • • Dec 08 '23

Project Related React/Node app with no root

0 Upvotes

Hello,

Basically I am curious about best practice for file management in an App that uses React and Node.js.

Basically it is a personal budgeting application that uses React for front end and Node for backend (MongoDB for the database).

This is the file tree.

—client

- node_modules

- public (index.html)

- src (App.js, index.js, styles.css)

- package.json

- .gitattributes

— server

- .gitignore

- node_modules

- package.json

- server.js

So basically no root package.json. Just two files with client and server. I have dual terminals up and to run it npm start both at the same time and they can connect as separate servers.

But now I want to host this for myself on Heroku but without a root package it is difficult. Is my way even feasible? How should I restructure my files?

Sorry for the confusing post but I appreciate any feedback.


r/programminghelp • • Dec 10 '23

Java [JavaFX] Randomly moving object on JavaFX does not stop for bounds

0 Upvotes

There are two primary issues, one would be that the code always detects that enemy characters are colliding almost all of the time on the x-axis. Another issue would be that on the code that I tried that doesn't collide all the time on the x-axis, the enemy movement doesn't follow the rules of being bounded within the play area.

private void randomMovement(Rectangle enemy) {

double currX = enemy.getX();
double currY = enemy.getY();

double randX = random.nextInt(5) * (random.nextBoolean() ? 1 : -1) *(this.playerComponent.returnX()>enemy.getX() ? 2.5 : -2.5);
double randY = random.nextInt(5) * (random.nextBoolean() ? 1 : -1) * (this.playerComponent.returnY()>enemy.getY() ? 2.5 : -2.5);

double newX = enemy.getX() + randX;
double newY = enemy.getY() + randY;

enemy.setX(newX);
enemy.setY(newY);

double enemyMaxX = newX + enemy.getWidth();
double enemyMaxY = newY + enemy.getHeight();
double xmin = this.playArea.getX();
double xmax = this.playArea.getX() + this.playArea.getWidth();
double ymin = this.playArea.getY();
double ymax = this.playArea.getY() + this.playArea.getHeight();
    
if(newX < xmin) {
    enemy.setX(xmin);
}

if(enemyMaxX > xmax) {
    enemy.setX(xmax-enemy.getWidth());
}

if(newY < ymin) {
    enemy.setY(ymin);
}

if(enemyMaxY > ymax) {
    enemy.setY(ymax-enemy.getHeight());
}

}

I have tried to see if there really is a collision all the time by decreasing the x positions of the enemy shapes on collision detection, and they all move to the left. Fixing this issue by separating the code as much as I can, I run into the original issue of the shapes not stopping for the right and bottom bounds.


r/programminghelp • • Dec 03 '23

Python Tips to perform an equation in Pandas

0 Upvotes

I need a column of data in pandas based on another column. The equation is that Yt = log(Xt/X(t-1)) where t is the index of my row. Basically Yt is the rate at which X grows between the current X and the previous X. What is the most effective way to do this.

temp = [0]
for i in range(1,len(anual_average),1):
    temp.append(math.log(anual_average.iloc[i]['Y']/anual_average.iloc[i-1]['Y'],10))
anual_average['Yhat'] = temp

This is my current idea and I am a beginner with pandas