#help XD

53 messages · Page 1 of 1 (latest)

remote inletBOT
#

@cold dune

victor65419845 Uploaded Some Code
Uploaded these files to a Gist
cold dune
#

I have a problem with my c++ code, I'm sorry if my english is bad, I am french.
So
My code is the start of a plateformer game.
And the problem of all of my code is that, my character is not loading in the good place and doesn't even move... Even with tests like cout<<1<<endl; at the beginning of the main function, nothing apear on the cmd.
Here are the files:

subtle kayak
#

Haven't used SFML for ages, but does move() actually take a delta or is it absolute position ?

#

like , player.move(200,200) will move the sprite to 200,200 instantly

cold dune
#

Yes, I've tried it, but doesn't work

#

The problem, is that the problem is unspotable

#

Like

#

Even the beginning of the main doesnt work

#

Everything is loading

#

But Idk

#

I've putted a cout<<1<<ebdl; at the begging of the main and doesnt work

subtle kayak
#

Are you using an IDE where you can easily put in a breakpoint and you could inspect the variables ?

cold dune
#

Wdym? I'm kinda new in c++

subtle kayak
#

Like, a code editor where you can set a point in code where it should stop running and show you information about variables and such

cold dune
#

Oh yeah

subtle kayak
#

you should be able to do alot with just cout << "1" stuff too, just more tedious 😉

cold dune
#

I'm in visual studio

subtle kayak
#

okay, you should be able to click on the left side where you have your line numbers, it should get marked with a red filled circle.. if you run your program in debug mode it will stop at that line and you can point at the variables with your mouse to see more information

#

what I'm getting at is that, with a breakpoint you could verify that your deltaX and Y are actually set

cold dune
#

I don't think the problem is located here

#

I founded some errors on an other panel

#

I give you

#

Gravity Code Description Project File Line Deletion Status
Error C2440 'initialization': cannot convert from 'initializer list' to 'int' Platformer H:\C++\Platformer\Platformer\menu.cpp 9
Error C2011 'joueur': redefinition of a type 'struct' Platformer H:\C++\Platformer\Platformer\menu.h 23
Error C2079 'perso' uses an undefined struct 'joueur' Platformer H:\C++\Platformer\Platformer\menu.cpp 9
Error C2664 'void Collisions::gererCollisionsJoueur(sf::Sprite &, sf::Image &, joueur &, float &)': cannot convert argument 3 from 'int' to 'joueur &' Platformer H:\C++\Platformer\Platformer\menu.cpp 84
Error C2374 'WIN_HEIGHT': redefinition; multiple initialization Platformer H:\C++\Platformer\Platformer\menu.h 13
Error C2374 'WIN_WIDTH': redefinition; multiple initialization Platformer H:\C++\Platformer\Platformer\menu.h 14

subtle kayak
#

whoa, that looks like it doesn't compile at all

cold dune
#

T_T

subtle kayak
#

those errors about "redefinition" is usually because you have used #include in a way that something gets defined twice or more

cold dune
#

Imma try to find the error

subtle kayak
#

not sure if it is going to help, but I noticed your menu.h does not have header guards, like #ifndef MENU_H and #define MENU_H, finally a #endif

cold dune
#

Thank you, I've done this and now I only have 2 errors

subtle kayak
#

What are those errors? 🙂

cold dune
#

I'm translating them

#

Error C2660 'Collisions::gererCollisionsJoueur': function does not take 4 arguments: This error occurs on line 85 of "menu.cpp". It means that you are calling the 'gererCollisionsJoueur' function with 4 arguments, but the function is defined to take a different number of arguments. Check the function signature of 'gererCollisionsJoueur' in the "collisions.h" file and make sure you are calling the function with the correct number of arguments.

Error C2061 syntax error: identifier 'Sprite': This error occurs on line 11 of "collisions.h". It indicates that there is incorrect usage of the identifier 'Sprite' in that file. Make sure you have included the necessary SFML library to use the 'Sprite' class correctly. Check if you have included the line #include <SFML/Graphics.hpp> in "collisions.h" to have access to the 'Sprite' class.

subtle kayak
#

okay, first one seems to be a missmatch on number of arguments you are passing to the function, double check you got them right

#

second one might be fixed with the hint they give you to #include the proper file, unless you already did that then it is something odd

cold dune
#

I've included #include <SFML/Graphics.hpp>

#

So idk

subtle kayak
#

paste in the line 11 from collisions.h to this chat

cold dune
#

#ifndef COLLISIONS_H
#define COLLISIONS_H

#include "menu.h"
#include <iostream>
#include <SFML/Graphics.hpp>

using namespace sf;

class Collisions
{
public:
static void gererCollisionsJoueur(Sprite& sprite, Image& image_masque, joueur& player, float& gravite);
};

#endif // COLLISIONS_H

#

The 11 line is the {

subtle kayak
#

oh yeah, cpp is rather bad at giving you exact line number for some reason

cold dune
#

But the sprite problem is on the 13

#

the static void ...

subtle kayak
#

yea, I see the function declaration, to me that looks just fine. If you hover your mouse on the Sprite& .. does it show you information about it? Like, it should show something about where that was declared etc.

cold dune
subtle kayak
#

what if you prefix it with sf:: ?

#

like static void gererCollisionsJoueur(sf::Sprite& sprite...

cold dune
#

Gravity Code Description Project File Line Deletion Status
Error C2660 'Collisions::gererCollisionsJoueur': function does not take 4 arguments Platformer H:\C++\Plateformer\Plateformer\menu.cpp 85
Error C2061 syntax error: identifier 'joueur' Platformer H:\C++\Plateformer\Plateformer\collisions.h 13

subtle kayak
#

sf:: in this case means you want to use Sprite from the namespace "sf"

#

the second error there sell you that it doesn't know what "joueur" is, you have to #include its declaration from some file, and from code you posted earlier it was declared in "menu.h", I would put this into a separate file and include that instead, for example joueur.h

#

Also noticed that you have circular #include statements, menu.h includes collision.h, but collision.h also includes menu.h ... basically they are including each other for ever 😉

cold dune
#

You saved my life XD

#

Thank you

#

Sorry I had an important call 😉